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

Side by Side Diff: base/strings/string_util.cc

Issue 1224553010: Replace base::str[n]casecmp with helper functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 unified diff | Download patch
« no previous file with comments | « base/strings/string_util.h ('k') | base/strings/string_util_posix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <math.h> 9 #include <math.h>
10 #include <stdarg.h> 10 #include <stdarg.h>
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // Portable, keep scanning the rest of the format string. 133 // Portable, keep scanning the rest of the format string.
134 in_specification = false; 134 in_specification = false;
135 } 135 }
136 } 136 }
137 } 137 }
138 } 138 }
139 139
140 return true; 140 return true;
141 } 141 }
142 142
143 template<class StringType>
144 int CompareCaseInsensitiveASCIIT(BasicStringPiece<StringType> a,
145 BasicStringPiece<StringType> b) {
146 // Find the first characters that aren't equal and compare them. If the end
147 // of one of the strings is found before a nonequal character, the lengths
148 // of the strings are compared.
149 size_t i = 0;
150 while (i < a.length() && i < b.length()) {
151 typename StringType::value_type lower_a = ToLowerASCII(a[i]);
152 typename StringType::value_type lower_b = ToLowerASCII(b[i]);
153 if (lower_a < lower_b)
154 return -1;
155 if (lower_a > lower_b)
156 return 1;
157 i++;
158 }
159
160 // End of one string hit before finding a different character. Expect the
161 // common case to be "strings equal" at this point so check that first.
162 if (a.length() == b.length())
163 return 0;
164
165 if (a.length() < b.length())
166 return -1;
167 return 1;
168 }
169
170 int CompareCaseInsensitiveASCII(base::StringPiece a, base::StringPiece b) {
171 return CompareCaseInsensitiveASCIIT<std::string>(a, b);
172 }
173
174 int CompareCaseInsensitiveASCII(base::StringPiece16 a, base::StringPiece16 b) {
175 return CompareCaseInsensitiveASCIIT<base::string16>(a, b);
176 }
177
178 bool EqualsCaseInsensitiveASCII(base::StringPiece a, base::StringPiece b) {
179 if (a.length() != b.length())
180 return false;
181 return CompareCaseInsensitiveASCIIT<std::string>(a, b) == 0;
182 }
183
184 bool EqualsCaseInsensitiveASCII(base::StringPiece16 a, base::StringPiece16 b) {
185 if (a.length() != b.length())
186 return false;
187 return CompareCaseInsensitiveASCIIT<base::string16>(a, b) == 0;
188 }
189
143 const std::string& EmptyString() { 190 const std::string& EmptyString() {
144 return EmptyStrings::GetInstance()->s; 191 return EmptyStrings::GetInstance()->s;
145 } 192 }
146 193
147 const string16& EmptyString16() { 194 const string16& EmptyString16() {
148 return EmptyStrings::GetInstance()->s16; 195 return EmptyStrings::GetInstance()->s16;
149 } 196 }
150 197
151 template<typename STR> 198 template<typename STR>
152 bool ReplaceCharsT(const STR& input, 199 bool ReplaceCharsT(const STR& input,
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 } 1020 }
974 1021
975 } // namespace 1022 } // namespace
976 1023
977 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { 1024 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
978 return lcpyT<char>(dst, src, dst_size); 1025 return lcpyT<char>(dst, src, dst_size);
979 } 1026 }
980 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 1027 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
981 return lcpyT<wchar_t>(dst, src, dst_size); 1028 return lcpyT<wchar_t>(dst, src, dst_size);
982 } 1029 }
OLDNEW
« no previous file with comments | « base/strings/string_util.h ('k') | base/strings/string_util_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698