# HG changeset patch # User John W. Eaton # Date 1203537388 18000 # Node ID 5d50ebf98273609df0503fbdcb3be92cf7780837 # Parent ef95e842ba81a7b616b7597a77dcafea5bda84d3 detect cellstr args in strcat diff -r ef95e842ba81 -r 5d50ebf98273 scripts/ChangeLog --- 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 + + * strings/strcat.m: Detect cellstr args. + 2008-02-15 Timo Lindfors * statistics/tests/kruskal_wallis_test.m: Handle ties. diff -r ef95e842ba81 -r 5d50ebf98273 scripts/strings/strcat.m --- 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"})))