Fix #898. Two approximate matches followed by an exact match

no longer cause an ambiguity to be reported.


[SVN r38187]
This commit is contained in:
Vladimir Prus
2007-07-11 19:07:44 +00:00
parent 4223d3231d
commit cd647f785a
2 changed files with 12 additions and 20 deletions

View File

@@ -258,7 +258,8 @@ namespace boost { namespace program_options {
options_description::find_nothrow(const std::string& name,
bool approx) const
{
int found = -1;
shared_ptr<option_description> found;
vector<string> approximate_matches;
// We use linear search because matching specified option
// name with the declared option name need to take care about
// case sensitivity and trailing '*' and so we can't use simple map.
@@ -284,25 +285,16 @@ namespace boost { namespace program_options {
return m_options[i].get();
}
if (found != -1)
{
vector<string> alts;
// FIXME: the use of 'key' here might not
// be the best approach.
alts.push_back(m_options[found]->key(name));
alts.push_back(m_options[i]->key(name));
boost::throw_exception(ambiguous_option(name, alts));
}
else
{
found = i;
}
}
if (found != -1) {
return m_options[found].get();
} else {
return 0;
found = m_options[i];
// FIXME: the use of 'key' here might not
// be the best approach.
approximate_matches.push_back(m_options[i]->key(name));
}
if (approximate_matches.size() > 1)
boost::throw_exception(
ambiguous_option(name, approximate_matches));
else
return found.get();
}
BOOST_PROGRAM_OPTIONS_DECL

View File

@@ -44,9 +44,9 @@ void test_approximation()
("foo", new untyped_value())
("fee", new untyped_value())
("baz", new untyped_value())
("all", new untyped_value())
("all-chroots", new untyped_value())
("all-sessions", new untyped_value())
("all", new untyped_value())
;
BOOST_CHECK_EQUAL(desc.find("fo", true).long_name(), "foo");