changeset 11653:5d50ebf98273 release-3-0-x

detect cellstr args in strcat
author John W. Eaton <jwe@octave.org>
date Wed, 20 Feb 2008 14:56:28 -0500
parents ef95e842ba81
children 087af2a4ca26
files scripts/ChangeLog scripts/strings/strcat.m
diffstat 2 files changed, 33 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Feb 15 19:54:25 2008 -0500
+++ b/scripts/ChangeLog	Wed Feb 20 14:56:28 2008 -0500
@@ -1,3 +1,7 @@
+2008-02-20  John W. Eaton  <jwe@octave.org>
+
+	* strings/strcat.m: Detect cellstr args.
+
 2008-02-15  Timo Lindfors  <timo.lindfors@iki.fi>
 
 	* statistics/tests/kruskal_wallis_test.m: Handle ties.
--- a/scripts/strings/strcat.m	Fri Feb 15 19:54:25 2008 -0500
+++ b/scripts/strings/strcat.m	Wed Feb 20 14:56:28 2008 -0500
@@ -35,20 +35,36 @@
 
 function st = strcat (varargin)
 
-  if (nargin < 1)
+  if (nargin > 0)
+
+    if (iscellstr (varargin))
+      ## All arguments are character strings.
+      unwind_protect
+	tmp = warning ("query", "Octave:empty-list-elements");
+	warning ("off", "Octave:empty-list-elements");
+	st = [varargin{:}];
+      unwind_protect_cleanup
+	warning (tmp.state, "Octave:empty-list-elements");
+      end_unwind_protect
+    else
+      for i = 1:nargin
+	tmp = varargin{i};
+	if (! (iscellstr (tmp) || ischar (tmp)))
+	  error ("strcat: all arguments must be strings or cell arrays of strings");
+	endif
+      endfor
+      st = strcat_cell (varargin);
+    endif
+  else
     print_usage ();
-  elseif (! iscellstr (varargin))
-    error ("strcat: all arguments must be strings");
   endif
 
-  unwind_protect
-    tmp = warning ("query", "Octave:empty-list-elements");
-    warning ("off", "Octave:empty-list-elements");
-    st = [varargin{:}];
-  unwind_protect_cleanup
-    warning (tmp.state, "Octave:empty-list-elements");
-  end_unwind_protect
+endfunction
 
+function st = strcat_cell (varargin)
+  ## All args must be same size or scalars.
+  ## See the xtest below for expected behavior.
+  error ("strcat: concatenating cell arrays of strings not implemented");
 endfunction
 
 ## test the dimensionality
@@ -56,3 +72,6 @@
 %!assert(strcat("ab ", "ab "), "ab ab ")
 ## 2d
 %!assert(strcat(["ab ";"cde"], ["ab ";"cde"]), ["ab ab ";"cdecde"])
+
+%!xtest
+%! assert(all (strcmp (strcat ("a", {"bc", "de"}, "f"), {"abcf", "adef"})))