Index: base/strings/string_util.cc |
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc |
index e23317e90f3e34fb30167b7ce21b0474f6d6e3d5..e64b95f7635dc1ddeec4d8f0d97b4d92c0d9b2e3 100644 |
--- a/base/strings/string_util.cc |
+++ b/base/strings/string_util.cc |
@@ -113,7 +113,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; |
@@ -132,41 +132,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 |
@@ -190,15 +190,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, |
@@ -240,13 +242,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. |
@@ -435,17 +438,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, |
@@ -491,7 +492,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) { |
@@ -499,7 +500,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(); |
@@ -510,7 +511,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, |
@@ -518,7 +519,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, |
@@ -526,7 +527,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, |
@@ -534,7 +535,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, |
@@ -548,9 +549,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; |