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

Side by Side Diff: trunk/src/base/strings/string_util.h

Issue 474483002: Revert 289312 "Move StringToUpperASCII and LowerCaseEqualsASCII ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 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
« no previous file with comments | « trunk/src/base/i18n/rtl.cc ('k') | trunk/src/base/strings/string_util.cc » ('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 // This file defines utility functions for working with strings. 5 // This file defines utility functions for working with strings.
6 6
7 #ifndef BASE_STRINGS_STRING_UTIL_H_ 7 #ifndef BASE_STRINGS_STRING_UTIL_H_
8 #define BASE_STRINGS_STRING_UTIL_H_ 8 #define BASE_STRINGS_STRING_UTIL_H_
9 9
10 #include <ctype.h> 10 #include <ctype.h>
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 *i = ToLowerASCII(*i); 256 *i = ToLowerASCII(*i);
257 } 257 }
258 258
259 template <class str> inline str StringToLowerASCII(const str& s) { 259 template <class str> inline str StringToLowerASCII(const str& s) {
260 // for std::string and std::wstring 260 // for std::string and std::wstring
261 str output(s); 261 str output(s);
262 StringToLowerASCII(&output); 262 StringToLowerASCII(&output);
263 return output; 263 return output;
264 } 264 }
265 265
266 } // namespace base
267
268 #if defined(OS_WIN)
269 #include "base/strings/string_util_win.h"
270 #elif defined(OS_POSIX)
271 #include "base/strings/string_util_posix.h"
272 #else
273 #error Define string operations appropriately for your platform
274 #endif
275
266 // Converts the elements of the given string. This version uses a pointer to 276 // Converts the elements of the given string. This version uses a pointer to
267 // clearly differentiate it from the non-pointer variant. 277 // clearly differentiate it from the non-pointer variant.
268 template <class str> inline void StringToUpperASCII(str* s) { 278 template <class str> inline void StringToUpperASCII(str* s) {
269 for (typename str::iterator i = s->begin(); i != s->end(); ++i) 279 for (typename str::iterator i = s->begin(); i != s->end(); ++i)
270 *i = base::ToUpperASCII(*i); 280 *i = base::ToUpperASCII(*i);
271 } 281 }
272 282
273 template <class str> inline str StringToUpperASCII(const str& s) { 283 template <class str> inline str StringToUpperASCII(const str& s) {
274 // for std::string and std::wstring 284 // for std::string and std::wstring
275 str output(s); 285 str output(s);
276 StringToUpperASCII(&output); 286 StringToUpperASCII(&output);
277 return output; 287 return output;
278 } 288 }
279 289
280 // Compare the lower-case form of the given string against the given 290 // Compare the lower-case form of the given string against the given ASCII
281 // previously-lower-cased ASCII string. This is useful for doing checking if an 291 // string. This is useful for doing checking if an input string matches some
282 // input string matches some token, and it is optimized to avoid intermediate 292 // token, and it is optimized to avoid intermediate string copies. This API is
283 // string copies. 293 // borrowed from the equivalent APIs in Mozilla.
284 BASE_EXPORT bool LowerCaseEqualsASCII(StringPiece str, 294 BASE_EXPORT bool LowerCaseEqualsASCII(const std::string& a, const char* b);
285 const char* lower_cased_cmp); 295 BASE_EXPORT bool LowerCaseEqualsASCII(const base::string16& a, const char* b);
286 BASE_EXPORT bool LowerCaseEqualsASCII(StringPiece16 str,
287 const char* lower_cased_cmp);
288 296
289 // Same thing, but with string iterators instead. 297 // Same thing, but with string iterators instead.
290 // TODO(brettw) remove these variants in preference for the StringPiece
291 // versions above.
292 BASE_EXPORT bool LowerCaseEqualsASCII(std::string::const_iterator a_begin, 298 BASE_EXPORT bool LowerCaseEqualsASCII(std::string::const_iterator a_begin,
293 std::string::const_iterator a_end, 299 std::string::const_iterator a_end,
294 const char* b); 300 const char* b);
295 BASE_EXPORT bool LowerCaseEqualsASCII(base::string16::const_iterator a_begin, 301 BASE_EXPORT bool LowerCaseEqualsASCII(base::string16::const_iterator a_begin,
296 base::string16::const_iterator a_end, 302 base::string16::const_iterator a_end,
297 const char* b); 303 const char* b);
298 BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin, 304 BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin,
299 const char* a_end, 305 const char* a_end,
300 const char* b); 306 const char* b);
301 BASE_EXPORT bool LowerCaseEqualsASCII(const base::char16* a_begin, 307 BASE_EXPORT bool LowerCaseEqualsASCII(const base::char16* a_begin,
302 const base::char16* a_end, 308 const base::char16* a_end,
303 const char* b); 309 const char* b);
304 310
305 } // namespace base
306
307 #if defined(OS_WIN)
308 #include "base/strings/string_util_win.h"
309 #elif defined(OS_POSIX)
310 #include "base/strings/string_util_posix.h"
311 #else
312 #error Define string operations appropriately for your platform
313 #endif
314
315 // Performs a case-sensitive string compare. The behavior is undefined if both 311 // Performs a case-sensitive string compare. The behavior is undefined if both
316 // strings are not ASCII. 312 // strings are not ASCII.
317 BASE_EXPORT bool EqualsASCII(const base::string16& a, const base::StringPiece& b ); 313 BASE_EXPORT bool EqualsASCII(const base::string16& a, const base::StringPiece& b );
318 314
319 // Returns true if str starts with search, or false otherwise. 315 // Returns true if str starts with search, or false otherwise.
320 BASE_EXPORT bool StartsWithASCII(const std::string& str, 316 BASE_EXPORT bool StartsWithASCII(const std::string& str,
321 const std::string& search, 317 const std::string& search,
322 bool case_sensitive); 318 bool case_sensitive);
323 BASE_EXPORT bool StartsWith(const base::string16& str, 319 BASE_EXPORT bool StartsWith(const base::string16& str,
324 const base::string16& search, 320 const base::string16& search,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 #elif defined(WCHAR_T_IS_UTF32) 514 #elif defined(WCHAR_T_IS_UTF32)
519 typedef uint32 Unsigned; 515 typedef uint32 Unsigned;
520 #endif 516 #endif
521 }; 517 };
522 template<> 518 template<>
523 struct ToUnsigned<short> { 519 struct ToUnsigned<short> {
524 typedef unsigned short Unsigned; 520 typedef unsigned short Unsigned;
525 }; 521 };
526 522
527 #endif // BASE_STRINGS_STRING_UTIL_H_ 523 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « trunk/src/base/i18n/rtl.cc ('k') | trunk/src/base/strings/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698