| Index: base/strings/string_util.cc
|
| diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc
|
| index 0adb98959fc0ea335e4bcb2bd408709455441627..0e048f55b8615a4f8b2f95f32ae8bd538af49706 100644
|
| --- a/base/strings/string_util.cc
|
| +++ b/base/strings/string_util.cc
|
| @@ -118,7 +118,7 @@ const string16& EmptyString16() {
|
|
|
| template<typename STR>
|
| bool ReplaceCharsT(const STR& input,
|
| - const typename STR::value_type replace_chars[],
|
| + const STR& replace_chars,
|
| const STR& replace_with,
|
| STR* output) {
|
| bool removed = false;
|
| @@ -137,41 +137,41 @@ bool ReplaceCharsT(const STR& input,
|
| }
|
|
|
| bool ReplaceChars(const string16& input,
|
| - const char16 replace_chars[],
|
| + const base::StringPiece16& replace_chars,
|
| const string16& replace_with,
|
| string16* output) {
|
| - return ReplaceCharsT(input, replace_chars, replace_with, output);
|
| + return ReplaceCharsT(input, replace_chars.as_string(), replace_with, output);
|
| }
|
|
|
| bool ReplaceChars(const std::string& input,
|
| - const char replace_chars[],
|
| + const base::StringPiece& replace_chars,
|
| const std::string& replace_with,
|
| std::string* output) {
|
| - return ReplaceCharsT(input, replace_chars, replace_with, output);
|
| + return ReplaceCharsT(input, replace_chars.as_string(), replace_with, output);
|
| }
|
|
|
| bool RemoveChars(const string16& input,
|
| - const char16 remove_chars[],
|
| + const base::StringPiece16& remove_chars,
|
| string16* output) {
|
| - return ReplaceChars(input, remove_chars, string16(), output);
|
| + return ReplaceChars(input, remove_chars.as_string(), string16(), output);
|
| }
|
|
|
| bool RemoveChars(const std::string& input,
|
| - const char remove_chars[],
|
| + const base::StringPiece& remove_chars,
|
| std::string* output) {
|
| - return ReplaceChars(input, remove_chars, std::string(), output);
|
| + return ReplaceChars(input, remove_chars.as_string(), std::string(), output);
|
| }
|
|
|
| template<typename STR>
|
| TrimPositions TrimStringT(const STR& input,
|
| - const typename STR::value_type trim_chars[],
|
| + const STR& trim_chars,
|
| TrimPositions positions,
|
| STR* output) {
|
| // Find the edges of leading/trailing whitespace as desired.
|
| - const typename STR::size_type last_char = input.length() - 1;
|
| - const typename STR::size_type first_good_char = (positions & TRIM_LEADING) ?
|
| + const size_t last_char = input.length() - 1;
|
| + const size_t first_good_char = (positions & TRIM_LEADING) ?
|
| input.find_first_not_of(trim_chars) : 0;
|
| - const typename STR::size_type last_good_char = (positions & TRIM_TRAILING) ?
|
| + const size_t last_good_char = (positions & TRIM_TRAILING) ?
|
| input.find_last_not_of(trim_chars) : last_char;
|
|
|
| // When the string was all whitespace, report that we stripped off whitespace
|
| @@ -195,15 +195,17 @@ TrimPositions TrimStringT(const STR& input,
|
| }
|
|
|
| bool TrimString(const string16& input,
|
| - const char16 trim_chars[],
|
| + const base::StringPiece16& trim_chars,
|
| string16* output) {
|
| - return TrimStringT(input, trim_chars, TRIM_ALL, output) != TRIM_NONE;
|
| + return TrimStringT(input, trim_chars.as_string(), TRIM_ALL, output) !=
|
| + TRIM_NONE;
|
| }
|
|
|
| bool TrimString(const std::string& input,
|
| - const char trim_chars[],
|
| + const base::StringPiece& trim_chars,
|
| std::string* output) {
|
| - return TrimStringT(input, trim_chars, TRIM_ALL, output) != TRIM_NONE;
|
| + return TrimStringT(input, trim_chars.as_string(), TRIM_ALL, output) !=
|
| + TRIM_NONE;
|
| }
|
|
|
| void TruncateUTF8ToByteSize(const std::string& input,
|
| @@ -245,13 +247,14 @@ void TruncateUTF8ToByteSize(const std::string& input,
|
| TrimPositions TrimWhitespace(const string16& input,
|
| TrimPositions positions,
|
| string16* output) {
|
| - return TrimStringT(input, kWhitespaceUTF16, positions, output);
|
| + return TrimStringT(input, base::string16(kWhitespaceUTF16), positions,
|
| + output);
|
| }
|
|
|
| TrimPositions TrimWhitespaceASCII(const std::string& input,
|
| TrimPositions positions,
|
| std::string* output) {
|
| - return TrimStringT(input, kWhitespaceASCII, positions, output);
|
| + return TrimStringT(input, std::string(kWhitespaceASCII), positions, output);
|
| }
|
|
|
| // This function is only for backward-compatibility.
|
| @@ -440,17 +443,15 @@ bool StartsWith(const string16& str, const string16& search,
|
|
|
| template <typename STR>
|
| bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) {
|
| - typename STR::size_type str_length = str.length();
|
| - typename STR::size_type search_length = search.length();
|
| + size_t str_length = str.length();
|
| + size_t search_length = search.length();
|
| if (search_length > str_length)
|
| return false;
|
| - if (case_sensitive) {
|
| + if (case_sensitive)
|
| return str.compare(str_length - search_length, search_length, search) == 0;
|
| - } else {
|
| - return std::equal(search.begin(), search.end(),
|
| - str.begin() + (str_length - search_length),
|
| - base::CaseInsensitiveCompare<typename STR::value_type>());
|
| - }
|
| + return std::equal(search.begin(), search.end(),
|
| + str.begin() + (str_length - search_length),
|
| + base::CaseInsensitiveCompare<typename STR::value_type>());
|
| }
|
|
|
| bool EndsWith(const std::string& str, const std::string& search,
|
| @@ -496,7 +497,7 @@ string16 FormatBytesUnlocalized(int64 bytes) {
|
|
|
| template<class StringType>
|
| void DoReplaceSubstringsAfterOffset(StringType* str,
|
| - typename StringType::size_type start_offset,
|
| + size_t start_offset,
|
| const StringType& find_this,
|
| const StringType& replace_with,
|
| bool replace_all) {
|
| @@ -504,7 +505,7 @@ void DoReplaceSubstringsAfterOffset(StringType* str,
|
| return;
|
|
|
| DCHECK(!find_this.empty());
|
| - for (typename StringType::size_type offs(str->find(find_this, start_offset));
|
| + for (size_t offs(str->find(find_this, start_offset));
|
| offs != StringType::npos; offs = str->find(find_this, offs)) {
|
| str->replace(offs, find_this.length(), replace_with);
|
| offs += replace_with.length();
|
| @@ -515,7 +516,7 @@ void DoReplaceSubstringsAfterOffset(StringType* str,
|
| }
|
|
|
| void ReplaceFirstSubstringAfterOffset(string16* str,
|
| - string16::size_type start_offset,
|
| + size_t start_offset,
|
| const string16& find_this,
|
| const string16& replace_with) {
|
| DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
|
| @@ -523,7 +524,7 @@ void ReplaceFirstSubstringAfterOffset(string16* str,
|
| }
|
|
|
| void ReplaceFirstSubstringAfterOffset(std::string* str,
|
| - std::string::size_type start_offset,
|
| + size_t start_offset,
|
| const std::string& find_this,
|
| const std::string& replace_with) {
|
| DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
|
| @@ -531,7 +532,7 @@ void ReplaceFirstSubstringAfterOffset(std::string* str,
|
| }
|
|
|
| void ReplaceSubstringsAfterOffset(string16* str,
|
| - string16::size_type start_offset,
|
| + size_t start_offset,
|
| const string16& find_this,
|
| const string16& replace_with) {
|
| DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
|
| @@ -539,7 +540,7 @@ void ReplaceSubstringsAfterOffset(string16* str,
|
| }
|
|
|
| void ReplaceSubstringsAfterOffset(std::string* str,
|
| - std::string::size_type start_offset,
|
| + size_t start_offset,
|
| const std::string& find_this,
|
| const std::string& replace_with) {
|
| DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
|
| @@ -553,9 +554,9 @@ static size_t TokenizeT(const STR& str,
|
| std::vector<STR>* tokens) {
|
| tokens->clear();
|
|
|
| - typename STR::size_type start = str.find_first_not_of(delimiters);
|
| + size_t start = str.find_first_not_of(delimiters);
|
| while (start != STR::npos) {
|
| - typename STR::size_type end = str.find_first_of(delimiters, start + 1);
|
| + size_t end = str.find_first_of(delimiters, start + 1);
|
| if (end == STR::npos) {
|
| tokens->push_back(str.substr(start));
|
| break;
|
|
|