Mercurial > hg > octave-max
changeset 7504:ddcf233d765b
detect cellstr args in strcat
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 20 Feb 2008 14:56:22 -0500 |
parents | 8c32f95c2639 |
children | f5005d9510f4 |
files | scripts/ChangeLog scripts/strings/strcat.m |
diffstat | 2 files changed, 33 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2008-02-20 John W. Eaton <jwe@octave.org> + + * strings/strcat.m: Detect cellstr args. + 2008-02-19 Ben Abbott <bpabbott@mac.com> * miscellaneous/edit.m: New option EDITINPLACE. Prefer file list
--- a/scripts/strings/strcat.m +++ b/scripts/strings/strcat.m @@ -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 @@ -60,6 +76,9 @@ %!assert((strcmp (strcat ("foo", "bar"), "foobar") %! && strcmp (strcat (["a"; "bb"], ["foo"; "bar"]), ["a foo"; "bbbar"]))); +%!xtest +%! assert(all (strcmp (strcat ("a", {"bc", "de"}, "f"), {"abcf", "adef"}))) + %!error strcat (); %!error strcat (1, 2);