| 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 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // - 'F', which is not identified by Windows wprintf documentation. | 109 // - 'F', which is not identified by Windows wprintf documentation. |
| 110 // - 'D', 'O', and 'U', which are deprecated and not available on all systems. | 110 // - 'D', 'O', and 'U', which are deprecated and not available on all systems. |
| 111 // Use %ld, %lo, and %lu instead. | 111 // Use %ld, %lo, and %lu instead. |
| 112 // | 112 // |
| 113 // Note that there is no portable conversion specifier for char data when | 113 // Note that there is no portable conversion specifier for char data when |
| 114 // working with wprintf. | 114 // working with wprintf. |
| 115 // | 115 // |
| 116 // This function is intended to be called from base::vswprintf. | 116 // This function is intended to be called from base::vswprintf. |
| 117 bool IsWprintfFormatPortable(const wchar_t* format); | 117 bool IsWprintfFormatPortable(const wchar_t* format); |
| 118 | 118 |
| 119 // Function objects to aid in comparing/searching strings. |
| 120 |
| 121 template<typename Char> struct CaseInsensitiveCompare { |
| 122 public: |
| 123 bool operator()(Char x, Char y) const { |
| 124 // TODO(darin): Do we really want to do locale sensitive comparisons here? |
| 125 // See http://crbug.com/24917 |
| 126 return tolower(x) == tolower(y); |
| 127 } |
| 128 }; |
| 129 |
| 130 template<typename Char> struct CaseInsensitiveCompareASCII { |
| 131 public: |
| 132 bool operator()(Char x, Char y) const { |
| 133 return ToLowerASCII(x) == ToLowerASCII(y); |
| 134 } |
| 135 }; |
| 136 |
| 119 } // namespace base | 137 } // namespace base |
| 120 | 138 |
| 121 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
| 122 #include "base/string_util_win.h" | 140 #include "base/string_util_win.h" |
| 123 #elif defined(OS_POSIX) | 141 #elif defined(OS_POSIX) |
| 124 #include "base/string_util_posix.h" | 142 #include "base/string_util_posix.h" |
| 125 #else | 143 #else |
| 126 #error Define string operations appropriately for your platform | 144 #error Define string operations appropriately for your platform |
| 127 #endif | 145 #endif |
| 128 | 146 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 template <class string_type> | 479 template <class string_type> |
| 462 inline typename string_type::value_type* WriteInto(string_type* str, | 480 inline typename string_type::value_type* WriteInto(string_type* str, |
| 463 size_t length_with_null) { | 481 size_t length_with_null) { |
| 464 str->reserve(length_with_null); | 482 str->reserve(length_with_null); |
| 465 str->resize(length_with_null - 1); | 483 str->resize(length_with_null - 1); |
| 466 return &((*str)[0]); | 484 return &((*str)[0]); |
| 467 } | 485 } |
| 468 | 486 |
| 469 //----------------------------------------------------------------------------- | 487 //----------------------------------------------------------------------------- |
| 470 | 488 |
| 471 // Function objects to aid in comparing/searching strings. | |
| 472 | |
| 473 template<typename Char> struct CaseInsensitiveCompare { | |
| 474 public: | |
| 475 bool operator()(Char x, Char y) const { | |
| 476 // TODO(darin): Do we really want to do locale sensitive comparisons here? | |
| 477 // See http://crbug.com/24917 | |
| 478 return tolower(x) == tolower(y); | |
| 479 } | |
| 480 }; | |
| 481 | |
| 482 template<typename Char> struct CaseInsensitiveCompareASCII { | |
| 483 public: | |
| 484 bool operator()(Char x, Char y) const { | |
| 485 return ToLowerASCII(x) == ToLowerASCII(y); | |
| 486 } | |
| 487 }; | |
| 488 | 489 |
| 489 // Splits a string into its fields delimited by any of the characters in | 490 // Splits a string into its fields delimited by any of the characters in |
| 490 // |delimiters|. Each field is added to the |tokens| vector. Returns the | 491 // |delimiters|. Each field is added to the |tokens| vector. Returns the |
| 491 // number of tokens found. | 492 // number of tokens found. |
| 492 size_t Tokenize(const std::wstring& str, | 493 size_t Tokenize(const std::wstring& str, |
| 493 const std::wstring& delimiters, | 494 const std::wstring& delimiters, |
| 494 std::vector<std::wstring>* tokens); | 495 std::vector<std::wstring>* tokens); |
| 495 size_t Tokenize(const string16& str, | 496 size_t Tokenize(const string16& str, |
| 496 const string16& delimiters, | 497 const string16& delimiters, |
| 497 std::vector<string16>* tokens); | 498 std::vector<string16>* tokens); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 #elif defined(WCHAR_T_IS_UTF32) | 579 #elif defined(WCHAR_T_IS_UTF32) |
| 579 typedef uint32 Unsigned; | 580 typedef uint32 Unsigned; |
| 580 #endif | 581 #endif |
| 581 }; | 582 }; |
| 582 template<> | 583 template<> |
| 583 struct ToUnsigned<short> { | 584 struct ToUnsigned<short> { |
| 584 typedef unsigned short Unsigned; | 585 typedef unsigned short Unsigned; |
| 585 }; | 586 }; |
| 586 | 587 |
| 587 #endif // BASE_STRING_UTIL_H_ | 588 #endif // BASE_STRING_UTIL_H_ |
| OLD | NEW |