Skip to content

Commit

Permalink
Move LowerCaseEqualsASCII to base namespace
Browse files Browse the repository at this point in the history
Remove url:: variants. Add the 4-element version from url:: to base::

Review URL: https://codereview.chromium.org/1172753003

Cr-Commit-Position: refs/heads/master@{#333597}
  • Loading branch information
brettw authored and Commit bot committed Jun 9, 2015
1 parent 952985e commit bc17d2c
Show file tree
Hide file tree
Showing 117 changed files with 436 additions and 450 deletions.
4 changes: 3 additions & 1 deletion base/files/file_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,9 @@ TEST(ScopedFD, ScopedFDDoesClose) {
ASSERT_EQ(0, pipe(fds));
const int write_end = fds[1];
ScopedFD read_end_closer(fds[0]);
{ ScopedFD write_end_closer(fds[1]); }
{
ScopedFD write_end_closer(fds[1]);
}
// This is the only thread. This file descriptor should no longer be valid.
int ret = close(write_end);
EXPECT_EQ(-1, ret);
Expand Down
18 changes: 15 additions & 3 deletions base/strings/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,12 @@ bool IsStringUTF8(const StringPiece& str) {
return true;
}

} // namespace base

template<typename Iter>
static inline bool DoLowerCaseEqualsASCII(Iter a_begin,
Iter a_end,
const char* b) {
for (Iter it = a_begin; it != a_end; ++it, ++b) {
if (!*b || base::ToLowerASCII(*it) != *b)
if (!*b || ToLowerASCII(*it) != *b)
return false;
}
return *b == 0;
Expand Down Expand Up @@ -460,12 +458,26 @@ bool LowerCaseEqualsASCII(const char* a_begin,
return DoLowerCaseEqualsASCII(a_begin, a_end, b);
}

bool LowerCaseEqualsASCII(const char* a_begin,
const char* a_end,
const char* b_begin,
const char* b_end) {
while (a_begin != a_end && b_begin != b_end &&
ToLowerASCII(*a_begin) == *b_begin) {
a_begin++;
b_begin++;
}
return a_begin == a_end && b_begin == b_end;
}

bool LowerCaseEqualsASCII(const char16* a_begin,
const char16* a_end,
const char* b) {
return DoLowerCaseEqualsASCII(a_begin, a_end, b);
}

} // namespace base

bool EqualsASCII(const string16& a, const base::StringPiece& b) {
if (a.length() != b.length())
return false;
Expand Down
36 changes: 20 additions & 16 deletions base/strings/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,38 +285,42 @@ template <class str> inline str StringToUpperASCII(const str& s) {
StringToUpperASCII(&output);
return output;
}

} // namespace base

#if defined(OS_WIN)
#include "base/strings/string_util_win.h"
#elif defined(OS_POSIX)
#include "base/strings/string_util_posix.h"
#else
#error Define string operations appropriately for your platform
#endif

//
// Compare the lower-case form of the given string against the given ASCII
// string. This is useful for doing checking if an input string matches some
// token, and it is optimized to avoid intermediate string copies. This API is
// borrowed from the equivalent APIs in Mozilla.
BASE_EXPORT bool LowerCaseEqualsASCII(const std::string& a, const char* b);
BASE_EXPORT bool LowerCaseEqualsASCII(const base::string16& a, const char* b);
BASE_EXPORT bool LowerCaseEqualsASCII(const string16& a, const char* b);

// Same thing, but with string iterators instead.
BASE_EXPORT bool LowerCaseEqualsASCII(std::string::const_iterator a_begin,
std::string::const_iterator a_end,
const char* b);
BASE_EXPORT bool LowerCaseEqualsASCII(base::string16::const_iterator a_begin,
base::string16::const_iterator a_end,
BASE_EXPORT bool LowerCaseEqualsASCII(string16::const_iterator a_begin,
string16::const_iterator a_end,
const char* b);
BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin,
const char* a_end,
const char* b);
BASE_EXPORT bool LowerCaseEqualsASCII(const base::char16* a_begin,
const base::char16* a_end,
BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin,
const char* a_end,
const char* b_begin,
const char* b_end);
BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin,
const char16* a_end,
const char* b);

} // namespace base

#if defined(OS_WIN)
#include "base/strings/string_util_win.h"
#elif defined(OS_POSIX)
#include "base/strings/string_util_posix.h"
#else
#error Define string operations appropriately for your platform
#endif

// Performs a case-sensitive string compare. The behavior is undefined if both
// strings are not ASCII.
BASE_EXPORT bool EqualsASCII(const base::string16& a, const base::StringPiece& b);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/auto_launch_trial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ bool IsInAutoLaunchGroup() {
}

bool IsInExperimentGroup(const std::string& brand_code) {
return LowerCaseEqualsASCII(brand_code, "rngp");
return base::LowerCaseEqualsASCII(brand_code, "rngp");
}

bool IsInControlGroup(const std::string& brand_code) {
return LowerCaseEqualsASCII(brand_code, "rngq");
return base::LowerCaseEqualsASCII(brand_code, "rngq");
}

} // namespace auto_launch_trial
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme(
const std::string& scheme) const {
if (base::IsStringASCII(scheme) &&
(ProfileIOData::IsHandledProtocol(scheme) ||
LowerCaseEqualsASCII(scheme, content::kViewSourceScheme) ||
LowerCaseEqualsASCII(scheme, url::kJavaScriptScheme) ||
LowerCaseEqualsASCII(scheme, url::kDataScheme))) {
base::LowerCaseEqualsASCII(scheme, content::kViewSourceScheme) ||
base::LowerCaseEqualsASCII(scheme, url::kJavaScriptScheme) ||
base::LowerCaseEqualsASCII(scheme, url::kDataScheme))) {
return metrics::OmniboxInputType::URL;
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/autocomplete/history_url_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ bool HistoryURLProvider::CanFindIntranetURL(
// input's text and parts between Parse() and here, it seems better to be
// paranoid and check.
if ((input.type() != metrics::OmniboxInputType::UNKNOWN) ||
!LowerCaseEqualsASCII(input.scheme(), url::kHttpScheme) ||
!base::LowerCaseEqualsASCII(input.scheme(), url::kHttpScheme) ||
!input.parts().host.is_nonempty())
return false;
const std::string host(base::UTF16ToUTF8(
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/browser_about_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ bool WillHandleBrowserAboutURL(GURL* url,
bool HandleNonNavigationAboutURL(const GURL& url) {
const std::string spec(url.spec());

if (LowerCaseEqualsASCII(spec, chrome::kChromeUIRestartURL)) {
if (base::LowerCaseEqualsASCII(spec, chrome::kChromeUIRestartURL)) {
// Call AttemptRestart after chrome::Navigate() completes to avoid access of
// gtk objects after they are destroyed by BrowserWindowGtk::Close().
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&chrome::AttemptRestart));
return true;
} else if (LowerCaseEqualsASCII(spec, chrome::kChromeUIQuitURL)) {
} else if (base::LowerCaseEqualsASCII(spec, chrome::kChromeUIQuitURL)) {
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&chrome::AttemptExit));
return true;
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/events/event_rewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ EventRewriter::DeviceType GetDeviceType(const std::string& device_name,
return EventRewriter::kDeviceHotrodRemote;
}

if (LowerCaseEqualsASCII(device_name, "virtual core keyboard"))
if (base::LowerCaseEqualsASCII(device_name, "virtual core keyboard"))
return EventRewriter::kDeviceVirtualCoreKeyboard;

std::vector<std::string> tokens;
Expand All @@ -157,9 +157,9 @@ EventRewriter::DeviceType GetDeviceType(const std::string& device_name,
bool found_apple = false;
bool found_keyboard = false;
for (size_t i = 0; i < tokens.size(); ++i) {
if (!found_apple && LowerCaseEqualsASCII(tokens[i], "apple"))
if (!found_apple && base::LowerCaseEqualsASCII(tokens[i], "apple"))
found_apple = true;
if (!found_keyboard && LowerCaseEqualsASCII(tokens[i], "keyboard"))
if (!found_keyboard && base::LowerCaseEqualsASCII(tokens[i], "keyboard"))
found_keyboard = true;
if (found_apple && found_keyboard)
return EventRewriter::kDeviceAppleKeyboard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest(
// static
bool ComponentExtensionIMEManagerImpl::IsIMEExtensionID(const std::string& id) {
for (size_t i = 0; i < arraysize(whitelisted_component_extension); ++i) {
if (LowerCaseEqualsASCII(id, whitelisted_component_extension[i].id))
if (base::LowerCaseEqualsASCII(id, whitelisted_component_extension[i].id))
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/download/download_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ DownloadDangerLevel GetFileDangerLevel(const base::FilePath& path) {
ascii_extension.erase(0, 1);

for (size_t i = 0; i < arraysize(g_executables); ++i) {
if (LowerCaseEqualsASCII(ascii_extension, g_executables[i].extension))
if (base::LowerCaseEqualsASCII(ascii_extension, g_executables[i].extension))
return g_executables[i].level;
}
return NOT_DANGEROUS;
Expand Down
18 changes: 9 additions & 9 deletions chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,17 @@ void IOThread::ConfigureSpdyGlobals(
}
if (spdy_trial_group.starts_with(kSpdyFieldTrialParametrizedPrefix)) {
bool spdy_enabled = false;
if (LowerCaseEqualsASCII(
if (base::LowerCaseEqualsASCII(
GetVariationParam(spdy_trial_params, "enable_spdy31"), "true")) {
globals->next_protos.push_back(net::kProtoSPDY31);
spdy_enabled = true;
}
if (LowerCaseEqualsASCII(
if (base::LowerCaseEqualsASCII(
GetVariationParam(spdy_trial_params, "enable_http2_14"), "true")) {
globals->next_protos.push_back(net::kProtoSPDY4_14);
spdy_enabled = true;
}
if (LowerCaseEqualsASCII(
if (base::LowerCaseEqualsASCII(
GetVariationParam(spdy_trial_params, "enable_http2"), "true")) {
globals->next_protos.push_back(net::kProtoSPDY4);
spdy_enabled = true;
Expand Down Expand Up @@ -1412,7 +1412,7 @@ bool IOThread::ShouldEnableQuicForDataReductionProxy() {
// static
bool IOThread::ShouldDisableInsecureQuic(
const VariationParameters& quic_trial_params) {
return LowerCaseEqualsASCII(
return base::LowerCaseEqualsASCII(
GetVariationParam(quic_trial_params, "disable_insecure_quic"),
"true");
}
Expand Down Expand Up @@ -1482,7 +1482,7 @@ double IOThread::GetAlternativeProtocolProbabilityThreshold(
// static
bool IOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
const VariationParameters& quic_trial_params) {
return LowerCaseEqualsASCII(
return base::LowerCaseEqualsASCII(
GetVariationParam(quic_trial_params,
"always_require_handshake_confirmation"),
"true");
Expand All @@ -1491,7 +1491,7 @@ bool IOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
// static
bool IOThread::ShouldQuicDisableConnectionPooling(
const VariationParameters& quic_trial_params) {
return LowerCaseEqualsASCII(
return base::LowerCaseEqualsASCII(
GetVariationParam(quic_trial_params, "disable_connection_pooling"),
"true");
}
Expand All @@ -1511,23 +1511,23 @@ float IOThread::GetQuicLoadServerInfoTimeoutSrttMultiplier(
// static
bool IOThread::ShouldQuicEnableConnectionRacing(
const VariationParameters& quic_trial_params) {
return LowerCaseEqualsASCII(
return base::LowerCaseEqualsASCII(
GetVariationParam(quic_trial_params, "enable_connection_racing"),
"true");
}

// static
bool IOThread::ShouldQuicEnableNonBlockingIO(
const VariationParameters& quic_trial_params) {
return LowerCaseEqualsASCII(
return base::LowerCaseEqualsASCII(
GetVariationParam(quic_trial_params, "enable_non_blocking_io"),
"true");
}

// static
bool IOThread::ShouldQuicDisableDiskCache(
const VariationParameters& quic_trial_params) {
return LowerCaseEqualsASCII(
return base::LowerCaseEqualsASCII(
GetVariationParam(quic_trial_params, "disable_disk_cache"), "true");
}

Expand Down
10 changes: 6 additions & 4 deletions chrome/browser/memory_details.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,13 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
const NavigationEntry* last_committed_entry =
contents->GetController().GetLastCommittedEntry();
if ((last_committed_entry &&
LowerCaseEqualsASCII(last_committed_entry->GetVirtualURL().spec(),
chrome::kChromeUIMemoryURL)) ||
base::LowerCaseEqualsASCII(
last_committed_entry->GetVirtualURL().spec(),
chrome::kChromeUIMemoryURL)) ||
(pending_entry &&
LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(),
chrome::kChromeUIMemoryURL))) {
base::LowerCaseEqualsASCII(
pending_entry->GetVirtualURL().spec(),
chrome::kChromeUIMemoryURL))) {
process.is_diagnostics = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/net/firefox_proxy_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ bool ParsePrefFile(const base::FilePath& pref_file,
stop_value - start_value - 1);
base::TrimWhitespace(value, base::TRIM_ALL, &value);
// Value could be a boolean.
bool is_value_true = LowerCaseEqualsASCII(value, "true");
if (is_value_true || LowerCaseEqualsASCII(value, "false")) {
bool is_value_true = base::LowerCaseEqualsASCII(value, "true");
if (is_value_true || base::LowerCaseEqualsASCII(value, "false")) {
prefs->SetBoolean(key, is_value_true);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/profiles/profile_impl_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ net::BackendType ChooseCacheBackendType() {
if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) {
const std::string opt_value =
command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend);
if (LowerCaseEqualsASCII(opt_value, "off"))
if (base::LowerCaseEqualsASCII(opt_value, "off"))
return net::CACHE_BACKEND_BLOCKFILE;
if (opt_value.empty() || LowerCaseEqualsASCII(opt_value, "on"))
if (opt_value.empty() || base::LowerCaseEqualsASCII(opt_value, "on"))
return net::CACHE_BACKEND_SIMPLE;
}
const std::string experiment_name =
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/safe_browsing/malware_details_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void MalwareDetailsCacheCollector::ReadResponse(
pb_response->add_headers();
pb_header->set_name(name);
// Strip any Set-Cookie headers.
if (LowerCaseEqualsASCII(name, "set-cookie")) {
if (base::LowerCaseEqualsASCII(name, "set-cookie")) {
pb_header->set_value("");
} else {
pb_header->set_value(value);
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/ssl/ssl_browser_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestWSSInvalidCertAndClose) {
// The title will be changed to 'PASS'.
ui_test_utils::NavigateToURL(browser(), master_url);
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));

// Close tabs which contains the test page.
for (int i = 0; i < 16; ++i)
Expand Down Expand Up @@ -844,7 +844,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) {
// Test page run a WebSocket wss connection test. The result will be shown
// as page title.
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));
}

#if defined(USE_NSS_CERTS)
Expand Down Expand Up @@ -931,7 +931,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITestWithClientCert, TestWSSClientCert) {
// Test page runs a WebSocket wss connection test. The result will be shown
// as page title.
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));
}
#endif // defined(USE_NSS_CERTS)

Expand Down Expand Up @@ -2083,7 +2083,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) {
// Test page run a WebSocket wss connection test. The result will be shown
// as page title.
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));
}

// Verifies that the interstitial can proceed, even if JavaScript is disabled.
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/themes/browser_theme_pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ int GetPersistentIDByNameHelper(const std::string& key,
const PersistingImagesTable* image_table,
size_t image_table_size) {
for (size_t i = 0; i < image_table_size; ++i) {
if (image_table[i].key && LowerCaseEqualsASCII(key, image_table[i].key)) {
if (image_table[i].key &&
base::LowerCaseEqualsASCII(key, image_table[i].key)) {
return image_table[i].persistent_id;
}
}
Expand Down Expand Up @@ -344,7 +345,7 @@ int GetIntForString(const std::string& key,
StringToIntTable* table,
size_t table_length) {
for (size_t i = 0; i < table_length; ++i) {
if (LowerCaseEqualsASCII(key, table[i].key)) {
if (base::LowerCaseEqualsASCII(key, table[i].key)) {
return table[i].id;
}
}
Expand Down
Loading

0 comments on commit bc17d2c

Please sign in to comment.