diff options
-rw-r--r-- | base/string_util.h | 5 | ||||
-rw-r--r-- | base/string_util_unittest.cc | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/base/string_util.h b/base/string_util.h index ae8b93c..ca028e1 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -579,8 +579,9 @@ void SplitStringAlongWhitespace(const std::string& str, std::vector<std::string>* result); // Replace $1-$2-$3..$9 in the format string with |a|-|b|-|c|..|i| respectively. -// Additionally, $$ is replaced by $. The offsets parameter here can -// be NULL. This only allows you to use up to nine replacements. +// Additionally, any number of consecutive '$' characters is replaced by that +// number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be +// NULL. This only allows you to use up to nine replacements. string16 ReplaceStringPlaceholders(const string16& format_string, const std::vector<string16>& subst, std::vector<size_t>* offsets); diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 7bdacea..b317d83 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -1022,6 +1022,15 @@ TEST(StringUtilTest, StdStringReplaceStringPlaceholders) { EXPECT_EQ(formatted, "9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii"); } +TEST(StringUtilTest, ReplaceStringPlaceholdersConsecutiveDollarSigns) { + std::vector<std::string> subst; + subst.push_back("a"); + subst.push_back("b"); + subst.push_back("c"); + EXPECT_EQ(ReplaceStringPlaceholders("$$1 $$$2 $$$$3", subst, NULL), + "$1 $$2 $$$3"); +} + TEST(StringUtilTest, SplitStringAlongWhitespace) { struct TestData { const std::wstring input; |