Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Unified Diff: base/string_util_unittest.cc

Issue 18603: Add a replace_all param to ReplaceSubstringsAfterOffset and update call sites. (Closed)
Patch Set: Add ReplaceFirstSubstringAfterPos() Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/string_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util_unittest.cc
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 9a7f40f507d615ca5ad4001462fdd08e183d9f74..11c727d01bf9b73b7e9b132219189ee28c0fab5e 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -675,6 +675,35 @@ TEST(StringUtilTest, ReplaceSubstringsAfterOffset) {
}
}
+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;
+ } 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"},
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
+ std::wstring str(cases[i].str);
+ ReplaceFirstSubstringAfterOffset(&str, cases[i].start_offset,
+ cases[i].find_this, cases[i].replace_with);
+ EXPECT_EQ(cases[i].expected, str);
+ }
+}
+
namespace {
template <typename INT>
« no previous file with comments | « base/string_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698