Mercurial > hg > octave-nkf
changeset 15435:13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
* libinterp/interpfcn/utils.cc (isvarname): Redraft function to
return false when input is not a string rather than printing
an error.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 21 Sep 2012 22:44:10 -0700 |
parents | e1f59fd57756 |
children | 32fd31378052 |
files | libinterp/interpfcn/utils.cc |
diffstat | 1 files changed, 9 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/interpfcn/utils.cc +++ b/libinterp/interpfcn/utils.cc @@ -99,19 +99,17 @@ @seealso{iskeyword, exist, who}\n\ @end deftypefn") { - octave_value retval; + octave_value retval = false; - int argc = args.length () + 1; - - string_vector argv = args.make_argv ("isvarname"); + int nargin = args.length (); - if (error_state) - return retval; - - if (argc == 2) - retval = valid_identifier (argv[1]) && ! is_keyword (argv[1]); - else + if (nargin != 1) print_usage (); + else if (args(0).is_string ()) + { + std::string varname = args(0).string_value (); + retval = valid_identifier (varname) && ! is_keyword (varname); + } return retval; } @@ -122,6 +120,7 @@ %!assert (isvarname ("_1"), true) %!assert (isvarname ("1foo"), false) %!assert (isvarname (""), false) +%!assert (isvarname (12), false) %!error isvarname () %!error isvarname ("foo", "bar");