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

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

Issue 312003002: Port net/tools/balsa to non-Linux platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows compiler warnings Created 6 years, 6 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 #if defined(COMPILER_MSVC)
16 struct StringPieceCaseCompare {
17 static const size_t bucket_size = 4;
18
19 size_t operator()(const base::StringPiece& sp) const {
20 // based on __stl_string_hash in http://www.sgi.com/tech/stl/string
21 size_t hash_val = 0;
22 for (base::StringPiece::const_iterator it = sp.begin();
23 it != sp.end(); ++it) {
24 hash_val = 5 * hash_val + tolower(*it);
25 }
26 return hash_val;
27 }
28
29 bool operator()(const base::StringPiece& sp1,
30 const base::StringPiece& sp2) const {
31 size_t len1 = sp1.length();
32 size_t len2 = sp2.length();
33 bool sp1_shorter = len1 < len2;
34 size_t len = sp1_shorter ? len1 : len2;
35 int rv = _memicmp(sp1.data(), sp2.data(), len);
36 if (rv == 0) {
37 return sp1_shorter;
38 }
39 return rv < 0;
40 }
41 };
42 #else // COMPILER_MSVC
15 struct StringPieceCaseHash { 43 struct StringPieceCaseHash {
16 size_t operator()(const base::StringPiece& sp) const { 44 size_t operator()(const base::StringPiece& sp) const {
17 // based on __stl_string_hash in http://www.sgi.com/tech/stl/string 45 // based on __stl_string_hash in http://www.sgi.com/tech/stl/string
18 size_t hash_val = 0; 46 size_t hash_val = 0;
19 for (base::StringPiece::const_iterator it = sp.begin(); 47 for (base::StringPiece::const_iterator it = sp.begin();
20 it != sp.end(); ++it) { 48 it != sp.end(); ++it) {
21 hash_val = 5 * hash_val + tolower(*it); 49 hash_val = 5 * hash_val + tolower(*it);
22 } 50 }
23 return hash_val; 51 return hash_val;
24 } 52 }
25 }; 53 };
54 #endif // COMPILER_MSVC
26 55
27 struct StringPieceUtils { 56 struct StringPieceUtils {
28 static bool EqualIgnoreCase(const base::StringPiece& piece1, 57 static bool EqualIgnoreCase(const base::StringPiece& piece1,
29 const base::StringPiece& piece2) { 58 const base::StringPiece& piece2) {
30 base::StringPiece::const_iterator p1i = piece1.begin(); 59 base::StringPiece::const_iterator p1i = piece1.begin();
31 base::StringPiece::const_iterator p2i = piece2.begin(); 60 base::StringPiece::const_iterator p2i = piece2.begin();
32 if (piece1.empty() && piece2.empty()) { 61 if (piece1.empty() && piece2.empty()) {
33 return true; 62 return true;
34 } else if (piece1.size() != piece2.size()) { 63 } else if (piece1.size() != piece2.size()) {
35 return false; 64 return false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return StringPieceUtils::EqualIgnoreCase(piece1, piece2); 103 return StringPieceUtils::EqualIgnoreCase(piece1, piece2);
75 } 104 }
76 }; 105 };
77 106
78 107
79 108
80 } // namespace net 109 } // namespace net
81 110
82 #endif // NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_ 111 #endif // NET_TOOLS_BALSA_STRING_PIECE_UTILS_H_
83 112
OLDNEW
« net/tools/balsa/balsa_frame.cc ('K') | « net/tools/balsa/balsa_headers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698