comparison 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
comparison
equal deleted inserted replaced
20616:fd0efcdb3718 20617:ba2b07c13913
391 391
392 int nargin = args.length (); 392 int nargin = args.length ();
393 393
394 if (nargin == 2 || nargin == 3) 394 if (nargin == 2 || nargin == 3)
395 { 395 {
396 if (args(0).is_string ()) 396 std::string path = args(0).string_value ("file_in_path: PATH must be a string");
397 { 397
398 std::string path = args(0).string_value (); 398 string_vector names = args(1).all_strings ();
399 399
400 string_vector names = args(1).all_strings (); 400 if (! error_state && names.numel () > 0)
401 401 {
402 if (! error_state && names.numel () > 0) 402 if (nargin == 2)
403 retval = search_path_for_file (path, names);
404 else if (nargin == 3)
403 { 405 {
404 if (nargin == 2) 406 std::string opt = args(2).string_value ();
405 retval = search_path_for_file (path, names); 407
406 else if (nargin == 3) 408 if (! error_state && opt == "all")
407 { 409 retval = Cell (make_absolute
408 std::string opt = args(2).string_value (); 410 (search_path_for_all_files (path, names)));
409 411 else
410 if (! error_state && opt == "all") 412 error ("file_in_path: invalid option");
411 retval = Cell (make_absolute
412 (search_path_for_all_files (path, names)));
413 else
414 error ("file_in_path: invalid option");
415 }
416 } 413 }
417 else
418 error ("file_in_path: all arguments must be strings");
419 } 414 }
420 else 415 else
421 error ("file_in_path: PATH must be a string"); 416 error ("file_in_path: all arguments must be strings");
422 } 417 }
423 else 418 else
424 print_usage (); 419 print_usage ();
425 420
426 return retval; 421 return retval;
759 754
760 int nargin = args.length (); 755 int nargin = args.length ();
761 756
762 if (nargin == 1) 757 if (nargin == 1)
763 { 758 {
764 if (args(0).is_string ()) 759 std::string str = args(0).string_value ("do_string_escapes: STRING argument must be of type string");
765 retval = do_string_escapes (args(0).string_value ()); 760
766 else 761 retval = do_string_escapes (str);
767 error ("do_string_escapes: STRING argument must be of type string");
768 } 762 }
769 else 763 else
770 print_usage (); 764 print_usage ();
771 765
772 return retval; 766 return retval;
903 897
904 int nargin = args.length (); 898 int nargin = args.length ();
905 899
906 if (nargin == 1) 900 if (nargin == 1)
907 { 901 {
908 if (args(0).is_string ()) 902 std::string str = args(0).string_value ("undo_string_escapes: S argument must be a string");
909 retval = undo_string_escapes (args(0).string_value ()); 903
910 else 904 retval = undo_string_escapes (str);
911 error ("undo_string_escapes: S argument must be a string");
912 } 905 }
913 else 906 else
914 print_usage (); 907 print_usage ();
915 908
916 return retval; 909 return retval;
1000 { 993 {
1001 octave_value retval = std::string (); 994 octave_value retval = std::string ();
1002 995
1003 if (args.length () == 1) 996 if (args.length () == 1)
1004 { 997 {
1005 std::string nm = args(0).string_value (); 998 std::string nm = args(0).string_value ("make_absolute_filename: FILE argument must be a file name");
1006 999
1007 if (! error_state) 1000 retval = octave_env::make_absolute (nm);
1008 retval = octave_env::make_absolute (nm);
1009 else
1010 error ("make_absolute_filename: FILE argument must be a file name");
1011 } 1001 }
1012 else 1002 else
1013 print_usage (); 1003 print_usage ();
1014 1004
1015 return retval; 1005 return retval;
1045 1035
1046 std::string dir; 1036 std::string dir;
1047 1037
1048 if (nargin == 1 || nargin == 2) 1038 if (nargin == 1 || nargin == 2)
1049 { 1039 {
1050 dir = args(0).string_value (); 1040 dir = args(0).string_value ("dir_in_loadpath: DIR must be a directory name");
1051 1041
1052 if (! error_state) 1042 if (nargin == 1)
1053 { 1043 retval = load_path::find_dir (dir);
1054 if (nargin == 1) 1044 else if (nargin == 2)
1055 retval = load_path::find_dir (dir); 1045 retval = Cell (load_path::find_matching_dirs (dir));
1056 else if (nargin == 2)
1057 retval = Cell (load_path::find_matching_dirs (dir));
1058 }
1059 else
1060 error ("dir_in_loadpath: DIR must be a directory name");
1061 } 1046 }
1062 else 1047 else
1063 print_usage (); 1048 print_usage ();
1064 1049
1065 return retval; 1050 return retval;