comparison scripts/strings/strcat.m @ 20166:196871335aa8

Allow call with empty argument list in strcat related functions (bug #44981) * libinterp/corefcn/strfns.cc (strvcat): return an empty string for an empty argument list. Simply dropping the input checking, will return an empty string. This makes it more consistent with cat(), vertcat, and horzcat() functions, which return [] for this cases. It makes it easier to support "strcat (cell{:})" when cell is empty. * scripts/strings/cstrcat.m, scripts/strings/strcat.m: same as above. But because [cellstr{:}] when cellstr is empty returns double ([]), we specifically return "".
author Carnë Draug <carandraug@octave.org>
date Fri, 01 May 2015 16:21:39 +0100
parents 4197fc428c7d
children
comparison
equal deleted inserted replaced
20161:65e22ba879f0 20166:196871335aa8
79 ## Author: jwe 79 ## Author: jwe
80 80
81 function st = strcat (varargin) 81 function st = strcat (varargin)
82 82
83 if (nargin == 0) 83 if (nargin == 0)
84 print_usage (); 84 st = "";
85 endif 85 elseif (nargin == 1)
86
87 if (nargin == 1)
88 st = varargin{1}; 86 st = varargin{1};
89 else 87 else
90 ## Convert to cells of strings 88 ## Convert to cells of strings
91 uo = "uniformoutput"; 89 uo = "uniformoutput";
92 reals = cellfun ("isreal", varargin); 90 reals = cellfun ("isreal", varargin);
146 %!assert (all (strcmp (strcat ("a", {"bb", "ccc"}), {"abb", "accc"}))) 144 %!assert (all (strcmp (strcat ("a", {"bb", "ccc"}), {"abb", "accc"})))
147 145
148 %!assert (strcat (1, 2), strcat (char (1), char (2))) 146 %!assert (strcat (1, 2), strcat (char (1), char (2)))
149 %!assert (strcat ("", 2), strcat ([], char (2))) 147 %!assert (strcat ("", 2), strcat ([], char (2)))
150 148
151 %!error strcat () 149 %!assert (strcat (), "")
152 150