diff options
author | brettw <brettw@chromium.org> | 2015-07-23 14:56:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-23 21:57:37 +0000 |
commit | 85111674b30562ab0ba3a0f7d3b09761fdc09e00 (patch) | |
tree | a8ac1e3a51e6322156244b9b86516ccaccb2507d | |
parent | 666686c757e8c17d47ec2036e718eb85ca26fb1c (diff) | |
download | chromium_src-85111674b30562ab0ba3a0f7d3b09761fdc09e00.zip chromium_src-85111674b30562ab0ba3a0f7d3b09761fdc09e00.tar.gz chromium_src-85111674b30562ab0ba3a0f7d3b09761fdc09e00.tar.bz2 |
Unify LowerCaseEqualsASCII and EqualsASCII functions.
This removes the many overrides and unifies on StringPIece implementations.
StringPiece did not exist when these functions were written. The lack of
StringPiece versions make it difficult to use when (typically newer) code has a
StringPiece (for example, see affiliation_utils.cc), and StringPiece versions
can't be added because it will be ambiguous with the std::string versions.
There are a few dozen places where a WebString is passed into these functions.
A WebString can not be implicitly converted into a StringPiece, so I added
explicit base::StringPiece16 wrappers around the necessary parameters. This is
actually nice because it emphasizes that a temporary is created. In a few
places it does this redundantly and I pulled a string16 out (for example,
drop_data_builder.cc).
Callers that were using the iterator versions got converted to constructing
a StringPiece with iterators. This was the case mostly for net where this
pattern seems common.
A few cases, such as data_reduction_proxy_config.cc were actually trying to
do prefix matches. I converted these to StartsWith (cur current, more-
convenient version of StartsWith is relatively new). Theoretically these
aren't equivalent because StartsWith doesn't assume a previously-lower-cased
2nd argument. But the strings are short and the convenience makes up for the
difference.
I converted the define HTTP_LWS to a constant kHttpLinearWhitespace to avoid
polluting the global namespace. This traces back to the original commit with
a vague comment about overriding at buildtime (which can't happen). I kept
the define in the .cc file because header pollution is less and C constant
concatenation is used with this in a few places that would require a
constant with confusing description or a temporary to be created.
http_response_headers.cc: changed some functions to StringPIeces that used
iterators for convenience and clarity.
Added a TrimLWSPiece to NetUtil for convenience in the header parsing code.
Significantly updated HttpUtil::ParseContentType to use StringPieces.
Review URL: https://codereview.chromium.org/1242673002
Cr-Commit-Position: refs/heads/master@{#340176}
33 files changed, 215 insertions, 228 deletions
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc index b6fad29..725d86d 100644 --- a/base/strings/string_util.cc +++ b/base/strings/string_util.cc @@ -509,66 +509,45 @@ bool IsStringUTF8(const StringPiece& str) { return true; } -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 || ToLowerASCII(*it) != *b) +// Implementation note: Normally this function will be called with a hardcoded +// constant for the lowercase_ascii parameter. Constructing a StringPiece from +// a C constant requires running strlen, so the result will be two passes +// through the buffers, one to file the length of lowercase_ascii, and one to +// compare each letter. +// +// This function could have taken a const char* to avoid this and only do one +// pass through the string. But the strlen is faster than the case-insensitive +// compares and lets us early-exit in the case that the strings are different +// lengths (will often be the case for non-matches). So whether one approach or +// the other will be faster depends on the case. +// +// The hardcoded strings are typically very short so it doesn't matter, and the +// string piece gives additional flexibility for the caller (doesn't have to be +// null terminated) so we choose the StringPiece route. +template<typename Str> +static inline bool DoLowerCaseEqualsASCII(BasicStringPiece<Str> str, + StringPiece lowercase_ascii) { + if (str.size() != lowercase_ascii.size()) + return false; + for (size_t i = 0; i < str.size(); i++) { + if (ToLowerASCII(str[i]) != lowercase_ascii[i]) return false; } - return *b == 0; -} - -// Front-ends for LowerCaseEqualsASCII. -bool LowerCaseEqualsASCII(const std::string& a, const char* b) { - return DoLowerCaseEqualsASCII(a.begin(), a.end(), b); -} - -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) { - return DoLowerCaseEqualsASCII(a_begin, a_end, b); -} - -bool LowerCaseEqualsASCII(string16::const_iterator a_begin, - string16::const_iterator a_end, - const char* b) { - return DoLowerCaseEqualsASCII(a_begin, a_end, b); -} - -bool LowerCaseEqualsASCII(const char* a_begin, - const char* a_end, - const char* b) { - return DoLowerCaseEqualsASCII(a_begin, a_end, b); + return true; } -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(StringPiece str, StringPiece lowercase_ascii) { + return DoLowerCaseEqualsASCII<std::string>(str, lowercase_ascii); } -bool LowerCaseEqualsASCII(const char16* a_begin, - const char16* a_end, - const char* b) { - return DoLowerCaseEqualsASCII(a_begin, a_end, b); +bool LowerCaseEqualsASCII(StringPiece16 str, StringPiece lowercase_ascii) { + return DoLowerCaseEqualsASCII<string16>(str, lowercase_ascii); } -bool EqualsASCII(const string16& a, const StringPiece& b) { - if (a.length() != b.length()) +bool EqualsASCII(StringPiece16 str, StringPiece ascii) { + if (str.length() != ascii.length()) return false; - return std::equal(b.begin(), b.end(), a.begin()); + return std::equal(ascii.begin(), ascii.end(), str.begin()); } template<typename Str> diff --git a/base/strings/string_util.h b/base/strings/string_util.h index 4f113ed..01dc3fc 100644 --- a/base/strings/string_util.h +++ b/base/strings/string_util.h @@ -316,35 +316,18 @@ template <class str> inline str StringToUpperASCII(const str& s) { StringToUpperASCII(&output); return output; } -// -// 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 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(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 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); - -// Performs a case-sensitive string compare. The behavior is undefined if both -// strings are not ASCII. -BASE_EXPORT bool EqualsASCII(const string16& a, const StringPiece& b); + +// Compare the lower-case form of the given string against the given +// previously-lower-cased ASCII string (typically a constant). +BASE_EXPORT bool LowerCaseEqualsASCII(StringPiece str, + StringPiece lowecase_ascii); +BASE_EXPORT bool LowerCaseEqualsASCII(StringPiece16 str, + StringPiece lowecase_ascii); + +// Performs a case-sensitive string compare of the given 16-bit string against +// the given 8-bit ASCII string (typically a constant). The behavior is +// undefined if the |ascii| string is not ASCII. +BASE_EXPORT bool EqualsASCII(StringPiece16 str, StringPiece ascii); // Indicates case sensitivity of comparisons. Only ASCII case insensitivity // is supported. Full Unicode case-insensitive conversions would need to go in diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index ad59ffb..9413042 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -610,7 +610,8 @@ SkBitmap* ChromeContentRendererClient::GetSadWebViewBitmap() { #if defined(ENABLE_EXTENSIONS) const Extension* ChromeContentRendererClient::GetExtensionByOrigin( const WebSecurityOrigin& origin) const { - if (!base::EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) + if (!base::EqualsASCII(base::StringPiece16(origin.protocol()), + extensions::kExtensionScheme)) return NULL; const std::string extension_id = origin.host().utf8().data(); @@ -1141,7 +1142,8 @@ void ChromeContentRendererClient::GetNavigationErrorStrings( base::string16* error_description) { const GURL failed_url = error.unreachableURL; - bool is_post = base::EqualsASCII(failed_request.httpMethod(), "POST"); + bool is_post = base::EqualsASCII( + base::StringPiece16(failed_request.httpMethod()), "POST"); if (error_html) { // TODO(ellyjones): change GetNavigationErrorStrings to take a RenderFrame diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index e125e6b..e64d620 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -485,7 +485,8 @@ bool ChromeRenderViewObserver::HasRefreshMetaTag(WebFrame* frame) { if (!element.hasHTMLTagName(tag_name)) continue; WebString value = element.getAttribute(attribute_name); - if (value.isNull() || !base::LowerCaseEqualsASCII(value, "refresh")) + if (value.isNull() || + !base::LowerCaseEqualsASCII(base::StringPiece16(value), "refresh")) continue; return true; } diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc index 7204e93..e410a1d 100644 --- a/chrome/renderer/content_settings_observer.cc +++ b/chrome/renderer/content_settings_observer.cc @@ -670,7 +670,8 @@ bool ContentSettingsObserver::IsPlatformApp() { #if defined(ENABLE_EXTENSIONS) const extensions::Extension* ContentSettingsObserver::GetExtension( const WebSecurityOrigin& origin) const { - if (!base::EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) + if (!base::EqualsASCII(base::StringPiece16(origin.protocol()), + extensions::kExtensionScheme)) return NULL; const std::string extension_id = origin.host().utf8().data(); @@ -704,14 +705,15 @@ bool ContentSettingsObserver::IsWhitelistedForContentSettings( if (origin.isUnique()) return false; // Uninitialized document? - if (base::EqualsASCII(origin.protocol(), content::kChromeUIScheme)) + base::string16 protocol = origin.protocol(); + if (base::EqualsASCII(protocol, content::kChromeUIScheme)) return true; // Browser UI elements should still work. - if (base::EqualsASCII(origin.protocol(), content::kChromeDevToolsScheme)) + if (base::EqualsASCII(protocol, content::kChromeDevToolsScheme)) return true; // DevTools UI elements should still work. #if defined(ENABLE_EXTENSIONS) - if (base::EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) + if (base::EqualsASCII(protocol, extensions::kExtensionScheme)) return true; #endif @@ -722,7 +724,7 @@ bool ContentSettingsObserver::IsWhitelistedForContentSettings( // If the scheme is file:, an empty file name indicates a directory listing, // which requires JavaScript to function properly. - if (base::EqualsASCII(origin.protocol(), url::kFileScheme)) { + if (base::EqualsASCII(protocol, url::kFileScheme)) { return document_url.SchemeIs(url::kFileScheme) && document_url.ExtractFileName().empty(); } diff --git a/chrome/renderer/net/net_error_helper.cc b/chrome/renderer/net/net_error_helper.cc index 588cf27..3ec8b91 100644 --- a/chrome/renderer/net/net_error_helper.cc +++ b/chrome/renderer/net/net_error_helper.cc @@ -310,8 +310,9 @@ void NetErrorHelper::ReloadPage() { void NetErrorHelper::LoadPageFromCache(const GURL& page_url) { blink::WebFrame* web_frame = render_frame()->GetWebFrame(); - DCHECK(!base::EqualsASCII(web_frame->dataSource()->request().httpMethod(), - "POST")); + DCHECK(!base::EqualsASCII( + base::StringPiece16(web_frame->dataSource()->request().httpMethod()), + "POST")); blink::WebURLRequest request(page_url); request.setCachePolicy(blink::WebURLRequest::ReturnCacheDataDontLoad); diff --git a/chrome/renderer/safe_browsing/phishing_classifier.cc b/chrome/renderer/safe_browsing/phishing_classifier.cc index e1d1926..91fa589 100644 --- a/chrome/renderer/safe_browsing/phishing_classifier.cc +++ b/chrome/renderer/safe_browsing/phishing_classifier.cc @@ -127,7 +127,9 @@ void PhishingClassifier::BeginFeatureExtraction() { } blink::WebDataSource* ds = frame->dataSource(); - if (!ds || !base::EqualsASCII(ds->request().httpMethod(), "GET")) { + if (!ds || + !base::EqualsASCII(base::StringPiece16(ds->request().httpMethod()), + "GET")) { RunFailureCallback(); return; } diff --git a/chrome/renderer/web_apps.cc b/chrome/renderer/web_apps.cc index 95514bb..98d1afa 100644 --- a/chrome/renderer/web_apps.cc +++ b/chrome/renderer/web_apps.cc @@ -175,10 +175,12 @@ void ParseWebAppFromWebDocument(WebFrame* frame, if (!app_info->app_url.is_valid()) app_info->app_url = GURL(); } else if (name == "mobile-web-app-capable" && - base::LowerCaseEqualsASCII(content, "yes")) { + base::LowerCaseEqualsASCII(base::StringPiece16(content), + "yes")) { app_info->mobile_capable = WebApplicationInfo::MOBILE_CAPABLE; } else if (name == "apple-mobile-web-app-capable" && - base::LowerCaseEqualsASCII(content, "yes") && + base::LowerCaseEqualsASCII( + base::StringPiece16(content), "yes") && app_info->mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED) { app_info->mobile_capable = WebApplicationInfo::MOBILE_CAPABLE_APPLE; diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc index 2d43a30..7e96dd7 100644 --- a/components/autofill/content/renderer/form_autofill_util.cc +++ b/components/autofill/content/renderer/form_autofill_util.cc @@ -1182,7 +1182,8 @@ void WebFormControlElementToFormField(const WebFormControlElement& element, // attribute was present. field->autocomplete_attribute = "x-max-data-length-exceeded"; } - if (base::LowerCaseEqualsASCII(element.getAttribute(kRole), "presentation")) + if (base::LowerCaseEqualsASCII( + base::StringPiece16(element.getAttribute(kRole)), "presentation")) field->role = FormFieldData::ROLE_ATTRIBUTE_PRESENTATION; if (!IsAutofillableElement(element)) diff --git a/components/autofill/content/renderer/password_form_conversion_utils.cc b/components/autofill/content/renderer/password_form_conversion_utils.cc index 22be42e..a50fb03e 100644 --- a/components/autofill/content/renderer/password_form_conversion_utils.cc +++ b/components/autofill/content/renderer/password_form_conversion_utils.cc @@ -101,8 +101,9 @@ PasswordForm::Layout SequenceToLayout(base::StringPiece layout_sequence) { // |element| is present and has the specified |value_in_lowercase|. bool HasAutocompleteAttributeValue(const WebInputElement& element, const char* value_in_lowercase) { - return base::LowerCaseEqualsASCII(element.getAttribute("autocomplete"), - value_in_lowercase); + return base::LowerCaseEqualsASCII( + base::StringPiece16(element.getAttribute("autocomplete")), + value_in_lowercase); } // Helper to determine which password is the main (current) one, and which is diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc index 6916e40..36f09fb 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc @@ -831,11 +831,8 @@ bool DataReductionProxyConfig::MaybeDisableIfVPN() { // Data Saver will not be disabled on any other platform on VPN. const std::string vpn_interface_name_prefix = "tun"; for (size_t i = 0; i < network_interfaces.size(); ++i) { - std::string interface_name = network_interfaces[i].name; - if (base::LowerCaseEqualsASCII( - interface_name.begin(), - interface_name.begin() + vpn_interface_name_prefix.size(), - vpn_interface_name_prefix.c_str())) { + if (base::StartsWith(network_interfaces[i].name, vpn_interface_name_prefix, + base::CompareCase::INSENSITIVE_ASCII)) { disabled_on_vpn_ = true; ReloadConfig(); RecordNetworkChangeEvent(DISABLED_ON_VPN); diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc index b423275..0edb70f 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc @@ -74,8 +74,8 @@ bool GetDataReductionProxyActionValue( while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { if (value.size() > prefix.size()) { - if (base::LowerCaseEqualsASCII( - value.begin(), value.begin() + prefix.size(), prefix.c_str())) { + if (base::StartsWith(value, prefix, + base::CompareCase::INSENSITIVE_ASCII)) { if (action_value) *action_value = value.substr(prefix.size()); return true; @@ -98,8 +98,8 @@ bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers, while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { if (value.size() > prefix.size()) { - if (base::LowerCaseEqualsASCII( - value.begin(), value.begin() + prefix.size(), prefix.c_str())) { + if (base::StartsWith(value, prefix, + base::CompareCase::INSENSITIVE_ASCII)) { int64 seconds; if (!base::StringToInt64( StringPiece(value.begin() + prefix.size(), value.end()), @@ -303,10 +303,8 @@ void GetDataReductionProxyHeaderWithFingerprintRemoved( void* iter = NULL; while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { if (value.size() > chrome_proxy_fingerprint_prefix.size()) { - if (base::LowerCaseEqualsASCII( - value.begin(), - value.begin() + chrome_proxy_fingerprint_prefix.size(), - chrome_proxy_fingerprint_prefix.c_str())) { + if (base::StartsWith(value, chrome_proxy_fingerprint_prefix, + base::CompareCase::INSENSITIVE_ASCII)) { continue; } } diff --git a/components/history/core/browser/visitsegment_database.cc b/components/history/core/browser/visitsegment_database.cc index 891c1b5..afeecb7 100644 --- a/components/history/core/browser/visitsegment_database.cc +++ b/components/history/core/browser/visitsegment_database.cc @@ -105,10 +105,9 @@ std::string VisitSegmentDatabase::ComputeSegmentName(const GURL& url) { const int kWWWDotLen = arraysize(kWWWDot) - 1; std::string host = url.host(); - const char* host_c = host.c_str(); // Remove www. to avoid some dups. if (static_cast<int>(host.size()) > kWWWDotLen && - base::LowerCaseEqualsASCII(host_c, host_c + kWWWDotLen, kWWWDot)) { + base::StartsWith(host, kWWWDot, base::CompareCase::INSENSITIVE_ASCII)) { r.SetHost(host.c_str(), url::Component(kWWWDotLen, static_cast<int>(host.size()) - kWWWDotLen)); diff --git a/components/password_manager/core/browser/affiliation_utils.cc b/components/password_manager/core/browser/affiliation_utils.cc index 2b16e8b..49b25c2 100644 --- a/components/password_manager/core/browser/affiliation_utils.cc +++ b/components/password_manager/core/browser/affiliation_utils.cc @@ -182,11 +182,9 @@ bool ParseAndCanonicalizeFacetURI(const std::string& input_uri, url::ParseStandardURL(input_uri.c_str(), input_uri.size(), &input_parsed); base::StringPiece scheme = ComponentString(input_uri, input_parsed.scheme); - if (base::LowerCaseEqualsASCII(scheme.begin(), scheme.end(), - url::kHttpsScheme)) { + if (base::LowerCaseEqualsASCII(scheme, url::kHttpsScheme)) { return CanonicalizeWebFacetURI(input_uri, input_parsed, canonical_uri); - } else if (base::LowerCaseEqualsASCII(scheme.begin(), scheme.end(), - kAndroidAppScheme)) { + } else if (base::LowerCaseEqualsASCII(scheme, kAndroidAppScheme)) { return CanonicalizeAndroidFacetURI(input_uri, input_parsed, canonical_uri); } return false; diff --git a/components/translate/content/renderer/translate_helper.cc b/components/translate/content/renderer/translate_helper.cc index 121cc32..41531bd 100644 --- a/components/translate/content/renderer/translate_helper.cc +++ b/components/translate/content/renderer/translate_helper.cc @@ -116,7 +116,8 @@ bool HasNoTranslateMeta(WebDocument* document) { attribute = element.getAttribute(content); if (attribute.isNull()) continue; - if (base::LowerCaseEqualsASCII(attribute, "notranslate")) + if (base::LowerCaseEqualsASCII(base::StringPiece16(attribute), + "notranslate")) return true; } return false; diff --git a/content/common/android/address_parser.cc b/content/common/android/address_parser.cc index 2b0478a..bed843d 100644 --- a/content/common/android/address_parser.cc +++ b/content/common/android/address_parser.cc @@ -171,12 +171,12 @@ bool FindAddress(const base::string16::const_iterator& begin, if (current_word_length == 2 && words.size() > 2) { const Word& previous_word = words[state_first_word - 1]; if (previous_word.end - previous_word.begin == 2 && - base::LowerCaseEqualsASCII(previous_word.begin, - previous_word.end, - "et") && - base::LowerCaseEqualsASCII(current_word.begin, - current_word.end, - "al")) + base::LowerCaseEqualsASCII( + base::StringPiece16(previous_word.begin, previous_word.end), + "et") && + base::LowerCaseEqualsASCII( + base::StringPiece16(current_word.begin, current_word.end), + "al")) break; } diff --git a/content/common/android/address_parser_internal.cc b/content/common/android/address_parser_internal.cc index 79e1d31..e1ee2b4 100644 --- a/content/common/android/address_parser_internal.cc +++ b/content/common/android/address_parser_internal.cc @@ -157,7 +157,9 @@ bool HouseNumberParser::Parse( if (base::IsAsciiAlpha(*it_)) { // Handle special case 'one'. if (result_chars_ == 0) { - if (it_ + 3 <= end_ && base::LowerCaseEqualsASCII(it_, it_ + 3, "one")) + if (it_ + 3 <= end_ && + base::LowerCaseEqualsASCII(base::StringPiece16(it_, it_ + 3), + "one")) AcceptChars(3); else RestartOnNextDelimiter(); diff --git a/content/common/cross_site_document_classifier.cc b/content/common/cross_site_document_classifier.cc index c57c2f4..4231610 100644 --- a/content/common/cross_site_document_classifier.cc +++ b/content/common/cross_site_document_classifier.cc @@ -40,16 +40,9 @@ bool MatchesSignature(StringPiece data, return false; data.remove_prefix(offset); - size_t length = data.length(); - for (size_t sig_index = 0; sig_index < arr_size; ++sig_index) { - const StringPiece& signature = signatures[sig_index]; - size_t signature_length = signature.length(); - if (length < signature_length) - continue; - - if (base::LowerCaseEqualsASCII( - data.begin(), data.begin() + signature_length, signature.data())) + if (base::StartsWith(data, signatures[sig_index], + base::CompareCase::INSENSITIVE_ASCII)) return true; } return false; diff --git a/content/public/common/window_container_type.cc b/content/public/common/window_container_type.cc index 57c91d0..adbae30 100644 --- a/content/public/common/window_container_type.cc +++ b/content/public/common/window_container_type.cc @@ -22,11 +22,10 @@ WindowContainerType WindowFeaturesToContainerType( bool persistent = false; for (size_t i = 0; i < window_features.additionalFeatures.size(); ++i) { - if (base::LowerCaseEqualsASCII(window_features.additionalFeatures[i], - kBackground)) + base::string16 feature = window_features.additionalFeatures[i]; + if (base::LowerCaseEqualsASCII(feature, kBackground)) background = true; - else if (base::LowerCaseEqualsASCII(window_features.additionalFeatures[i], - kPersistent)) + else if (base::LowerCaseEqualsASCII(feature, kPersistent)) persistent = true; } diff --git a/content/renderer/dom_serializer_browsertest.cc b/content/renderer/dom_serializer_browsertest.cc index f0601d5..78dbe91 100644 --- a/content/renderer/dom_serializer_browsertest.cc +++ b/content/renderer/dom_serializer_browsertest.cc @@ -108,7 +108,8 @@ bool IsMetaElement(const WebNode& node, std::string& charset_info) { charset_info.erase(0, charset_info.length()); // Check the META charset declaration. WebString httpEquiv = meta.getAttribute("http-equiv"); - if (base::LowerCaseEqualsASCII(httpEquiv, "content-type")) { + if (base::LowerCaseEqualsASCII(base::StringPiece16(httpEquiv), + "content-type")) { std::string content = meta.getAttribute("content").utf8(); int pos = content.find("charset", 0); if (pos > -1) { diff --git a/content/renderer/drop_data_builder.cc b/content/renderer/drop_data_builder.cc index bff73f5..a1d10cd 100644 --- a/content/renderer/drop_data_builder.cc +++ b/content/renderer/drop_data_builder.cc @@ -26,23 +26,21 @@ DropData DropDataBuilder::Build(const WebDragData& drag_data) { const WebDragData::Item& item = item_list[i]; switch (item.storageType) { case WebDragData::Item::StorageTypeString: { - if (base::EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { + base::string16 str_type(item.stringType); + if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeText)) { result.text = base::NullableString16(item.stringData, false); break; } - if (base::EqualsASCII(item.stringType, - ui::Clipboard::kMimeTypeURIList)) { + if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeURIList)) { result.url = GURL(item.stringData); result.url_title = item.title; break; } - if (base::EqualsASCII(item.stringType, - ui::Clipboard::kMimeTypeDownloadURL)) { + if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeDownloadURL)) { result.download_metadata = item.stringData; break; } - if (base::EqualsASCII(item.stringType, - ui::Clipboard::kMimeTypeHTML)) { + if (base::EqualsASCII(str_type, ui::Clipboard::kMimeTypeHTML)) { result.html = base::NullableString16(item.stringData, false); result.html_base_url = item.baseURL; break; diff --git a/content/renderer/npapi/webplugin_impl.cc b/content/renderer/npapi/webplugin_impl.cc index b6e4db1..4d28f232 100644 --- a/content/renderer/npapi/webplugin_impl.cc +++ b/content/renderer/npapi/webplugin_impl.cc @@ -208,7 +208,7 @@ void GetResponseInfo(const WebURLResponse& response, WebString content_encoding = response.httpHeaderField(WebString::fromUTF8("Content-Encoding")); if (!content_encoding.isNull() && - !base::EqualsASCII(content_encoding, "identity")) { + !base::EqualsASCII(base::StringPiece16(content_encoding), "identity")) { // Don't send the compressed content length to the plugin, which only // cares about the decoded length. response_info->expected_length = 0; diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index df9e34a..796bd04 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -4229,7 +4229,8 @@ WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation( bool is_form_post = ((info.navigationType == blink::WebNavigationTypeFormSubmitted) || (info.navigationType == blink::WebNavigationTypeFormResubmitted)) && - base::EqualsASCII(info.urlRequest.httpMethod(), "POST"); + base::EqualsASCII(base::StringPiece16(info.urlRequest.httpMethod()), + "POST"); bool browser_handles_request = render_view_->renderer_preferences_ .browser_handles_non_local_top_level_requests @@ -4813,7 +4814,7 @@ void RenderFrameImpl::SendFailedProvisionalLoad( blink::WebLocalFrame* frame) { bool show_repost_interstitial = (error.reason == net::ERR_CACHE_MISS && - base::EqualsASCII(request.httpMethod(), "POST")); + base::EqualsASCII(base::StringPiece16(request.httpMethod()), "POST")); FrameHostMsg_DidFailProvisionalLoadWithError_Params params; params.error_code = error.reason; diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 07ad3f5..f4b1782 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2293,7 +2293,8 @@ bool RenderViewImpl::IsEditableNode(const WebNode& node) const { return true; } - return base::LowerCaseEqualsASCII(element.getAttribute("role"), "textbox"); + return base::LowerCaseEqualsASCII( + base::StringPiece16(element.getAttribute("role")), "textbox"); } return false; diff --git a/content/renderer/savable_resources.cc b/content/renderer/savable_resources.cc index b5fdf8e..1a9612d 100644 --- a/content/renderer/savable_resources.cc +++ b/content/renderer/savable_resources.cc @@ -166,8 +166,10 @@ WebString GetSubResourceLinkFromElement(const WebElement& element) { attribute_name = "cite"; } else if (element.hasHTMLTagName("link")) { // If the link element is not linked to css, ignore it. - if (base::LowerCaseEqualsASCII(element.getAttribute("type"), "text/css") || - base::LowerCaseEqualsASCII(element.getAttribute("rel"), "stylesheet")) { + if (base::LowerCaseEqualsASCII( + base::StringPiece16(element.getAttribute("type")), "text/css") || + base::LowerCaseEqualsASCII( + base::StringPiece16(element.getAttribute("rel")), "stylesheet")) { // TODO(jnd): Add support for extracting links of sub-resources which // are inside style-sheet such as @import, url(), etc. // See bug: http://b/issue?id=1111667. diff --git a/content/test/mock_webclipboard_impl.cc b/content/test/mock_webclipboard_impl.cc index eb9677b..7886f12 100644 --- a/content/test/mock_webclipboard_impl.cc +++ b/content/test/mock_webclipboard_impl.cc @@ -176,15 +176,16 @@ void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { switch (item.storageType) { case WebDragData::Item::StorageTypeString: { ++m_sequenceNumber; - if (base::EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { + base::string16 type(item.stringType); + if (base::EqualsASCII(type, ui::Clipboard::kMimeTypeText)) { m_plainText = item.stringData; continue; } - if (base::EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { + if (base::EqualsASCII(type, ui::Clipboard::kMimeTypeHTML)) { m_htmlText = item.stringData; continue; } - m_customData.insert(std::make_pair(item.stringType, item.stringData)); + m_customData.insert(std::make_pair(type, item.stringData)); continue; } default: diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index 77ea96c..632bc2c 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -237,8 +237,8 @@ static bool HeaderMatches(const HttpRequestHeaders& headers, HttpUtil::ValuesIterator v(header_value.begin(), header_value.end(), ','); while (v.GetNext()) { - if (base::LowerCaseEqualsASCII(v.value_begin(), v.value_end(), - search->value)) + if (base::LowerCaseEqualsASCII( + base::StringPiece(v.value_begin(), v.value_end()), search->value)) return true; } } diff --git a/net/http/http_content_disposition.cc b/net/http/http_content_disposition.cc index 0e830f6..28ea8bd 100644 --- a/net/http/http_content_disposition.cc +++ b/net/http/http_content_disposition.cc @@ -359,9 +359,11 @@ std::string::const_iterator HttpContentDisposition::ConsumeDispositionType( DCHECK(std::find(type_begin, type_end, '=') == type_end); - if (base::LowerCaseEqualsASCII(type_begin, type_end, "inline")) { + if (base::LowerCaseEqualsASCII(base::StringPiece(type_begin, type_end), + "inline")) { type_ = INLINE; - } else if (base::LowerCaseEqualsASCII(type_begin, type_end, "attachment")) { + } else if (base::LowerCaseEqualsASCII(base::StringPiece(type_begin, type_end), + "attachment")) { type_ = ATTACHMENT; } else { parse_result_flags_ |= HAS_UNKNOWN_DISPOSITION_TYPE; @@ -403,15 +405,17 @@ void HttpContentDisposition::Parse(const std::string& header, HttpUtil::NameValuePairsIterator iter(pos, end, ';'); while (iter.GetNext()) { if (filename.empty() && - base::LowerCaseEqualsASCII(iter.name_begin(), iter.name_end(), - "filename")) { + base::LowerCaseEqualsASCII( + base::StringPiece(iter.name_begin(), iter.name_end()), + "filename")) { DecodeFilenameValue(iter.value(), referrer_charset, &filename, &parse_result_flags_); if (!filename.empty()) parse_result_flags_ |= HAS_FILENAME; } else if (ext_filename.empty() && - base::LowerCaseEqualsASCII(iter.name_begin(), iter.name_end(), - "filename*")) { + base::LowerCaseEqualsASCII( + base::StringPiece(iter.name_begin(), iter.name_end()), + "filename*")) { DecodeExtValue(iter.raw_value(), &ext_filename); if (!ext_filename.empty()) parse_result_flags_ |= HAS_EXT_FILENAME; diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index 84f1a22..119ec52 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -95,15 +95,13 @@ const char* const kNonUpdatedHeaderPrefixes[] = { "x-webkit-" }; -bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, - const std::string::const_iterator& name_end) { +bool ShouldUpdateHeader(base::StringPiece name) { for (size_t i = 0; i < arraysize(kNonUpdatedHeaders); ++i) { - if (base::LowerCaseEqualsASCII(name_begin, name_end, kNonUpdatedHeaders[i])) + if (base::LowerCaseEqualsASCII(name, kNonUpdatedHeaders[i])) return false; } for (size_t i = 0; i < arraysize(kNonUpdatedHeaderPrefixes); ++i) { - if (base::StartsWith(base::StringPiece(name_begin, name_end), - kNonUpdatedHeaderPrefixes[i], + if (base::StartsWith(name, kNonUpdatedHeaderPrefixes[i], base::CompareCase::INSENSITIVE_ASCII)) return false; } @@ -248,16 +246,16 @@ void HttpResponseHeaders::Update(const HttpResponseHeaders& new_headers) { while (++k < new_parsed.size() && new_parsed[k].is_continuation()) {} --k; - const std::string::const_iterator& name_begin = new_parsed[i].name_begin; - const std::string::const_iterator& name_end = new_parsed[i].name_end; - if (ShouldUpdateHeader(name_begin, name_end)) { - std::string name(name_begin, name_end); - base::StringToLowerASCII(&name); - updated_headers.insert(name); + base::StringPiece name(new_parsed[i].name_begin, new_parsed[i].name_end); + if (ShouldUpdateHeader(name)) { + std::string name_lower; + name.CopyToString(&name_lower); + base::StringToLowerASCII(&name_lower); + updated_headers.insert(name_lower); // Preserve this header line in the merged result, making sure there is // a null after the value. - new_raw_headers.append(name_begin, new_parsed[k].value_end); + new_raw_headers.append(new_parsed[i].name_begin, new_parsed[k].value_end); new_raw_headers.push_back('\0'); } @@ -631,7 +629,8 @@ HttpVersion HttpResponseHeaders::ParseVersion( // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1). // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1. - if ((line_end - p < 4) || !base::LowerCaseEqualsASCII(p, p + 4, "http")) { + if (!base::StartsWith(base::StringPiece(line_begin, line_end), "http", + base::CompareCase::INSENSITIVE_ASCII)) { DVLOG(1) << "missing status line"; return HttpVersion(); } @@ -759,8 +758,8 @@ bool HttpResponseHeaders::GetCacheControlDirective(const StringPiece& directive, void* iter = NULL; while (EnumerateHeader(&iter, name, &value)) { if (value.size() > directive_size + 1 && - base::LowerCaseEqualsASCII( - value.begin(), value.begin() + directive_size, directive.begin()) && + base::StartsWith(value, directive, + base::CompareCase::INSENSITIVE_ASCII) && value[directive_size] == '=') { int64 seconds; base::StringToInt64( @@ -1304,8 +1303,9 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position, std::string::const_iterator content_range_spec_end = content_range_spec.begin() + space_position; HttpUtil::TrimLWS(&content_range_spec_begin, &content_range_spec_end); - if (!base::LowerCaseEqualsASCII(content_range_spec_begin, - content_range_spec_end, "bytes")) { + if (!base::LowerCaseEqualsASCII( + base::StringPiece(content_range_spec_begin, content_range_spec_end), + "bytes")) { return false; } @@ -1368,8 +1368,9 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position, content_range_spec.end(); HttpUtil::TrimLWS(&instance_length_begin, &instance_length_end); - if (base::LowerCaseEqualsASCII(instance_length_begin, instance_length_end, - "*")) { + if (base::StartsWith( + base::StringPiece(instance_length_begin, instance_length_end), "*", + base::CompareCase::SENSITIVE)) { return false; } else if (!base::StringToInt64(StringPiece(instance_length_begin, instance_length_end), diff --git a/net/http/http_util.cc b/net/http/http_util.cc index 53693f4..9a88dad 100644 --- a/net/http/http_util.cc +++ b/net/http/http_util.cc @@ -118,14 +118,15 @@ void HttpUtil::ParseContentType(const std::string& content_type_str, DCHECK(param_value_begin <= tokenizer.token_end()); TrimLWS(¶m_value_begin, ¶m_value_end); - if (base::LowerCaseEqualsASCII(param_name_begin, param_name_end, - "charset")) { + if (base::LowerCaseEqualsASCII( + base::StringPiece(param_name_begin, param_name_end), "charset")) { // TODO(abarth): Refactor this function to consistently use iterators. charset_val = param_value_begin - begin; charset_end = param_value_end - begin; type_has_charset = true; - } else if (base::LowerCaseEqualsASCII(param_name_begin, param_name_end, - "boundary")) { + } else if (base::LowerCaseEqualsASCII( + base::StringPiece(param_name_begin, param_name_end), + "boundary")) { if (boundary) boundary->assign(param_value_begin, param_value_end); } @@ -162,8 +163,9 @@ void HttpUtil::ParseContentType(const std::string& content_type_str, content_type_str.find_first_of('/') != std::string::npos) { // Common case here is that mime_type is empty bool eq = !mime_type->empty() && - base::LowerCaseEqualsASCII(begin + type_val, begin + type_end, - mime_type->data()); + base::LowerCaseEqualsASCII( + base::StringPiece(begin + type_val, begin + type_end), + mime_type->data()); if (!eq) { mime_type->assign(begin + type_val, begin + type_end); base::StringToLowerASCII(mime_type); @@ -220,7 +222,8 @@ bool HttpUtil::ParseRangeHeader(const std::string& ranges_specifier, TrimLWS(&bytes_unit_begin, &bytes_unit_end); // "bytes" unit identifier is not found. - if (!base::LowerCaseEqualsASCII(bytes_unit_begin, bytes_unit_end, "bytes")) + if (!base::LowerCaseEqualsASCII( + base::StringPiece(bytes_unit_begin, bytes_unit_end), "bytes")) return false; ValuesIterator byte_range_set_iterator(byte_range_set_begin, @@ -386,8 +389,9 @@ std::string HttpUtil::StripHeaders(const std::string& headers, while (it.GetNext()) { bool should_remove = false; for (size_t i = 0; i < headers_to_remove_len; ++i) { - if (base::LowerCaseEqualsASCII(it.name_begin(), it.name_end(), - headers_to_remove[i])) { + if (base::LowerCaseEqualsASCII( + base::StringPiece(it.name_begin(), it.name_end()), + headers_to_remove[i])) { should_remove = true; break; } @@ -422,7 +426,7 @@ bool HttpUtil::IsNonCoalescingHeader(std::string::const_iterator name_begin, "strict-transport-security" }; for (size_t i = 0; i < arraysize(kNonCoalescingHeaders); ++i) { - if (base::LowerCaseEqualsASCII(name_begin, name_end, + if (base::LowerCaseEqualsASCII(base::StringPiece(name_begin, name_end), kNonCoalescingHeaders[i])) return true; } @@ -537,7 +541,8 @@ int HttpUtil::LocateStartOfStatusLine(const char* buf, int buf_len) { if (buf_len >= http_len) { int i_max = std::min(buf_len - http_len, slop); for (int i = 0; i <= i_max; ++i) { - if (base::LowerCaseEqualsASCII(buf + i, buf + i + http_len, "http")) + if (base::LowerCaseEqualsASCII(base::StringPiece(buf + i, http_len), + "http")) return i; } } @@ -753,7 +758,7 @@ bool HttpUtil::HasStrongValidators(HttpVersion version, std::string::const_iterator i = etag_header.begin(); std::string::const_iterator j = etag_header.begin() + slash; TrimLWS(&i, &j); - if (!base::LowerCaseEqualsASCII(i, j, "w")) + if (!base::LowerCaseEqualsASCII(base::StringPiece(i, j), "w")) return true; } @@ -854,7 +859,8 @@ bool HttpUtil::HeadersIterator::AdvanceTo(const char* name) { << "the header name must be in all lower case"; while (GetNext()) { - if (base::LowerCaseEqualsASCII(name_begin_, name_end_, name)) { + if (base::LowerCaseEqualsASCII(base::StringPiece(name_begin_, name_end_), + name)) { return true; } } diff --git a/net/proxy/proxy_server.cc b/net/proxy/proxy_server.cc index c65df31..e451265 100644 --- a/net/proxy/proxy_server.cc +++ b/net/proxy/proxy_server.cc @@ -18,26 +18,24 @@ namespace { // Parses the proxy type from a PAC string, to a ProxyServer::Scheme. // This mapping is case-insensitive. If no type could be matched // returns SCHEME_INVALID. -ProxyServer::Scheme GetSchemeFromPacTypeInternal( - std::string::const_iterator begin, - std::string::const_iterator end) { - if (base::LowerCaseEqualsASCII(begin, end, "proxy")) +ProxyServer::Scheme GetSchemeFromPacTypeInternal(base::StringPiece type) { + if (base::LowerCaseEqualsASCII(type, "proxy")) return ProxyServer::SCHEME_HTTP; - if (base::LowerCaseEqualsASCII(begin, end, "socks")) { + if (base::LowerCaseEqualsASCII(type, "socks")) { // Default to v4 for compatibility. This is because the SOCKS4 vs SOCKS5 // notation didn't originally exist, so if a client returns SOCKS they // really meant SOCKS4. return ProxyServer::SCHEME_SOCKS4; } - if (base::LowerCaseEqualsASCII(begin, end, "socks4")) + if (base::LowerCaseEqualsASCII(type, "socks4")) return ProxyServer::SCHEME_SOCKS4; - if (base::LowerCaseEqualsASCII(begin, end, "socks5")) + if (base::LowerCaseEqualsASCII(type, "socks5")) return ProxyServer::SCHEME_SOCKS5; - if (base::LowerCaseEqualsASCII(begin, end, "direct")) + if (base::LowerCaseEqualsASCII(type, "direct")) return ProxyServer::SCHEME_DIRECT; - if (base::LowerCaseEqualsASCII(begin, end, "https")) + if (base::LowerCaseEqualsASCII(type, "https")) return ProxyServer::SCHEME_HTTPS; - if (base::LowerCaseEqualsASCII(begin, end, "quic")) + if (base::LowerCaseEqualsASCII(type, "quic")) return ProxyServer::SCHEME_QUIC; return ProxyServer::SCHEME_INVALID; @@ -46,21 +44,20 @@ ProxyServer::Scheme GetSchemeFromPacTypeInternal( // Parses the proxy scheme from a URL-like representation, to a // ProxyServer::Scheme. This corresponds with the values used in // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. -ProxyServer::Scheme GetSchemeFromURIInternal(std::string::const_iterator begin, - std::string::const_iterator end) { - if (base::LowerCaseEqualsASCII(begin, end, "http")) +ProxyServer::Scheme GetSchemeFromURIInternal(base::StringPiece type) { + if (base::LowerCaseEqualsASCII(type, "http")) return ProxyServer::SCHEME_HTTP; - if (base::LowerCaseEqualsASCII(begin, end, "socks4")) + if (base::LowerCaseEqualsASCII(type, "socks4")) return ProxyServer::SCHEME_SOCKS4; - if (base::LowerCaseEqualsASCII(begin, end, "socks")) + if (base::LowerCaseEqualsASCII(type, "socks")) return ProxyServer::SCHEME_SOCKS5; - if (base::LowerCaseEqualsASCII(begin, end, "socks5")) + if (base::LowerCaseEqualsASCII(type, "socks5")) return ProxyServer::SCHEME_SOCKS5; - if (base::LowerCaseEqualsASCII(begin, end, "direct")) + if (base::LowerCaseEqualsASCII(type, "direct")) return ProxyServer::SCHEME_DIRECT; - if (base::LowerCaseEqualsASCII(begin, end, "https")) + if (base::LowerCaseEqualsASCII(type, "https")) return ProxyServer::SCHEME_HTTPS; - if (base::LowerCaseEqualsASCII(begin, end, "quic")) + if (base::LowerCaseEqualsASCII(type, "quic")) return ProxyServer::SCHEME_QUIC; return ProxyServer::SCHEME_INVALID; } @@ -108,7 +105,7 @@ ProxyServer ProxyServer::FromURI(std::string::const_iterator begin, (end - colon) >= 3 && *(colon + 1) == '/' && *(colon + 2) == '/') { - scheme = GetSchemeFromURIInternal(begin, colon); + scheme = GetSchemeFromURIInternal(base::StringPiece(begin, colon)); begin = colon + 3; // Skip past the "://" } @@ -161,7 +158,7 @@ ProxyServer ProxyServer::FromPacString(std::string::const_iterator begin, } // Everything to the left of the space is the scheme. - Scheme scheme = GetSchemeFromPacTypeInternal(begin, space); + Scheme scheme = GetSchemeFromPacTypeInternal(base::StringPiece(begin, space)); // And everything to the right of the space is the // <host>[":" <port>]. @@ -169,7 +166,7 @@ ProxyServer ProxyServer::FromPacString(std::string::const_iterator begin, } std::string ProxyServer::ToPacString() const { - switch (scheme_) { + switch (scheme_) { case SCHEME_DIRECT: return "DIRECT"; case SCHEME_HTTP: @@ -210,7 +207,7 @@ int ProxyServer::GetDefaultPortForScheme(Scheme scheme) { // static ProxyServer::Scheme ProxyServer::GetSchemeFromURI(const std::string& scheme) { - return GetSchemeFromURIInternal(scheme.begin(), scheme.end()); + return GetSchemeFromURIInternal(scheme); } // static diff --git a/url/gurl.cc b/url/gurl.cc index 0137de6..2547a95 100644 --- a/url/gurl.cc +++ b/url/gurl.cc @@ -372,9 +372,10 @@ bool GURL::IsStandard() const { bool GURL::SchemeIs(const char* lower_ascii_scheme) const { if (parsed_.scheme.len <= 0) return lower_ascii_scheme == NULL; - return base::LowerCaseEqualsASCII(spec_.data() + parsed_.scheme.begin, - spec_.data() + parsed_.scheme.end(), - lower_ascii_scheme); + return base::LowerCaseEqualsASCII( + base::StringPiece(spec_.data() + parsed_.scheme.begin, + parsed_.scheme.len), + lower_ascii_scheme); } bool GURL::SchemeIsHTTPOrHTTPS() const { @@ -511,10 +512,9 @@ bool GURL::DomainIs(const char* lower_ascii_domain, const char* start_pos = spec_.data() + parsed_.host.begin + host_len - domain_len; - if (!base::LowerCaseEqualsASCII(start_pos, - last_pos + 1, - lower_ascii_domain, - lower_ascii_domain + domain_len)) + if (!base::LowerCaseEqualsASCII( + base::StringPiece(start_pos, last_pos - start_pos + 1), + base::StringPiece(lower_ascii_domain, domain_len))) return false; // Check whether host has right domain start with dot, make sure we got diff --git a/url/url_util.cc b/url/url_util.cc index 28a8931..5a19390 100644 --- a/url/url_util.cc +++ b/url/url_util.cc @@ -38,6 +38,17 @@ std::vector<const char*>* standard_schemes = NULL; // See the LockStandardSchemes declaration in the header. bool standard_schemes_locked = false; +// This template converts a given character type to the corresponding +// StringPiece type. +template<typename CHAR> struct CharToStringPiece { +}; +template<> struct CharToStringPiece<char> { + typedef base::StringPiece Piece; +}; +template<> struct CharToStringPiece<base::char16> { + typedef base::StringPiece16 Piece; +}; + // Ensures that the standard_schemes list is initialized, does nothing if it // already has values. void InitStandardSchemes() { @@ -56,9 +67,10 @@ inline bool DoCompareSchemeComponent(const CHAR* spec, const char* compare_to) { if (!component.is_nonempty()) return compare_to[0] == 0; // When component is empty, match empty scheme. - return base::LowerCaseEqualsASCII(&spec[component.begin], - &spec[component.end()], - compare_to); + return base::LowerCaseEqualsASCII( + typename CharToStringPiece<CHAR>::Piece( + &spec[component.begin], component.len), + compare_to); } // Returns true if the given scheme identified by |scheme| within |spec| is one @@ -70,8 +82,10 @@ bool DoIsStandard(const CHAR* spec, const Component& scheme) { InitStandardSchemes(); for (size_t i = 0; i < standard_schemes->size(); i++) { - if (base::LowerCaseEqualsASCII(&spec[scheme.begin], &spec[scheme.end()], - standard_schemes->at(i))) + if (base::LowerCaseEqualsASCII( + typename CharToStringPiece<CHAR>::Piece( + &spec[scheme.begin], scheme.len), + standard_schemes->at(i))) return true; } return false; |