Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/value_semantic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,11 @@ namespace boost { namespace program_options {

void error_with_option_name::replace_token(const string& from, const string& to) const
{
for (;;)
std::size_t pos = 0;
while ((pos = m_message.find(from, pos)) != std::string::npos)
{
std::size_t pos = m_message.find(from.c_str(), 0, from.length());
// not found: all replaced
if (pos == std::string::npos)
return;
m_message.replace(pos, from.length(), to);
pos += to.length();
}
}

Expand Down
8 changes: 7 additions & 1 deletion test/exception_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ void test_unknown_option()
}
}

void test_unknown_option_placeholder()
{
unknown_option err("-%canonical_option%");
BOOST_CHECK_EQUAL(string(err.what()), "unrecognised option '-%canonical_option%'");
}



void test_multiple_values()
Expand Down Expand Up @@ -253,6 +259,7 @@ int main(int /*ac*/, char** /*av*/)
test_ambiguous_long();
test_ambiguous_multiple_long_names();
test_unknown_option();
test_unknown_option_placeholder();
test_multiple_values();
test_multiple_occurrences();
test_multiple_occurrences_with_different_names();
Expand All @@ -261,4 +268,3 @@ int main(int /*ac*/, char** /*av*/)

return 0;
}

Loading