Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2974)

Unified Diff: net/tools/balsa/string_piece_utils.h

Issue 1215933004: New new versions of Starts/EndsWith and SplitString in net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@starts_with
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/tools/balsa/string_piece_utils.h
diff --git a/net/tools/balsa/string_piece_utils.h b/net/tools/balsa/string_piece_utils.h
index cab48fbd182fea05aa79b2bae7a562fcd93c112b..7d8a1aaaee28733cd8afe70374822a91c4e3b9f8 100644
--- a/net/tools/balsa/string_piece_utils.h
+++ b/net/tools/balsa/string_piece_utils.h
@@ -5,9 +5,8 @@
#ifndef NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_
#define NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_
-#include <ctype.h>
-
#include "base/strings/string_piece.h"
+#include "base/strings/string_util.h"
namespace net {
@@ -20,7 +19,7 @@ struct StringPieceCaseCompare {
size_t hash_val = 0;
for (base::StringPiece::const_iterator it = sp.begin();
it != sp.end(); ++it) {
- hash_val = 5 * hash_val + tolower(*it);
+ hash_val = 5 * hash_val + base::ToLowerASCII(*it);
}
return hash_val;
}
@@ -31,7 +30,21 @@ struct StringPieceCaseCompare {
size_t len2 = sp2.length();
bool sp1_shorter = len1 < len2;
size_t len = sp1_shorter ? len1 : len2;
- int rv = _memicmp(sp1.data(), sp2.data(), len);
+
+ int rv = 0;
+ for (size_t i = 0; i < len; i++) {
+ char sp1_lower = base::ToLowerASCII(sp1[i]);
+ char sp2_lower = base::ToLowerASCII(sp2[i]);
+ if (sp1_lower < sp2_lower) {
+ rv = -1;
+ break;
+ }
+ if (sp1_lower > sp2_lower) {
+ rv = 1;
+ break;
+ }
+ }
+
if (rv == 0) {
return sp1_shorter;
}
@@ -45,7 +58,7 @@ struct StringPieceCaseHash {
size_t hash_val = 0;
for (base::StringPiece::const_iterator it = sp.begin();
it != sp.end(); ++it) {
- hash_val = 5 * hash_val + tolower(*it);
+ hash_val = 5 * hash_val + base::ToLowerASCII(*it);
}
return hash_val;
}
@@ -53,6 +66,7 @@ struct StringPieceCaseHash {
#endif // COMPILER_MSVC
struct StringPieceUtils {
+ // ASCII case-insensitive equality.
static bool EqualIgnoreCase(const base::StringPiece& piece1,
const base::StringPiece& piece2) {
base::StringPiece::const_iterator p1i = piece1.begin();
@@ -63,39 +77,15 @@ struct StringPieceUtils {
return false;
}
while (p1i != piece1.end() && p2i != piece2.end()) {
- if (tolower(*p1i) != tolower(*p2i))
+ if (base::ToLowerASCII(*p1i) != base::ToLowerASCII(*p2i))
return false;
++p1i;
++p2i;
}
return true;
}
-
- static void RemoveWhitespaceContext(base::StringPiece* piece1) {
- base::StringPiece::const_iterator c = piece1->begin();
- base::StringPiece::const_iterator e = piece1->end();
- while (c != e && isspace(*c)) {
- ++c;
- }
- if (c == e) {
- *piece1 = base::StringPiece(c, e-c);
- return;
- }
- --e;
- while (c != e &&isspace(*e)) {
- --e;
- }
- ++e;
- *piece1 = base::StringPiece(c, e-c);
- }
-
- static bool StartsWithIgnoreCase(const base::StringPiece& text,
- const base::StringPiece& starts_with) {
- if (text.size() < starts_with.size())
- return false;
- return EqualIgnoreCase(text.substr(0, starts_with.size()), starts_with);
- }
};
+
struct StringPieceCaseEqual {
bool operator()(const base::StringPiece& piece1,
const base::StringPiece& piece2) const {
@@ -103,8 +93,6 @@ struct StringPieceCaseEqual {
}
};
-
-
} // namespace net
#endif // NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_
« no previous file with comments | « net/tools/balsa/balsa_headers_token_utils.cc ('k') | net/tools/disk_cache_memory_test/disk_cache_memory_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698