| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 template <class char_type> | 432 template <class char_type> |
| 433 inline char_type* WriteInto( | 433 inline char_type* WriteInto( |
| 434 std::basic_string<char_type, std::char_traits<char_type>, | 434 std::basic_string<char_type, std::char_traits<char_type>, |
| 435 std::allocator<char_type> >* str, | 435 std::allocator<char_type> >* str, |
| 436 size_t length_including_null) { | 436 size_t length_including_null) { |
| 437 str->reserve(length_including_null); | 437 str->reserve(length_including_null); |
| 438 str->resize(length_including_null - 1); | 438 str->resize(length_including_null - 1); |
| 439 return &((*str)[0]); | 439 return &((*str)[0]); |
| 440 } | 440 } |
| 441 | 441 |
| 442 inline char16* WriteInto(string16* str, size_t length_including_null) { |
| 443 str->reserve(length_including_null); |
| 444 str->resize(length_including_null - 1); |
| 445 return &((*str)[0]); |
| 446 } |
| 447 |
| 442 //----------------------------------------------------------------------------- | 448 //----------------------------------------------------------------------------- |
| 443 | 449 |
| 444 // Function objects to aid in comparing/searching strings. | 450 // Function objects to aid in comparing/searching strings. |
| 445 | 451 |
| 446 template<typename Char> struct CaseInsensitiveCompare { | 452 template<typename Char> struct CaseInsensitiveCompare { |
| 447 public: | 453 public: |
| 448 bool operator()(Char x, Char y) const { | 454 bool operator()(Char x, Char y) const { |
| 449 return tolower(x) == tolower(y); | 455 return tolower(x) == tolower(y); |
| 450 } | 456 } |
| 451 }; | 457 }; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 // Returns true if the string passed in matches the pattern. The pattern | 532 // Returns true if the string passed in matches the pattern. The pattern |
| 527 // string can contain wildcards like * and ? | 533 // string can contain wildcards like * and ? |
| 528 // TODO(iyengar) This function may not work correctly for CJK strings as | 534 // TODO(iyengar) This function may not work correctly for CJK strings as |
| 529 // it does individual character matches. | 535 // it does individual character matches. |
| 530 // The backslash character (\) is an escape character for * and ? | 536 // The backslash character (\) is an escape character for * and ? |
| 531 bool MatchPattern(const std::wstring& string, const std::wstring& pattern); | 537 bool MatchPattern(const std::wstring& string, const std::wstring& pattern); |
| 532 bool MatchPattern(const std::string& string, const std::string& pattern); | 538 bool MatchPattern(const std::string& string, const std::string& pattern); |
| 533 | 539 |
| 534 #endif // BASE_STRING_UTIL_H_ | 540 #endif // BASE_STRING_UTIL_H_ |
| 535 | 541 |
| OLD | NEW |