Commit 0709f8b5 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[Trac901] Allow multiple replacements

parent 40e06e65
......@@ -27,7 +27,10 @@ replacePlaceholder(string* message, const string& arg,
string mark("%" + lexical_cast<string>(placeholder));
size_t pos(message->find(mark));
if (pos != string::npos) {
message->replace(pos, mark.size(), arg);
do {
message->replace(pos, mark.size(), arg);
pos = message->find(mark, pos + arg.size());
} while (pos != string::npos);
} else {
// We're missing the placeholder, so add some complain
message->append(" @@Missing placeholder " + mark + " for '" + arg +
......
......@@ -109,4 +109,25 @@ TEST_F(FormatterTest, missingPlace) {
"@@Missing placeholder %1 for 'missing'@@", outputs[0].second);
}
// Can replace multiple placeholders
TEST_F(FormatterTest, multiPlaceholder) {
Formatter("TEST", s("The %1 is the %1"), 1, *this).
arg("first rule of tautology club");
ASSERT_LE(1, outputs.size());
EXPECT_EQ(1, outputs.size());
EXPECT_STREQ("TEST", outputs[0].first);
EXPECT_EQ("The first rule of tautology club is "
"the first rule of tautology club", outputs[0].second);
}
// Test we can cope with replacement containing the placeholder
TEST_F(FormatterTest, noRecurse) {
// If we recurse, this will probably eat all the memory and crash
Formatter("TEST", s("%1"), 1, *this).arg("%1 %1");
ASSERT_LE(1, outputs.size());
EXPECT_EQ(1, outputs.size());
EXPECT_STREQ("TEST", outputs[0].first);
EXPECT_EQ("%1 %1", outputs[0].second);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment