diff libinterp/corefcn/time.cc @ 20616:fd0efcdb3718

use new string_value method to handle value extraction errors * dirfns.cc, file-io.cc, gammainc.cc, help.cc, load-path.cc, octave-link.cc, qz.cc, regexp.cc, strfns.cc, syscalls.cc, time.cc, variables.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 19:00:51 -0400
parents f90c8372b7ba
children
line wrap: on
line diff
--- a/libinterp/corefcn/time.cc	Thu Oct 08 17:55:57 2015 -0400
+++ b/libinterp/corefcn/time.cc	Thu Oct 08 19:00:51 2015 -0400
@@ -473,26 +473,21 @@
 
   if (args.length () == 2)
     {
-      if (args(0).is_string ())
+      std::string fmt = args(0).string_value ("strftime: FMT must be a string");
+
+      octave_scalar_map map = args(1).scalar_map_value ();
+
+      if (! error_state)
         {
-          std::string fmt = args(0).string_value ();
-
-          octave_scalar_map map = args(1).scalar_map_value ();
+          octave_base_tm tm = extract_tm (map);
 
           if (! error_state)
-            {
-              octave_base_tm tm = extract_tm (map);
-
-              if (! error_state)
-                retval = tm.strftime (fmt);
-              else
-                error ("strftime: invalid TM_STRUCT argument");
-            }
+            retval = tm.strftime (fmt);
           else
-            error ("strftime: TM_STRUCT must be a structure");
+            error ("strftime: invalid TM_STRUCT argument");
         }
       else
-        error ("strftime: FMT must be a string");
+        error ("strftime: TM_STRUCT must be a structure");
     }
   else
     print_usage ();
@@ -529,24 +524,14 @@
 
   if (args.length () == 2)
     {
-      if (args(0).is_string ())
-        {
-          std::string str = args(0).string_value ();
+      std::string str = args(0).string_value ("strptime: argument STR must be a string");
 
-          if (args(1).is_string ())
-            {
-              std::string fmt = args(1).string_value ();
+      std::string fmt = args(1).string_value ("strptime: FMT must be a string");
 
-              octave_strptime t (str, fmt);
+      octave_strptime t (str, fmt);
 
-              retval(1) = t.characters_converted ();
-              retval(0) = octave_value (mk_tm_map (t));
-            }
-          else
-            error ("strptime: FMT must be a string");
-        }
-      else
-        error ("strptime: argument STR must be a string");
+      retval(1) = t.characters_converted ();
+      retval(0) = octave_value (mk_tm_map (t));
     }
   else
     print_usage ();