Mercurial > hg > octave-nkf
diff src/graphics.cc @ 9584:0fcbfddaa87f
allow abbreviated graphics property names to match, with optional warning
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 28 Aug 2009 05:30:29 -0400 |
parents | bdcfb756d721 |
children | 06b8b51dca48 |
line wrap: on
line diff
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -61,7 +61,11 @@ error ("set: invalid value for %s property", pname.c_str ()); } -static void +// Check to see that PNAME matches just one of PNAMES uniquely. +// Return the full name of the match, or an empty caseless_str object +// if there is no match, or the match is ambiguous. + +static caseless_str validate_property_name (const std::string& who, const std::set<std::string>& pnames, const caseless_str& pname) @@ -73,7 +77,15 @@ p != pnames.end (); p++) { if (pname.compare (*p, len)) - matches.insert (*p); + { + if (len == p->length ()) + { + // Exact match. + return pname; + } + + matches.insert (*p); + } } size_t num_matches = matches.size (); @@ -95,13 +107,20 @@ error ("%s: ambiguous property name %s; possible matches:\n\n%s", who.c_str (), pname.c_str (), match_list.c_str ()); } - else if (num_matches == 1 && ! pname.compare (*(matches.begin ()))) + else if (num_matches == 1) { + // Exact match was handled above. + std::string possible_match = *(matches.begin ()); - error ("%s: instead of %s, did you mean %s?", - who.c_str (), pname.c_str (), possible_match.c_str ()); + warning_with_id ("Octave:abbreviated-property-match", + "%s: allowing %s to match %s", who.c_str (), + pname.c_str (), possible_match.c_str ()); + + return possible_match; } + + return caseless_str (); } static Matrix