Replace base::str[n]casecmp with helper functions.
Adds CompareCaseInsensitiveASCII and EqualsCaseInsensitiveASCII helper functions and removes base::strcasecmp and base::strncasecmp. This avoids the dangerous locale-sensitive behavior.
ClientIsAdvertisingSdchEncoding in sdch_browsertest had the condition inverted, but because it returned true any time the given line wasn't found, the test didn't notice.
cups_helper changed most significantly. I redid the loop to use StringPieces which saves a lot of copies. On line 82 cups_helper used to do a prefix match which I'm pretty sure it wanted a regular compare. I changed this.
render_text_harfbuzz set "<" operator was also doing a prefix comparison only, when it looks like it really just wanted to compare the strings.
file_path passed string pieces into strcasecmp which could then read off the end if they're not null terminated. This patch fixes the bug and calls the native strcasecmp which is probably the best we can do for Posix file names.
Removed additional version of the same function in net.
Adds a backwards-compat hack for crashpad which improperly uses base from a DEPS-ed in repo.
Review URL: https://codereview.chromium.org/1224553010
Cr-Commit-Position: refs/heads/master@{#338324}
diff --git a/chrome/browser/media_galleries/fileapi/media_path_filter.cc b/chrome/browser/media_galleries/fileapi/media_path_filter.cc
index 0212e111..5b27f10 100644
--- a/chrome/browser/media_galleries/fileapi/media_path_filter.cc
+++ b/chrome/browser/media_galleries/fileapi/media_path_filter.cc
@@ -126,15 +126,12 @@
const char win_98_recycle_bin_name[] = "RECYCLED";
const char win_xp_recycle_bin_name[] = "RECYCLER";
const char win_vista_recycle_bin_name[] = "$Recycle.bin";
- if ((base::strncasecmp(base_name.c_str(),
- win_98_recycle_bin_name,
- strlen(win_98_recycle_bin_name)) == 0) ||
- (base::strncasecmp(base_name.c_str(),
- win_xp_recycle_bin_name,
- strlen(win_xp_recycle_bin_name)) == 0) ||
- (base::strncasecmp(base_name.c_str(),
- win_vista_recycle_bin_name,
- strlen(win_vista_recycle_bin_name)) == 0))
+ if (base::StartsWith(base_name, win_98_recycle_bin_name,
+ base::CompareCase::INSENSITIVE_ASCII) ||
+ base::StartsWith(base_name, win_xp_recycle_bin_name,
+ base::CompareCase::INSENSITIVE_ASCII) ||
+ base::StartsWith(base_name, win_vista_recycle_bin_name,
+ base::CompareCase::INSENSITIVE_ASCII))
return true;
#endif // defined(OS_WIN)
return false;
diff --git a/chrome/browser/net/sdch_browsertest.cc b/chrome/browser/net/sdch_browsertest.cc
index 7a1cb7b..9c93d6b 100644
--- a/chrome/browser/net/sdch_browsertest.cc
+++ b/chrome/browser/net/sdch_browsertest.cc
@@ -108,7 +108,7 @@
std::string* value) {
for (HttpRequestHeaderMap::const_iterator it = map.begin();
it != map.end(); ++it) {
- if (!base::strcasecmp(it->first.c_str(), header)) {
+ if (base::EqualsCaseInsensitiveASCII(it->first, header)) {
*value = it->second;
return true;
}
@@ -170,7 +170,7 @@
return false;
base::StringTokenizer tokenizer(value, " ,");
while (tokenizer.GetNext()) {
- if (base::strcasecmp(tokenizer.token().c_str(), "sdch"))
+ if (base::EqualsCaseInsensitiveASCII(tokenizer.token(), "sdch"))
return true;
}
return false;
diff --git a/chrome/browser/printing/printing_layout_browsertest.cc b/chrome/browser/printing/printing_layout_browsertest.cc
index 4e1d2b73..4755a18a 100644
--- a/chrome/browser/printing/printing_layout_browsertest.cc
+++ b/chrome/browser/printing/printing_layout_browsertest.cc
@@ -207,7 +207,7 @@
base::FilePath file;
while (!(file = enumerator.Next()).empty()) {
std::wstring ext = file.Extension();
- if (base::strcasecmp(base::WideToUTF8(ext).c_str(), ".emf") == 0) {
+ if (base::EqualsCaseInsensitiveASCII(base::WideToUTF8(ext), ".emf")) {
EXPECT_FALSE(found_emf) << "Found a leftover .EMF file: \"" <<
emf_file << "\" and \"" << file.value() <<
"\" when looking for \"" << verification_name << "\"";
@@ -215,7 +215,7 @@
emf_file = file.value();
continue;
}
- if (base::strcasecmp(base::WideToUTF8(ext).c_str(), ".prn") == 0) {
+ if (base::EqualsCaseInsensitiveASCII(base::WideToUTF8(ext), ".prn")) {
EXPECT_FALSE(found_prn) << "Found a leftover .PRN file: \"" <<
prn_file << "\" and \"" << file.value() <<
"\" when looking for \"" << verification_name << "\"";
diff --git a/chrome/service/cloud_print/cloud_print_connector.cc b/chrome/service/cloud_print/cloud_print_connector.cc
index a1f6be7..f53c865e6 100644
--- a/chrome/service/cloud_print/cloud_print_connector.cc
+++ b/chrome/service/cloud_print/cloud_print_connector.cc
@@ -653,7 +653,7 @@
bool CloudPrintConnector::IsSamePrinter(const std::string& name1,
const std::string& name2) const {
- return (0 == base::strcasecmp(name1.c_str(), name2.c_str()));
+ return base::EqualsCaseInsensitiveASCII(name1, name2);
}
} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
index f93215db..53485ccd 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
@@ -550,8 +550,8 @@
DCHECK(base::MessageLoop::current() == backend_->core_thread_.message_loop());
VLOG(1) << "CP_CONNECTOR: Incoming notification.";
- if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource,
- notification.channel.c_str()))
+ if (base::EqualsCaseInsensitiveASCII(kCloudPrintPushNotificationsSource,
+ notification.channel))
HandlePrinterNotification(notification.data);
}
diff --git a/chrome/test/chromedriver/performance_logger.cc b/chrome/test/chromedriver/performance_logger.cc
index 37e66f4..f97385b6 100644
--- a/chrome/test/chromedriver/performance_logger.cc
+++ b/chrome/test/chromedriver/performance_logger.cc
@@ -43,7 +43,8 @@
bool ShouldRequestTraceEvents(const std::string& command) {
for (size_t i_domain = 0; i_domain < arraysize(kRequestTraceCommands);
++i_domain) {
- if (base::strcasecmp(command.c_str(), kRequestTraceCommands[i_domain]) == 0)
+ if (base::EqualsCaseInsensitiveASCII(command,
+ kRequestTraceCommands[i_domain]))
return true;
}
return false;