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

Side by Side Diff: net/tools/balsa/string_piece_utils.h

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_ 5 #ifndef NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_
6 #define NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_ 6 #define NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_
7 7
8 #include <ctype.h> 8 #include <ctype.h>
9 9
10 #include "base/port.h" 10 #include "base/port.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 struct StringPieceCaseHash { 15 struct StringPieceCaseHash {
16 size_t operator()(const base::StringPiece& sp) const { 16 size_t operator()(const base::StringPiece& sp) const {
17 // based on __stl_string_hash in http://www.sgi.com/tech/stl/string 17 // based on __stl_string_hash in http://www.sgi.com/tech/stl/string
18 size_t hash_val = 0; 18 size_t hash_val = 0;
19 for (base::StringPiece::const_iterator it = sp.begin(); 19 for (base::StringPiece::const_iterator it = sp.begin(); it != sp.end();
20 it != sp.end(); ++it) { 20 ++it) {
21 hash_val = 5 * hash_val + tolower(*it); 21 hash_val = 5 * hash_val + tolower(*it);
22 } 22 }
23 return hash_val; 23 return hash_val;
24 } 24 }
25 }; 25 };
26 26
27 struct StringPieceUtils { 27 struct StringPieceUtils {
28 static bool EqualIgnoreCase(const base::StringPiece& piece1, 28 static bool EqualIgnoreCase(const base::StringPiece& piece1,
29 const base::StringPiece& piece2) { 29 const base::StringPiece& piece2) {
30 base::StringPiece::const_iterator p1i = piece1.begin(); 30 base::StringPiece::const_iterator p1i = piece1.begin();
(...skipping 12 matching lines...) Expand all
43 return true; 43 return true;
44 } 44 }
45 45
46 static void RemoveWhitespaceContext(base::StringPiece* piece1) { 46 static void RemoveWhitespaceContext(base::StringPiece* piece1) {
47 base::StringPiece::const_iterator c = piece1->begin(); 47 base::StringPiece::const_iterator c = piece1->begin();
48 base::StringPiece::const_iterator e = piece1->end(); 48 base::StringPiece::const_iterator e = piece1->end();
49 while (c != e && isspace(*c)) { 49 while (c != e && isspace(*c)) {
50 ++c; 50 ++c;
51 } 51 }
52 if (c == e) { 52 if (c == e) {
53 *piece1 = base::StringPiece(c, e-c); 53 *piece1 = base::StringPiece(c, e - c);
54 return; 54 return;
55 } 55 }
56 --e; 56 --e;
57 while (c != e &&isspace(*e)) { 57 while (c != e && isspace(*e)) {
58 --e; 58 --e;
59 } 59 }
60 ++e; 60 ++e;
61 *piece1 = base::StringPiece(c, e-c); 61 *piece1 = base::StringPiece(c, e - c);
62 } 62 }
63 63
64 static bool StartsWithIgnoreCase(const base::StringPiece& text, 64 static bool StartsWithIgnoreCase(const base::StringPiece& text,
65 const base::StringPiece& starts_with) { 65 const base::StringPiece& starts_with) {
66 if (text.size() < starts_with.size()) 66 if (text.size() < starts_with.size())
67 return false; 67 return false;
68 return EqualIgnoreCase(text.substr(0, starts_with.size()), starts_with); 68 return EqualIgnoreCase(text.substr(0, starts_with.size()), starts_with);
69 } 69 }
70 }; 70 };
71 struct StringPieceCaseEqual { 71 struct StringPieceCaseEqual {
72 bool operator()(const base::StringPiece& piece1, 72 bool operator()(const base::StringPiece& piece1,
73 const base::StringPiece& piece2) const { 73 const base::StringPiece& piece2) const {
74 return StringPieceUtils::EqualIgnoreCase(piece1, piece2); 74 return StringPieceUtils::EqualIgnoreCase(piece1, piece2);
75 } 75 }
76 }; 76 };
77 77
78
79
80 } // namespace net 78 } // namespace net
81 79
82 #endif // NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_ 80 #endif // NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_
83
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698