summaryrefslogtreecommitdiffstats
path: root/url/url_util.cc
diff options
context:
space:
mode:
authorbrettw <brettw@chromium.org>2015-07-23 14:56:35 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-23 21:57:37 +0000
commit85111674b30562ab0ba3a0f7d3b09761fdc09e00 (patch)
treea8ac1e3a51e6322156244b9b86516ccaccb2507d /url/url_util.cc
parent666686c757e8c17d47ec2036e718eb85ca26fb1c (diff)
downloadchromium_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}
Diffstat (limited to 'url/url_util.cc')
-rw-r--r--url/url_util.cc24
1 files changed, 19 insertions, 5 deletions
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;