diff options
author | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 01:21:09 +0000 |
---|---|---|
committer | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 01:21:09 +0000 |
commit | dbf476de0ef1cdcc11c5f2d689b8755809a857fb (patch) | |
tree | 5a68c5a8fb056c10441752dcd230e96180d1e775 /base | |
parent | e1b01fc18365da2c58cc17981bf28fe71fd06b7e (diff) | |
download | chromium_src-dbf476de0ef1cdcc11c5f2d689b8755809a857fb.zip chromium_src-dbf476de0ef1cdcc11c5f2d689b8755809a857fb.tar.gz chromium_src-dbf476de0ef1cdcc11c5f2d689b8755809a857fb.tar.bz2 |
Port Replace(First)SubstringsAfterOffset to string16.
Review URL: http://codereview.chromium.org/28324
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/string_util.cc | 16 | ||||
-rw-r--r-- | base/string_util.h | 16 | ||||
-rw-r--r-- | base/string_util_unittest.cc | 80 |
3 files changed, 57 insertions, 55 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index 64c0cdc..e7f6c33 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -843,10 +843,10 @@ void DoReplaceSubstringsAfterOffset(StringType* str, } } -void ReplaceFirstSubstringAfterOffset(std::wstring* str, - std::wstring::size_type start_offset, - const std::wstring& find_this, - const std::wstring& replace_with) { +void ReplaceFirstSubstringAfterOffset(string16* str, + string16::size_type start_offset, + const string16& find_this, + const string16& replace_with) { DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with, false); // replace first instance } @@ -859,10 +859,10 @@ void ReplaceFirstSubstringAfterOffset(std::string* str, false); // replace first instance } -void ReplaceSubstringsAfterOffset(std::wstring* str, - std::wstring::size_type start_offset, - const std::wstring& find_this, - const std::wstring& replace_with) { +void ReplaceSubstringsAfterOffset(string16* str, + string16::size_type start_offset, + const string16& find_this, + const string16& replace_with) { DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with, true); // replace all instances } diff --git a/base/string_util.h b/base/string_util.h index 4e04cd8..26c42e5 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -359,10 +359,10 @@ std::wstring FormatNumber(int64 number); // Starting at |start_offset| (usually 0), replace the first instance of // |find_this| with |replace_with|. -void ReplaceFirstSubstringAfterOffset(std::wstring* str, - std::wstring::size_type start_offset, - const std::wstring& find_this, - const std::wstring& replace_with); +void ReplaceFirstSubstringAfterOffset(string16* str, + string16::size_type start_offset, + const string16& find_this, + const string16& replace_with); void ReplaceFirstSubstringAfterOffset(std::string* str, std::string::size_type start_offset, const std::string& find_this, @@ -374,10 +374,10 @@ void ReplaceFirstSubstringAfterOffset(std::string* str, // This does entire substrings; use std::replace in <algorithm> for single // characters, for example: // std::replace(str.begin(), str.end(), 'a', 'b'); -void ReplaceSubstringsAfterOffset(std::wstring* str, - std::wstring::size_type start_offset, - const std::wstring& find_this, - const std::wstring& replace_with); +void ReplaceSubstringsAfterOffset(string16* str, + string16::size_type start_offset, + const string16& find_this, + const string16& replace_with); void ReplaceSubstringsAfterOffset(std::string* str, std::string::size_type start_offset, const std::string& find_this, diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 6fc6f7f..0ceb18f 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -673,60 +673,62 @@ TEST(StringUtilTest, FormatBytes) { TEST(StringUtilTest, ReplaceSubstringsAfterOffset) { static const struct { - const wchar_t* str; - std::wstring::size_type start_offset; - const wchar_t* find_this; - const wchar_t* replace_with; - const wchar_t* expected; + const char* str; + string16::size_type start_offset; + const char* find_this; + const char* replace_with; + const char* expected; } cases[] = { - {L"aaa", 0, L"a", L"b", L"bbb"}, - {L"abb", 0, L"ab", L"a", L"ab"}, - {L"Removing some substrings inging", 0, L"ing", L"", L"Remov some substrs "}, - {L"Not found", 0, L"x", L"0", L"Not found"}, - {L"Not found again", 5, L"x", L"0", L"Not found again"}, - {L" Making it much longer ", 0, L" ", L"Four score and seven years ago", - L"Four score and seven years agoMakingFour score and seven years agoit" - L"Four score and seven years agomuchFour score and seven years agolonger" - L"Four score and seven years ago"}, - {L"Invalid offset", 9999, L"t", L"foobar", L"Invalid offset"}, - {L"Replace me only me once", 9, L"me ", L"", L"Replace me only once"}, - {L"abababab", 2, L"ab", L"c", L"abccc"}, + {"aaa", 0, "a", "b", "bbb"}, + {"abb", 0, "ab", "a", "ab"}, + {"Removing some substrings inging", 0, "ing", "", "Remov some substrs "}, + {"Not found", 0, "x", "0", "Not found"}, + {"Not found again", 5, "x", "0", "Not found again"}, + {" Making it much longer ", 0, " ", "Four score and seven years ago", + "Four score and seven years agoMakingFour score and seven years agoit" + "Four score and seven years agomuchFour score and seven years agolonger" + "Four score and seven years ago"}, + {"Invalid offset", 9999, "t", "foobar", "Invalid offset"}, + {"Replace me only me once", 9, "me ", "", "Replace me only once"}, + {"abababab", 2, "ab", "c", "abccc"}, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { - std::wstring str(cases[i].str); + string16 str = ASCIIToUTF16(cases[i].str); ReplaceSubstringsAfterOffset(&str, cases[i].start_offset, - cases[i].find_this, cases[i].replace_with); - EXPECT_EQ(cases[i].expected, str); + ASCIIToUTF16(cases[i].find_this), + ASCIIToUTF16(cases[i].replace_with)); + EXPECT_EQ(ASCIIToUTF16(cases[i].expected), str); } } TEST(StringUtilTest, ReplaceFirstSubstringAfterOffset) { static const struct { - const wchar_t* str; - std::wstring::size_type start_offset; - const wchar_t* find_this; - const wchar_t* replace_with; - const wchar_t* expected; + const char* str; + string16::size_type start_offset; + const char* find_this; + const char* replace_with; + const char* expected; } cases[] = { - {L"aaa", 0, L"a", L"b", L"baa"}, - {L"abb", 0, L"ab", L"a", L"ab"}, - {L"Removing some substrings inging", 0, L"ing", L"", - L"Remov some substrings inging"}, - {L"Not found", 0, L"x", L"0", L"Not found"}, - {L"Not found again", 5, L"x", L"0", L"Not found again"}, - {L" Making it much longer ", 0, L" ", L"Four score and seven years ago", - L"Four score and seven years agoMaking it much longer "}, - {L"Invalid offset", 9999, L"t", L"foobar", L"Invalid offset"}, - {L"Replace me only me once", 4, L"me ", L"", L"Replace only me once"}, - {L"abababab", 2, L"ab", L"c", L"abcabab"}, + {"aaa", 0, "a", "b", "baa"}, + {"abb", 0, "ab", "a", "ab"}, + {"Removing some substrings inging", 0, "ing", "", + "Remov some substrings inging"}, + {"Not found", 0, "x", "0", "Not found"}, + {"Not found again", 5, "x", "0", "Not found again"}, + {" Making it much longer ", 0, " ", "Four score and seven years ago", + "Four score and seven years agoMaking it much longer "}, + {"Invalid offset", 9999, "t", "foobar", "Invalid offset"}, + {"Replace me only me once", 4, "me ", "", "Replace only me once"}, + {"abababab", 2, "ab", "c", "abcabab"}, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { - std::wstring str(cases[i].str); + string16 str = ASCIIToUTF16(cases[i].str); ReplaceFirstSubstringAfterOffset(&str, cases[i].start_offset, - cases[i].find_this, cases[i].replace_with); - EXPECT_EQ(cases[i].expected, str); + ASCIIToUTF16(cases[i].find_this), + ASCIIToUTF16(cases[i].replace_with)); + EXPECT_EQ(ASCIIToUTF16(cases[i].expected), str); } } |