changeset 8353:349a555729a9

keep empty strings in char
author Thorsten Meyer <thorsten.meyier@gmx.de>
date Sat, 15 Nov 2008 00:58:17 +0100
parents 33337f1aca75
children 534fd216278c
files src/ChangeLog src/strfns.cc
diffstat 2 files changed, 37 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Nov 04 23:03:50 2008 +0100
+++ b/src/ChangeLog	Sat Nov 15 00:58:17 2008 +0100
@@ -68,6 +68,10 @@
 	OCTAVE_VALUE_INT_SCALAR_T::increment,
 	OCTAVE_VALUE_INT_SCALAR_T::decrement): Convert 1 to OCTAVE_INT_T.
 
+2008-11-15  Thorsten Meyer  <thorsten.meyier@gmx.de>
+
+        * strfns.cc (Fchar): adapt to conserve empty strings, add tests
+        
 2008-11-12  Michael Goffioul  <michael.goffioul@gmail.com>
 
 	* dirfcn.cc (Ffilesep): Make it return all file separators when 'all'
--- a/src/strfns.cc	Tue Nov 04 23:03:50 2008 +0100
+++ b/src/strfns.cc	Sat Nov 15 00:58:17 2008 +0100
@@ -90,7 +90,10 @@
 	      return retval;
 	    }
 
-	  n_elts += s.length ();
+	  if (s.length () > 0)
+            n_elts += s.length ();
+          else
+            n_elts += 1;
 
 	  int s_max_len = s.max_length ();
 
@@ -108,16 +111,23 @@
 
 	  int n = s.length ();
 
-	  for (int j = 0; j < n; j++)
-	    {
-	      std::string t = s[j];
-	      int t_len = t.length ();
+          if (n > 0)
+            {
+	      for (int j = 0; j < n; j++)
+	        {
+	          std::string t = s[j];
+	          int t_len = t.length ();
 
-	      if (max_len > t_len)
-		t += std::string (max_len - t_len, ' ');
+	          if (max_len > t_len)
+		    t += std::string (max_len - t_len, ' ');
 
-	      result[k++] = t;
-	    }
+	          result[k++] = t;
+	        }
+            }
+          else
+            {
+               result[k++] = std::string (max_len, ' ');
+            }
 	}
 
       retval = octave_value (result, '\'');
@@ -128,6 +138,20 @@
   return retval;
 }
 
+/*
+%!error <Invalid call to char> char()
+%!assert (char (100) == "d");
+%!assert (all(char (100,100) == ["d";"d"]));
+%!assert (all(char ({100,100}) == ["d";"d"]));
+%!assert (all(char ([100,100]) == ["dd"]));
+%!assert (all(char ({100,{100}}) == ["d";"d"]));
+%!assert (all(char (100, [], 100) == ["d";" ";"d"]))
+%!assert (all(char ({100, [], 100}) == ["d";" ";"d"]))
+%!assert (all(char ({100,{100, {""}}}) == ["d";"d";" "]))
+%!assert (all(char (["a";"be"], {"c", 100}) == ["a";"be";"c";"d"]))
+*/
+
+
 DEFUN (ischar, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} ischar (@var{a})\n\