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

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

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

Powered by Google App Engine
This is Rietveld 408576698