comparison 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
comparison
equal deleted inserted replaced
9583:8dc1531e2149 9584:0fcbfddaa87f
59 gripe_set_invalid (const std::string& pname) 59 gripe_set_invalid (const std::string& pname)
60 { 60 {
61 error ("set: invalid value for %s property", pname.c_str ()); 61 error ("set: invalid value for %s property", pname.c_str ());
62 } 62 }
63 63
64 static void 64 // Check to see that PNAME matches just one of PNAMES uniquely.
65 // Return the full name of the match, or an empty caseless_str object
66 // if there is no match, or the match is ambiguous.
67
68 static caseless_str
65 validate_property_name (const std::string& who, 69 validate_property_name (const std::string& who,
66 const std::set<std::string>& pnames, 70 const std::set<std::string>& pnames,
67 const caseless_str& pname) 71 const caseless_str& pname)
68 { 72 {
69 size_t len = pname.length (); 73 size_t len = pname.length ();
71 75
72 for (std::set<std::string>::const_iterator p = pnames.begin (); 76 for (std::set<std::string>::const_iterator p = pnames.begin ();
73 p != pnames.end (); p++) 77 p != pnames.end (); p++)
74 { 78 {
75 if (pname.compare (*p, len)) 79 if (pname.compare (*p, len))
76 matches.insert (*p); 80 {
81 if (len == p->length ())
82 {
83 // Exact match.
84 return pname;
85 }
86
87 matches.insert (*p);
88 }
77 } 89 }
78 90
79 size_t num_matches = matches.size (); 91 size_t num_matches = matches.size ();
80 92
81 if (num_matches == 0) 93 if (num_matches == 0)
93 std::string match_list = os.str (); 105 std::string match_list = os.str ();
94 106
95 error ("%s: ambiguous property name %s; possible matches:\n\n%s", 107 error ("%s: ambiguous property name %s; possible matches:\n\n%s",
96 who.c_str (), pname.c_str (), match_list.c_str ()); 108 who.c_str (), pname.c_str (), match_list.c_str ());
97 } 109 }
98 else if (num_matches == 1 && ! pname.compare (*(matches.begin ()))) 110 else if (num_matches == 1)
99 { 111 {
112 // Exact match was handled above.
113
100 std::string possible_match = *(matches.begin ()); 114 std::string possible_match = *(matches.begin ());
101 115
102 error ("%s: instead of %s, did you mean %s?", 116 warning_with_id ("Octave:abbreviated-property-match",
103 who.c_str (), pname.c_str (), possible_match.c_str ()); 117 "%s: allowing %s to match %s", who.c_str (),
104 } 118 pname.c_str (), possible_match.c_str ());
119
120 return possible_match;
121 }
122
123 return caseless_str ();
105 } 124 }
106 125
107 static Matrix 126 static Matrix
108 jet_colormap (void) 127 jet_colormap (void)
109 { 128 {