From cd647f785a70b3e651981a9fb30107915636be32 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Wed, 11 Jul 2007 19:07:44 +0000 Subject: [PATCH] Fix #898. Two approximate matches followed by an exact match no longer cause an ambiguity to be reported. [SVN r38187] --- src/options_description.cpp | 30 +++++++++++------------------- test/options_description_test.cpp | 2 +- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/options_description.cpp b/src/options_description.cpp index 7d5a941..546b78e 100644 --- a/src/options_description.cpp +++ b/src/options_description.cpp @@ -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 found; + vector 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 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 diff --git a/test/options_description_test.cpp b/test/options_description_test.cpp index d5ec259..885e539 100644 --- a/test/options_description_test.cpp +++ b/test/options_description_test.cpp @@ -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");