OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_STRING_UTIL_H_ | 7 #ifndef BASE_STRING_UTIL_H_ |
8 #define BASE_STRING_UTIL_H_ | 8 #define BASE_STRING_UTIL_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <stdarg.h> // va_list | 11 #include <stdarg.h> // va_list |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/string_piece.h" // For implicit conversions. | 19 #include "base/string_piece.h" // For implicit conversions. |
20 | 20 |
21 // TODO(brettw) remove this dependency. Previously StringPrintf lived in this | 21 // TODO(brettw) remove this dependency. Previously StringPrintf lived in this |
22 // file. We need to convert the callers over to using stringprintf.h instead | 22 // file. We need to convert the callers over to using stringprintf.h instead |
23 // and then remove this. | 23 // and then remove this. |
24 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
25 | 25 |
| 26 #ifdef RLZ_WIN_LIB_RLZ_LIB_H_ |
| 27 // TODO(tfarina): Fix the rlz library to include this instead and remove |
| 28 // this include. |
| 29 #include "base/string_split.h" |
| 30 #endif // RLZ_WIN_LIB_RLZ_LIB_H_ |
| 31 |
26 // Safe standard library wrappers for all platforms. | 32 // Safe standard library wrappers for all platforms. |
27 | 33 |
28 namespace base { | 34 namespace base { |
29 | 35 |
30 // C standard-library functions like "strncasecmp" and "snprintf" that aren't | 36 // C standard-library functions like "strncasecmp" and "snprintf" that aren't |
31 // cross-platform are provided as "base::strncasecmp", and their prototypes | 37 // cross-platform are provided as "base::strncasecmp", and their prototypes |
32 // are listed below. These functions are then implemented as inline calls | 38 // are listed below. These functions are then implemented as inline calls |
33 // to the platform-specific equivalents in the platform-specific headers. | 39 // to the platform-specific equivalents in the platform-specific headers. |
34 | 40 |
35 // Compares the two strings s1 and s2 without regard to case using | 41 // Compares the two strings s1 and s2 without regard to case using |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 } | 503 } |
498 }; | 504 }; |
499 | 505 |
500 template<typename Char> struct CaseInsensitiveCompareASCII { | 506 template<typename Char> struct CaseInsensitiveCompareASCII { |
501 public: | 507 public: |
502 bool operator()(Char x, Char y) const { | 508 bool operator()(Char x, Char y) const { |
503 return ToLowerASCII(x) == ToLowerASCII(y); | 509 return ToLowerASCII(x) == ToLowerASCII(y); |
504 } | 510 } |
505 }; | 511 }; |
506 | 512 |
507 // TODO(timsteele): Move these split string functions into their own API on | |
508 // string_split.cc/.h files. | |
509 //----------------------------------------------------------------------------- | |
510 | |
511 // Splits |str| into a vector of strings delimited by |s|. Append the results | |
512 // into |r| as they appear. If several instances of |s| are contiguous, or if | |
513 // |str| begins with or ends with |s|, then an empty string is inserted. | |
514 // | |
515 // Every substring is trimmed of any leading or trailing white space. | |
516 void SplitString(const std::wstring& str, | |
517 wchar_t s, | |
518 std::vector<std::wstring>* r); | |
519 void SplitString(const string16& str, | |
520 char16 s, | |
521 std::vector<string16>* r); | |
522 void SplitString(const std::string& str, | |
523 char s, | |
524 std::vector<std::string>* r); | |
525 | |
526 // Splits a string into its fields delimited by any of the characters in | 513 // Splits a string into its fields delimited by any of the characters in |
527 // |delimiters|. Each field is added to the |tokens| vector. Returns the | 514 // |delimiters|. Each field is added to the |tokens| vector. Returns the |
528 // number of tokens found. | 515 // number of tokens found. |
529 size_t Tokenize(const std::wstring& str, | 516 size_t Tokenize(const std::wstring& str, |
530 const std::wstring& delimiters, | 517 const std::wstring& delimiters, |
531 std::vector<std::wstring>* tokens); | 518 std::vector<std::wstring>* tokens); |
532 size_t Tokenize(const string16& str, | 519 size_t Tokenize(const string16& str, |
533 const string16& delimiters, | 520 const string16& delimiters, |
534 std::vector<string16>* tokens); | 521 std::vector<string16>* tokens); |
535 size_t Tokenize(const std::string& str, | 522 size_t Tokenize(const std::string& str, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 #elif defined(WCHAR_T_IS_UTF32) | 601 #elif defined(WCHAR_T_IS_UTF32) |
615 typedef uint32 Unsigned; | 602 typedef uint32 Unsigned; |
616 #endif | 603 #endif |
617 }; | 604 }; |
618 template<> | 605 template<> |
619 struct ToUnsigned<short> { | 606 struct ToUnsigned<short> { |
620 typedef unsigned short Unsigned; | 607 typedef unsigned short Unsigned; |
621 }; | 608 }; |
622 | 609 |
623 #endif // BASE_STRING_UTIL_H_ | 610 #endif // BASE_STRING_UTIL_H_ |
OLD | NEW |