]> Creatis software - CreaPhase.git/blob - octave_packages/m/strings/cstrcat.m
update packages
[CreaPhase.git] / octave_packages / m / strings / cstrcat.m
1 ## Copyright (C) 1994-2012 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} cstrcat (@var{s1}, @var{s2}, @dots{})
21 ## Return a string containing all the arguments concatenated
22 ## horizontally.  Trailing white space is preserved.  For example:
23 ##
24 ## @example
25 ## @group
26 ## cstrcat ("ab   ", "cd")
27 ##       @result{} "ab   cd"
28 ## @end group
29 ## @end example
30 ##
31 ## @example
32 ## @group
33 ## s = [ "ab"; "cde" ];
34 ## cstrcat (s, s, s)
35 ##      @result{} "ab ab ab "
36 ##         "cdecdecde"
37 ## @end group
38 ## @end example
39 ## @seealso{strcat, char, strvcat}
40 ## @end deftypefn
41
42 ## Author: jwe
43
44 function st = cstrcat (varargin)
45
46   if (nargin < 1)
47     print_usage ();
48   elseif (! iscellstr (varargin))
49     error ("cstrcat: expecting arguments to character strings");
50   endif
51
52   st = [varargin{:}];
53
54 endfunction
55
56
57 ## Test the dimensionality
58 ## 1d
59 %!assert (cstrcat ("ab ", "ab "), "ab ab ")
60 ## 2d
61 %!assert (cstrcat (["ab ";"cde"], ["ab ";"cde"]), ["ab ab ";"cdecde"])
62
63 %!assert (cstrcat ("foo", "bar"), "foobar")
64 %!assert (cstrcat (["a"; "bb"], ["foo"; "bar"]), ["a foo"; "bbbar"])
65
66 %% Test input validation
67 %!error cstrcat ();
68 %!error cstrcat (1, 2);
69