diff scripts/strings/cstrcat.m @ 7540:3422f39573b1

strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
author Ben Abbott <bpabbott@mac.com>
date Thu, 28 Feb 2008 02:41:19 -0500
parents scripts/strings/strcat.m@ddcf233d765b
children 502e58a0d44f
line wrap: on
line diff
copy from scripts/strings/strcat.m
copy to scripts/strings/cstrcat.m
--- a/scripts/strings/strcat.m
+++ b/scripts/strings/cstrcat.m
@@ -18,13 +18,13 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} strcat (@var{s1}, @var{s2}, @dots{})
+## @deftypefn {Function File} {} cstrcat (@var{s1}, @var{s2}, @dots{})
 ## Return a string containing all the arguments concatenated.  For example,
 ##
 ## @example
 ## @group
 ## s = [ "ab"; "cde" ];
-## strcat (s, s, s)
+## cstrcat (s, s, s)
 ##      @result{} "ab ab ab "
 ##         "cdecdecde"
 ## @end group
@@ -33,7 +33,7 @@
 
 ## Author: jwe
 
-function st = strcat (varargin)
+function st = cstrcat (varargin)
 
   if (nargin > 0)
 
@@ -47,13 +47,7 @@
 	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);
+      error ("cstrcat: expecting arguments to character strings");
     endif
   else
     print_usage ();
@@ -61,25 +55,16 @@
 
 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
 ## 1d
-%!assert(strcat("ab ", "ab "), "ab ab ")
+%!assert(cstrcat("ab ", "ab "), "ab ab ")
 ## 2d
-%!assert(strcat(["ab ";"cde"], ["ab ";"cde"]), ["ab ab ";"cdecde"])
-
-%!assert((strcmp (strcat ("foo", "bar"), "foobar")
-%! && strcmp (strcat (["a"; "bb"], ["foo"; "bar"]), ["a foo"; "bbbar"])));
+%!assert(cstrcat(["ab ";"cde"], ["ab ";"cde"]), ["ab ab ";"cdecde"])
 
-%!xtest
-%! assert(all (strcmp (strcat ("a", {"bc", "de"}, "f"), {"abcf", "adef"})))
+%!assert((strcmp (cstrcat ("foo", "bar"), "foobar")
+%! && strcmp (cstrcat (["a"; "bb"], ["foo"; "bar"]), ["a foo"; "bbbar"])));
 
-%!error strcat ();
+%!error cstrcat ();
 
-%!error strcat (1, 2);
+%!error cstrcat (1, 2);