| 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 template <class string_type> | 479 template <class string_type> |
| 480 inline typename string_type::value_type* WriteInto(string_type* str, | 480 inline typename string_type::value_type* WriteInto(string_type* str, |
| 481 size_t length_with_null) { | 481 size_t length_with_null) { |
| 482 str->reserve(length_with_null); | 482 str->reserve(length_with_null); |
| 483 str->resize(length_with_null - 1); | 483 str->resize(length_with_null - 1); |
| 484 return &((*str)[0]); | 484 return &((*str)[0]); |
| 485 } | 485 } |
| 486 | 486 |
| 487 //----------------------------------------------------------------------------- | 487 //----------------------------------------------------------------------------- |
| 488 | 488 |
| 489 | |
| 490 // Splits a string into its fields delimited by any of the characters in | 489 // Splits a string into its fields delimited by any of the characters in |
| 491 // |delimiters|. Each field is added to the |tokens| vector. Returns the | 490 // |delimiters|. Each field is added to the |tokens| vector. Returns the |
| 492 // number of tokens found. | 491 // number of tokens found. |
| 493 size_t Tokenize(const std::wstring& str, | 492 size_t Tokenize(const std::wstring& str, |
| 494 const std::wstring& delimiters, | 493 const std::wstring& delimiters, |
| 495 std::vector<std::wstring>* tokens); | 494 std::vector<std::wstring>* tokens); |
| 496 size_t Tokenize(const string16& str, | 495 size_t Tokenize(const string16& str, |
| 497 const string16& delimiters, | 496 const string16& delimiters, |
| 498 std::vector<string16>* tokens); | 497 std::vector<string16>* tokens); |
| 499 size_t Tokenize(const std::string& str, | 498 size_t Tokenize(const std::string& str, |
| 500 const std::string& delimiters, | 499 const std::string& delimiters, |
| 501 std::vector<std::string>* tokens); | 500 std::vector<std::string>* tokens); |
| 502 size_t Tokenize(const base::StringPiece& str, | 501 size_t Tokenize(const base::StringPiece& str, |
| 503 const base::StringPiece& delimiters, | 502 const base::StringPiece& delimiters, |
| 504 std::vector<base::StringPiece>* tokens); | 503 std::vector<base::StringPiece>* tokens); |
| 505 | 504 |
| 506 // Does the opposite of SplitString(). | 505 // Does the opposite of SplitString(). |
| 507 string16 JoinString(const std::vector<string16>& parts, char16 s); | 506 string16 JoinString(const std::vector<string16>& parts, char16 s); |
| 508 std::string JoinString(const std::vector<std::string>& parts, char s); | 507 std::string JoinString(const std::vector<std::string>& parts, char s); |
| 509 | 508 |
| 510 // WARNING: this uses whitespace as defined by the HTML5 spec. If you need | |
| 511 // a function similar to this but want to trim all types of whitespace, then | |
| 512 // factor this out into a function that takes a string containing the characters | |
| 513 // that are treated as whitespace. | |
| 514 // | |
| 515 // Splits the string along whitespace (where whitespace is the five space | |
| 516 // characters defined by HTML 5). Each contiguous block of non-whitespace | |
| 517 // characters is added to result. | |
| 518 void SplitStringAlongWhitespace(const std::wstring& str, | |
| 519 std::vector<std::wstring>* result); | |
| 520 void SplitStringAlongWhitespace(const string16& str, | |
| 521 std::vector<string16>* result); | |
| 522 void SplitStringAlongWhitespace(const std::string& str, | |
| 523 std::vector<std::string>* result); | |
| 524 | |
| 525 // Replace $1-$2-$3..$9 in the format string with |a|-|b|-|c|..|i| respectively. | 509 // Replace $1-$2-$3..$9 in the format string with |a|-|b|-|c|..|i| respectively. |
| 526 // Additionally, any number of consecutive '$' characters is replaced by that | 510 // Additionally, any number of consecutive '$' characters is replaced by that |
| 527 // number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be | 511 // number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be |
| 528 // NULL. This only allows you to use up to nine replacements. | 512 // NULL. This only allows you to use up to nine replacements. |
| 529 string16 ReplaceStringPlaceholders(const string16& format_string, | 513 string16 ReplaceStringPlaceholders(const string16& format_string, |
| 530 const std::vector<string16>& subst, | 514 const std::vector<string16>& subst, |
| 531 std::vector<size_t>* offsets); | 515 std::vector<size_t>* offsets); |
| 532 | 516 |
| 533 std::string ReplaceStringPlaceholders(const base::StringPiece& format_string, | 517 std::string ReplaceStringPlaceholders(const base::StringPiece& format_string, |
| 534 const std::vector<std::string>& subst, | 518 const std::vector<std::string>& subst, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 #elif defined(WCHAR_T_IS_UTF32) | 563 #elif defined(WCHAR_T_IS_UTF32) |
| 580 typedef uint32 Unsigned; | 564 typedef uint32 Unsigned; |
| 581 #endif | 565 #endif |
| 582 }; | 566 }; |
| 583 template<> | 567 template<> |
| 584 struct ToUnsigned<short> { | 568 struct ToUnsigned<short> { |
| 585 typedef unsigned short Unsigned; | 569 typedef unsigned short Unsigned; |
| 586 }; | 570 }; |
| 587 | 571 |
| 588 #endif // BASE_STRING_UTIL_H_ | 572 #endif // BASE_STRING_UTIL_H_ |
| OLD | NEW |