comparison 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
comparison
equal deleted inserted replaced
7539:3e107d73aeb4 7540:3422f39573b1
1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003,
2 ## 2005, 2006, 2007 John W. Eaton
3 ##
4 ## This file is part of Octave.
5 ##
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
10 ##
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
19
20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} cstrcat (@var{s1}, @var{s2}, @dots{})
22 ## Return a string containing all the arguments concatenated. For example,
23 ##
24 ## @example
25 ## @group
26 ## s = [ "ab"; "cde" ];
27 ## cstrcat (s, s, s)
28 ## @result{} "ab ab ab "
29 ## "cdecdecde"
30 ## @end group
31 ## @end example
32 ## @end deftypefn
33
34 ## Author: jwe
35
36 function st = cstrcat (varargin)
37
38 if (nargin > 0)
39
40 if (iscellstr (varargin))
41 ## All arguments are character strings.
42 unwind_protect
43 tmp = warning ("query", "Octave:empty-list-elements");
44 warning ("off", "Octave:empty-list-elements");
45 st = [varargin{:}];
46 unwind_protect_cleanup
47 warning (tmp.state, "Octave:empty-list-elements");
48 end_unwind_protect
49 else
50 error ("cstrcat: expecting arguments to character strings");
51 endif
52 else
53 print_usage ();
54 endif
55
56 endfunction
57
58 ## test the dimensionality
59 ## 1d
60 %!assert(cstrcat("ab ", "ab "), "ab ab ")
61 ## 2d
62 %!assert(cstrcat(["ab ";"cde"], ["ab ";"cde"]), ["ab ab ";"cdecde"])
63
64 %!assert((strcmp (cstrcat ("foo", "bar"), "foobar")
65 %! && strcmp (cstrcat (["a"; "bb"], ["foo"; "bar"]), ["a foo"; "bbbar"])));
66
67 %!error cstrcat ();
68
69 %!error cstrcat (1, 2);
70