changeset 6815:fa3c21cdf3bc

[project @ 2007-08-14 18:04:18 by jwe]
author jwe
date Tue, 14 Aug 2007 18:04:19 +0000
parents 8c89a644df8a
children ec4c1dfb985a
files src/ChangeLog src/ov-str-mat.cc
diffstat 2 files changed, 28 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Aug 14 17:30:59 2007 +0000
+++ b/src/ChangeLog	Tue Aug 14 18:04:19 2007 +0000
@@ -1,3 +1,8 @@
+2007-08-14  John W. Eaton  <jwe@octave.org>
+
+	* ov-str-mat.cc (octave_char_matrix_str::all_strings):
+	If empty, return a single element string vector containing "".
+
 2007-08-10  John W. Eaton  <jwe@octave.org>
 
 	* pt-idx.cc (tree_index_expression::get_struct_index): Improve
--- a/src/ov-str-mat.cc	Tue Aug 14 17:30:59 2007 +0000
+++ b/src/ov-str-mat.cc	Tue Aug 14 18:04:19 2007 +0000
@@ -229,14 +229,32 @@
 
   if (matrix.ndims () == 2)
     {
-      charMatrix chm = matrix.matrix_value ();
+      // FIXME -- is this the best behavior possible?  It does provide
+      // compatible behavior for things like
+      //
+      //   cellstr ("")
+      //   cellstr (char (zeros ((2, 0)))
+      //   cellstr (char (zeros ((0, 2)))
+      //
+      // etc.
 
-      octave_idx_type n = chm.rows ();
+      if (is_empty ())
+	{
+	  retval.resize (1);
 
-      retval.resize (n);
+	  retval[0] = "";
+	}
+      else
+	{
+	  charMatrix chm = matrix.matrix_value ();
 
-      for (octave_idx_type i = 0; i < n; i++)
-	retval[i] = chm.row_as_string (i);
+	  octave_idx_type n = chm.rows ();
+
+	  retval.resize (n);
+
+	  for (octave_idx_type i = 0; i < n; i++)
+	    retval[i] = chm.row_as_string (i);
+	}
     }
   else
     error ("invalid conversion of charNDArray to string_vector");