diff libinterp/corefcn/utils.cc @ 20617:ba2b07c13913

use new string_value method to handle value extraction errors * __dispatch__.cc, balance.cc, colloc.cc, conv2.cc, data.cc, debug.cc, graphics.cc, input.cc, matrix_type.cc, oct-hist.cc, schur.cc, spparms.cc, symtab.cc, sysdep.cc, toplev.cc, utils.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Fri, 09 Oct 2015 10:06:39 -0400
parents 0650b8431037
children
line wrap: on
line diff
--- a/libinterp/corefcn/utils.cc	Thu Oct 08 19:00:51 2015 -0400
+++ b/libinterp/corefcn/utils.cc	Fri Oct 09 10:06:39 2015 -0400
@@ -393,32 +393,27 @@
 
   if (nargin == 2 || nargin == 3)
     {
-      if (args(0).is_string ())
-        {
-          std::string path = args(0).string_value ();
+      std::string path = args(0).string_value ("file_in_path: PATH must be a string");
+
+      string_vector names = args(1).all_strings ();
 
-          string_vector names = args(1).all_strings ();
-
-          if (! error_state && names.numel () > 0)
+      if (! error_state && names.numel () > 0)
+        {
+          if (nargin == 2)
+            retval = search_path_for_file (path, names);
+          else if (nargin == 3)
             {
-              if (nargin == 2)
-                retval = search_path_for_file (path, names);
-              else if (nargin == 3)
-                {
-                  std::string opt = args(2).string_value ();
+              std::string opt = args(2).string_value ();
 
-                  if (! error_state && opt == "all")
-                    retval = Cell (make_absolute
-                                   (search_path_for_all_files (path, names)));
-                  else
-                    error ("file_in_path: invalid option");
-                }
+              if (! error_state && opt == "all")
+                retval = Cell (make_absolute
+                               (search_path_for_all_files (path, names)));
+              else
+                error ("file_in_path: invalid option");
             }
-          else
-            error ("file_in_path: all arguments must be strings");
         }
       else
-        error ("file_in_path: PATH must be a string");
+        error ("file_in_path: all arguments must be strings");
     }
   else
     print_usage ();
@@ -761,10 +756,9 @@
 
   if (nargin == 1)
     {
-      if (args(0).is_string ())
-        retval = do_string_escapes (args(0).string_value ());
-      else
-        error ("do_string_escapes: STRING argument must be of type string");
+      std::string str = args(0).string_value ("do_string_escapes: STRING argument must be of type string");
+
+      retval = do_string_escapes (str);
     }
   else
     print_usage ();
@@ -905,10 +899,9 @@
 
   if (nargin == 1)
     {
-      if (args(0).is_string ())
-        retval = undo_string_escapes (args(0).string_value ());
-      else
-        error ("undo_string_escapes: S argument must be a string");
+      std::string str = args(0).string_value ("undo_string_escapes: S argument must be a string");
+
+      retval = undo_string_escapes (str);
     }
   else
     print_usage ();
@@ -1002,12 +995,9 @@
 
   if (args.length () == 1)
     {
-      std::string nm = args(0).string_value ();
+      std::string nm = args(0).string_value ("make_absolute_filename: FILE argument must be a file name");
 
-      if (! error_state)
-        retval = octave_env::make_absolute (nm);
-      else
-        error ("make_absolute_filename: FILE argument must be a file name");
+      retval = octave_env::make_absolute (nm);
     }
   else
     print_usage ();
@@ -1047,17 +1037,12 @@
 
   if (nargin == 1 || nargin == 2)
     {
-      dir = args(0).string_value ();
+      dir = args(0).string_value ("dir_in_loadpath: DIR must be a directory name");
 
-      if (! error_state)
-        {
-          if (nargin == 1)
-            retval = load_path::find_dir (dir);
-          else if (nargin == 2)
-            retval = Cell (load_path::find_matching_dirs (dir));
-        }
-      else
-        error ("dir_in_loadpath: DIR must be a directory name");
+      if (nargin == 1)
+        retval = load_path::find_dir (dir);
+      else if (nargin == 2)
+        retval = Cell (load_path::find_matching_dirs (dir));
     }
   else
     print_usage ();