Revert 289312 "Move StringToUpperASCII and LowerCaseEqualsASCII ..."
> Move StringToUpperASCII and LowerCaseEqualsASCII to the base namespace
>
> Convert LowerCaseEqualsASCII to take StringPiece. In the current patch this is
> generally a NOP but will allow me to delete the other 4 variants in a followup
> (wanted to do that separately since that will require more review, since
> callsites will be changed in nontrivial ways).
>
> In some cases, LowerCaseEqualsASCII is called with a WebString, which no
> longer is implicitly converted. I added base::string16(...) around such
> calls to force the right conversion. It happened in these files:
> window_container_type.cc
> savable_resources.cc
> render_view_impl.cc
> blink_ax_tree_source.cc
> password_form_conversion_utils.cc
> translate_helper.cc
> chrome_render_view_observer.cc
> dom_serializer_browsertest.cc
>
> R=jamesr@chromium.org
>
> Review URL: https://codereview.chromium.org/448143008
TBR=brettw@chromium.org
Review URL: https://codereview.chromium.org/474483002
Cr-Commit-Position: refs/heads/master@{#289320}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289320 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: df80704e21578c439a2facfdaeabfe016d297353
diff --git a/base/environment.cc b/base/environment.cc
index 280469d..c547730 100644
--- a/base/environment.cc
+++ b/base/environment.cc
@@ -36,7 +36,7 @@
if (first_char >= 'a' && first_char <= 'z')
alternate_case_var = StringToUpperASCII(std::string(variable_name));
else if (first_char >= 'A' && first_char <= 'Z')
- alternate_case_var = StringToLowerASCII(std::string(variable_name));
+ alternate_case_var = base::StringToLowerASCII(std::string(variable_name));
else
return false;
return GetVarImpl(alternate_case_var.c_str(), result);
diff --git a/base/files/file_path.cc b/base/files/file_path.cc
index 2496e17..a8b2713 100644
--- a/base/files/file_path.cc
+++ b/base/files/file_path.cc
@@ -141,14 +141,13 @@
for (size_t i = 0; i < arraysize(kCommonDoubleExtensions); ++i) {
StringType extension(path, penultimate_dot + 1);
- if (base::LowerCaseEqualsASCII(extension, kCommonDoubleExtensions[i]))
+ if (LowerCaseEqualsASCII(extension, kCommonDoubleExtensions[i]))
return penultimate_dot;
}
StringType extension(path, last_dot + 1);
for (size_t i = 0; i < arraysize(kCommonDoubleExtensionSuffixes); ++i) {
- if (base::LowerCaseEqualsASCII(extension,
- kCommonDoubleExtensionSuffixes[i])) {
+ if (LowerCaseEqualsASCII(extension, kCommonDoubleExtensionSuffixes[i])) {
if ((last_dot - penultimate_dot) <= 5U &&
(last_dot - penultimate_dot) > 1U) {
return penultimate_dot;
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc
index 30737d6..392cb13 100644
--- a/base/i18n/rtl.cc
+++ b/base/i18n/rtl.cc
@@ -84,17 +84,17 @@
if (locale_string.substr(0, 2) != "es")
return locale_string;
// Expand es to es-ES.
- if (base::LowerCaseEqualsASCII(locale_string, "es"))
+ if (LowerCaseEqualsASCII(locale_string, "es"))
return "es-ES";
// Map es-419 (Latin American Spanish) to es-FOO depending on the system
// locale. If it's es-RR other than es-ES, map to es-RR. Otherwise, map
// to es-MX (the most populous in Spanish-speaking Latin America).
- if (base::LowerCaseEqualsASCII(locale_string, "es-419")) {
+ if (LowerCaseEqualsASCII(locale_string, "es-419")) {
const icu::Locale& locale = icu::Locale::getDefault();
std::string language = locale.getLanguage();
const char* country = locale.getCountry();
- if (base::LowerCaseEqualsASCII(language, "es") &&
- !base::LowerCaseEqualsASCII(country, "es")) {
+ if (LowerCaseEqualsASCII(language, "es") &&
+ !LowerCaseEqualsASCII(country, "es")) {
language += '-';
language += country;
return language;
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc
index 8d2bbc5..ab9570f 100644
--- a/base/strings/string_util.cc
+++ b/base/strings/string_util.cc
@@ -354,38 +354,38 @@
return true;
}
-template<typename StringType>
-static inline bool DoLowerCaseEqualsASCII(BasicStringPiece<StringType> str,
- const char* lower_cased_cmp) {
- for (typename BasicStringPiece<StringType>::const_iterator it = str.begin();
- it != str.end(); ++it, ++lower_cased_cmp) {
- if (!*lower_cased_cmp || base::ToLowerASCII(*it) != *lower_cased_cmp)
+} // 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)
return false;
}
- return *lower_cased_cmp == 0;
+ return *b == 0;
}
// Front-ends for LowerCaseEqualsASCII.
-bool LowerCaseEqualsASCII(StringPiece str, const char* lower_cased_cmp) {
- return DoLowerCaseEqualsASCII(str, lower_cased_cmp);
+bool LowerCaseEqualsASCII(const std::string& a, const char* b) {
+ return DoLowerCaseEqualsASCII(a.begin(), a.end(), b);
}
-bool LowerCaseEqualsASCII(StringPiece16 str, const char* lower_cased_cmp) {
- return DoLowerCaseEqualsASCII(str, lower_cased_cmp);
+bool LowerCaseEqualsASCII(const string16& a, const char* b) {
+ return DoLowerCaseEqualsASCII(a.begin(), a.end(), b);
}
bool LowerCaseEqualsASCII(std::string::const_iterator a_begin,
std::string::const_iterator a_end,
const char* b) {
- const char* a = &*a_begin;
- return LowerCaseEqualsASCII(StringPiece(a, a_end - a_begin), b);
+ return DoLowerCaseEqualsASCII(a_begin, a_end, b);
}
bool LowerCaseEqualsASCII(string16::const_iterator a_begin,
string16::const_iterator a_end,
const char* b) {
- const char16* a = &*a_begin;
- return LowerCaseEqualsASCII(StringPiece16(a, a_end - a_begin), b);
+ return DoLowerCaseEqualsASCII(a_begin, a_end, b);
}
// TODO(port): Resolve wchar_t/iterator issues that require OS_ANDROID here.
@@ -393,17 +393,16 @@
bool LowerCaseEqualsASCII(const char* a_begin,
const char* a_end,
const char* b) {
- return DoLowerCaseEqualsASCII(StringPiece(a_begin, a_end - a_begin), b);
+ return DoLowerCaseEqualsASCII(a_begin, a_end, b);
}
bool LowerCaseEqualsASCII(const char16* a_begin,
const char16* a_end,
const char* b) {
- return DoLowerCaseEqualsASCII(StringPiece16(a_begin, a_end - a_begin), b);
+ return DoLowerCaseEqualsASCII(a_begin, a_end, b);
}
-#endif // !defined(OS_ANDROID)
-} // namespace base
+#endif // !defined(OS_ANDROID)
bool EqualsASCII(const string16& a, const base::StringPiece& b) {
if (a.length() != b.length())
diff --git a/base/strings/string_util.h b/base/strings/string_util.h
index 1570a03..e20bbf0 100644
--- a/base/strings/string_util.h
+++ b/base/strings/string_util.h
@@ -263,6 +263,16 @@
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
+
// Converts the elements of the given string. This version uses a pointer to
// clearly differentiate it from the non-pointer variant.
template <class str> inline void StringToUpperASCII(str* s) {
@@ -277,18 +287,14 @@
return output;
}
-// Compare the lower-case form of the given string against the given
-// previously-lower-cased ASCII string. This is useful for doing checking if an
-// input string matches some token, and it is optimized to avoid intermediate
-// string copies.
-BASE_EXPORT bool LowerCaseEqualsASCII(StringPiece str,
- const char* lower_cased_cmp);
-BASE_EXPORT bool LowerCaseEqualsASCII(StringPiece16 str,
- const char* lower_cased_cmp);
+// 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);
// Same thing, but with string iterators instead.
-// TODO(brettw) remove these variants in preference for the StringPiece
-// versions above.
BASE_EXPORT bool LowerCaseEqualsASCII(std::string::const_iterator a_begin,
std::string::const_iterator a_end,
const char* b);
@@ -302,16 +308,6 @@
const base::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);
diff --git a/mojo/services/html_viewer/blink_url_request_type_converters.cc b/mojo/services/html_viewer/blink_url_request_type_converters.cc
index f083434..1f6553e 100644
--- a/mojo/services/html_viewer/blink_url_request_type_converters.cc
+++ b/mojo/services/html_viewer/blink_url_request_type_converters.cc
@@ -25,10 +25,10 @@
// Skip over referrer headers found in the header map because we already
// pulled it out as a separate parameter.
- if (base::LowerCaseEqualsASCII(name_latin1, "referer"))
+ if (LowerCaseEqualsASCII(name_latin1, "referer"))
return;
- if (base::LowerCaseEqualsASCII(name_latin1, "accept"))
+ if (LowerCaseEqualsASCII(name_latin1, "accept"))
has_accept_header_ = true;
buffer_.push_back(name_latin1 + ": " + value_latin1);
diff --git a/mojo/services/launcher/launcher.cc b/mojo/services/launcher/launcher.cc
index 8273d4c..b24d232 100644
--- a/mojo/services/launcher/launcher.cc
+++ b/mojo/services/launcher/launcher.cc
@@ -58,7 +58,7 @@
base::StringTokenizer t(headers[i], ": ;=");
while (t.GetNext()) {
if (!t.token_is_delim() &&
- base::LowerCaseEqualsASCII(t.token(), "content-type")) {
+ LowerCaseEqualsASCII(t.token(), "content-type")) {
while (t.GetNext()) {
if (!t.token_is_delim())
return t.token();