diff src/oct-stream.cc @ 3653:84b2f30007d5

[project @ 2000-03-31 23:33:25 by jwe]
author jwe
date Fri, 31 Mar 2000 23:33:26 +0000
parents 71b4ccd27162
children aef06675c94d
line wrap: on
line diff
--- a/src/oct-stream.cc
+++ b/src/oct-stream.cc
@@ -1970,7 +1970,7 @@
 {
 public:
 
-  enum state { ok, list_exhausted, conversion_error };
+  enum state { ok, conversion_error };
 
   printf_value_cache (const octave_value_list& args)
     : values (args), val_idx (0), elt_idx (0),
@@ -1990,8 +1990,7 @@
 
   operator bool () const { return (curr_state == ok); }
 
-  bool exhausted (void)
-    { return (curr_state == list_exhausted || val_idx >= n_vals); }
+  bool exhausted (void) { return (val_idx >= n_vals); }
 
   bool looking_at_string (void);
 
@@ -2022,26 +2021,10 @@
 {
   bool retval = false;
 
-  int idx = -1;
-
-  if (elt_idx == 0)
-    idx = val_idx;
-  else if (elt_idx >= n_elts)
-    idx = val_idx + 1;
+  int idx = (elt_idx == 0) ? val_idx : -1;
 
   if (idx >= 0 && idx < n_vals)
-    {
-      octave_value tmp_val = values (idx);
-
-      // An empty string has zero rows and zero columns.
-
-      if (tmp_val.is_string ())
-	{
-	  int nr = tmp_val.rows ();
-
-	  retval = (nr == 1 || (nr == 0 && tmp_val.columns () == 0));
-	}
-    }
+    retval = values(idx).is_string ();
 
   return retval;
 }
@@ -2074,7 +2057,15 @@
 
       if (elt_idx < n_elts)
 	{
-	  return data[elt_idx++];
+	  retval = data[elt_idx++];
+
+	  if (elt_idx >= n_elts)
+	    {
+	      elt_idx = 0;
+	      val_idx++;
+	      data = 0;
+	    }
+
 	  break;
 	}
       else
@@ -2085,8 +2076,6 @@
 	}
     }
 
-  curr_state = list_exhausted;
-
   return retval;
 }
 
@@ -2115,14 +2104,27 @@
 
   if (looking_at_string ())
     {
-      if (elt_idx != 0)
+      octave_value tval = values (val_idx++);
+
+      if (tval.rows () == 1)
+	retval = tval.string_value ();
+      else
 	{
-	  val_idx++;
-	  elt_idx = 0;
-	  data = 0;
+	  // In the name of Matlab compatibility.
+
+	  charMatrix chm = tval.char_matrix_value ();
+
+	  int nr = chm.rows ();
+	  int nc = chm.columns ();
+
+	  int k = 0;
+
+	  retval.resize (nr * nc, '\0');
+
+	  for (int j = 0; j < nc; j++)
+	    for (int i = 0; i < nr; i++)
+	      retval[k++] = chm(i,j);
 	}
-
-      retval = values (val_idx++).string_value ();
     }
   else
     curr_state = conversion_error;