Remove some legacy versions of StartsWith and EndsWith.
This just replaces
true -> base::CompareCase::SENSITIVE
false -> base::CompareCase::INSENSITIVE_ASCII
I checked the insensitive cases to make sure they're not doing anything suspicious. The old version is a sometimes-correct Unicode comparison so converting to INSENSTITIVE_ASCII isn't a no-op. However, generally the prefix/suffix checking is done against a hardcoded string so there were very few cases to actually look at.
extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc has a not-quite search-and-replace change where I changed the type of a class variable.
BUG=506255
TBR=jam
Reland of http://crrev.com/1239493005
Review URL: https://codereview.chromium.org/1233043003
Cr-Commit-Position: refs/heads/master@{#339071}
CrOS-Libchrome-Original-Commit: a7ff1b291cd328e9584779a4bb9101fa9a3c01ad
diff --git a/base/android/library_loader/library_prefetcher.cc b/base/android/library_loader/library_prefetcher.cc
index 798a283..9b54843 100644
--- a/base/android/library_loader/library_prefetcher.cc
+++ b/base/android/library_loader/library_prefetcher.cc
@@ -36,7 +36,7 @@
bool PathMatchesSuffix(const std::string& path) {
for (size_t i = 0; i < arraysize(kSuffixesToMatch); i++) {
- if (EndsWith(path, kSuffixesToMatch[i], true)) {
+ if (EndsWith(path, kSuffixesToMatch[i], CompareCase::SENSITIVE)) {
return true;
}
}
@@ -82,14 +82,14 @@
std::vector<AddressRange>* ranges) {
bool has_libchrome_region = false;
for (const base::debug::MappedMemoryRegion& region : regions) {
- if (EndsWith(region.path, kLibchromeSuffix, true)) {
+ if (EndsWith(region.path, kLibchromeSuffix, CompareCase::SENSITIVE)) {
has_libchrome_region = true;
break;
}
}
for (const base::debug::MappedMemoryRegion& region : regions) {
if (has_libchrome_region &&
- !EndsWith(region.path, kLibchromeSuffix, true)) {
+ !EndsWith(region.path, kLibchromeSuffix, CompareCase::SENSITIVE)) {
continue;
}
ranges->push_back(std::make_pair(region.start, region.end));
diff --git a/base/strings/string_util.h b/base/strings/string_util.h
index d7a08c8..755215c 100644
--- a/base/strings/string_util.h
+++ b/base/strings/string_util.h
@@ -381,19 +381,6 @@
case_sensitive ? CompareCase::SENSITIVE
: CompareCase::INSENSITIVE_ASCII);
}
-BASE_EXPORT bool StartsWith(const string16& str,
- const string16& search,
- bool case_sensitive);
-inline bool EndsWith(const std::string& str,
- const std::string& search,
- bool case_sensitive) {
- return EndsWith(StringPiece(str), StringPiece(search),
- case_sensitive ? CompareCase::SENSITIVE
- : CompareCase::INSENSITIVE_ASCII);
-}
-BASE_EXPORT bool EndsWith(const string16& str,
- const string16& search,
- bool case_sensitive);
// Determines the type of ASCII character, independent of locale (the C
// library versions will change based on locale).
diff --git a/base/strings/string_util_unittest.cc b/base/strings/string_util_unittest.cc
index 5d5ba8b..eb6cd7e 100644
--- a/base/strings/string_util_unittest.cc
+++ b/base/strings/string_util_unittest.cc
@@ -706,59 +706,83 @@
}
TEST(StringUtilTest, StartsWith) {
- EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true));
- EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true));
- EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false));
- EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false));
- EXPECT_FALSE(StartsWithASCII("java", "javascript", true));
- EXPECT_FALSE(StartsWithASCII("java", "javascript", false));
- EXPECT_FALSE(StartsWithASCII(std::string(), "javascript", false));
- EXPECT_FALSE(StartsWithASCII(std::string(), "javascript", true));
- EXPECT_TRUE(StartsWithASCII("java", std::string(), false));
- EXPECT_TRUE(StartsWithASCII("java", std::string(), true));
+ EXPECT_TRUE(StartsWith("javascript:url", "javascript",
+ base::CompareCase::SENSITIVE));
+ EXPECT_FALSE(StartsWith("JavaScript:url", "javascript",
+ base::CompareCase::SENSITIVE));
+ EXPECT_TRUE(StartsWith("javascript:url", "javascript",
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_TRUE(StartsWith("JavaScript:url", "javascript",
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(StartsWith("java", "javascript", base::CompareCase::SENSITIVE));
+ EXPECT_FALSE(StartsWith("java", "javascript",
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(StartsWith(std::string(), "javascript",
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(StartsWith(std::string(), "javascript",
+ base::CompareCase::SENSITIVE));
+ EXPECT_TRUE(StartsWith("java", std::string(),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_TRUE(StartsWith("java", std::string(), base::CompareCase::SENSITIVE));
EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"),
- ASCIIToUTF16("javascript"), true));
+ ASCIIToUTF16("javascript"),
+ base::CompareCase::SENSITIVE));
EXPECT_FALSE(StartsWith(ASCIIToUTF16("JavaScript:url"),
- ASCIIToUTF16("javascript"), true));
+ ASCIIToUTF16("javascript"),
+ base::CompareCase::SENSITIVE));
EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"),
- ASCIIToUTF16("javascript"), false));
+ ASCIIToUTF16("javascript"),
+ base::CompareCase::INSENSITIVE_ASCII));
EXPECT_TRUE(StartsWith(ASCIIToUTF16("JavaScript:url"),
- ASCIIToUTF16("javascript"), false));
- EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"),
- ASCIIToUTF16("javascript"), true));
- EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"),
- ASCIIToUTF16("javascript"), false));
- EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"), false));
- EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"), true));
- EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(), false));
- EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(), true));
+ ASCIIToUTF16("javascript"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"), ASCIIToUTF16("javascript"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"), ASCIIToUTF16("javascript"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(),
+ base::CompareCase::SENSITIVE));
}
TEST(StringUtilTest, EndsWith) {
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"),
- ASCIIToUTF16(".plugin"), true));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.Plugin"),
- ASCIIToUTF16(".plugin"), true));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.Plugin"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"), true));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"),
- ASCIIToUTF16(".plugin"), true));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), true));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), false));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), true));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"), true));
- EXPECT_TRUE(EndsWith(string16(), string16(), false));
- EXPECT_TRUE(EndsWith(string16(), string16(), true));
+ EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.Plugin"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.Plugin"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(),
+ base::CompareCase::SENSITIVE));
+ EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"),
+ base::CompareCase::SENSITIVE));
+ EXPECT_TRUE(
+ EndsWith(string16(), string16(), base::CompareCase::INSENSITIVE_ASCII));
+ EXPECT_TRUE(EndsWith(string16(), string16(), base::CompareCase::SENSITIVE));
}
TEST(StringUtilTest, GetStringFWithOffsets) {
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index e281cff..2910466 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -338,7 +338,7 @@
i18n::SetICUDefaultLocale("en_US");
#else
std::string default_locale(uloc_getDefault());
- if (EndsWith(default_locale, "POSIX", false))
+ if (EndsWith(default_locale, "POSIX", CompareCase::INSENSITIVE_ASCII))
i18n::SetICUDefaultLocale("en_US");
#endif
#endif
diff --git a/dbus/string_util.cc b/dbus/string_util.cc
index 0b07786..16e483a 100644
--- a/dbus/string_util.cc
+++ b/dbus/string_util.cc
@@ -8,13 +8,10 @@
namespace dbus {
+// This implementation is based upon D-Bus Specification Version 0.19.
bool IsValidObjectPath(const std::string& value) {
- // This implementation is based upon D-Bus Specification Version 0.19.
-
- const bool kCaseSensitive = true;
-
// A valid object path begins with '/'.
- if (!base::StartsWithASCII(value, "/", kCaseSensitive))
+ if (!base::StartsWith(value, "/", base::CompareCase::SENSITIVE))
return false;
// Elements are pieces delimited by '/'. For instance, "org", "chromium",
@@ -39,7 +36,8 @@
}
// A trailing '/' character is not allowed unless the path is the root path.
- if (value.size() > 1 && base::EndsWith(value, "/", kCaseSensitive))
+ if (value.size() > 1 &&
+ base::EndsWith(value, "/", base::CompareCase::SENSITIVE))
return false;
return true;
diff --git a/mojo/runner/shell_apptest.cc b/mojo/runner/shell_apptest.cc
index 70f7864..2a943d6 100644
--- a/mojo/runner/shell_apptest.cc
+++ b/mojo/runner/shell_apptest.cc
@@ -184,7 +184,8 @@
application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable);
auto callback = [this](const String& app_url, const String& connection_url,
const String& message) {
- EXPECT_TRUE(base::EndsWith(app_url, "/pingable_app.mojo", true));
+ EXPECT_TRUE(base::EndsWith(app_url, "/pingable_app.mojo",
+ base::CompareCase::SENSITIVE));
EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url);
EXPECT_EQ("hello", message);
base::MessageLoop::current()->Quit();