Mercurial > octave-antonio
annotate scripts/strings/strcat.m @ 17338:1c89599167a6
maint: End m-files with 1 blank line.
Simplifies automated grammarchecking script.
* scripts/@ftp/ascii.m, scripts/@ftp/binary.m, scripts/@ftp/cd.m,
scripts/@ftp/close.m, scripts/@ftp/delete.m, scripts/@ftp/dir.m,
scripts/@ftp/display.m, scripts/@ftp/ftp.m, scripts/@ftp/loadobj.m,
scripts/@ftp/mget.m, scripts/@ftp/mkdir.m, scripts/@ftp/mput.m,
scripts/@ftp/rename.m, scripts/@ftp/rmdir.m, scripts/@ftp/saveobj.m,
scripts/audio/lin2mu.m, scripts/audio/loadaudio.m, scripts/audio/mu2lin.m,
scripts/audio/record.m, scripts/audio/saveaudio.m, scripts/audio/setaudio.m,
scripts/deprecated/__error_text__.m, scripts/deprecated/cut.m,
scripts/deprecated/error_text.m, scripts/deprecated/isstr.m,
scripts/deprecated/polyderiv.m, scripts/deprecated/studentize.m,
scripts/deprecated/sylvester_matrix.m, scripts/general/bicubic.m,
scripts/general/celldisp.m, scripts/general/colon.m,
scripts/general/cplxpair.m, scripts/general/del2.m, scripts/general/display.m,
scripts/general/isdir.m, scripts/general/isequaln.m, scripts/general/loadobj.m,
scripts/general/private/__isequal__.m, scripts/general/private/__splinen__.m,
scripts/general/profexplore.m, scripts/general/quadgk.m,
scripts/general/randi.m, scripts/general/repmat.m, scripts/general/saveobj.m,
scripts/geometry/delaunay.m, scripts/help/__unimplemented__.m,
scripts/help/doc_cache_create.m, scripts/help/get_first_help_sentence.m,
scripts/help/help.m, scripts/help/print_usage.m,
scripts/help/private/__additional_help_message__.m,
scripts/help/private/__strip_html_tags__.m, scripts/help/type.m,
scripts/image/imfinfo.m, scripts/image/imformats.m, scripts/image/imread.m,
scripts/image/imwrite.m, scripts/image/private/__imfinfo__.m,
scripts/image/private/__imread__.m, scripts/image/private/__imwrite__.m,
scripts/image/private/imageIO.m, scripts/image/private/imwrite_filename.m,
scripts/image/private/ind2x.m, scripts/io/beep.m, scripts/io/strread.m,
scripts/io/textread.m, scripts/io/textscan.m, scripts/linear-algebra/krylov.m,
scripts/linear-algebra/subspace.m, scripts/miscellaneous/bug_report.m,
scripts/miscellaneous/bunzip2.m, scripts/miscellaneous/cast.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dir.m, scripts/miscellaneous/dump_prefs.m,
scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m,
scripts/miscellaneous/gunzip.m, scripts/miscellaneous/isdeployed.m,
scripts/miscellaneous/ismac.m, scripts/miscellaneous/mex.m,
scripts/miscellaneous/mexext.m, scripts/miscellaneous/mkoctfile.m,
scripts/miscellaneous/movefile.m, scripts/miscellaneous/namelengthmax.m,
scripts/miscellaneous/news.m, scripts/miscellaneous/pack.m,
scripts/miscellaneous/perl.m,
scripts/miscellaneous/private/display_info_file.m,
scripts/miscellaneous/python.m, scripts/miscellaneous/rmappdata.m,
scripts/miscellaneous/run.m, scripts/miscellaneous/tar.m,
scripts/miscellaneous/tempname.m, scripts/miscellaneous/untar.m,
scripts/miscellaneous/unzip.m, scripts/miscellaneous/what.m,
scripts/miscellaneous/zip.m, scripts/optimization/fminunc.m,
scripts/optimization/fsolve.m, scripts/optimization/fzero.m,
scripts/optimization/glpk.m, scripts/optimization/optimget.m,
scripts/optimization/optimset.m, scripts/optimization/qp.m,
scripts/optimization/sqp.m, scripts/path/pathdef.m, scripts/pkg/pkg.m,
scripts/pkg/private/build.m, scripts/pkg/private/describe.m,
scripts/pkg/private/dirempty.m, scripts/pkg/private/get_forge_download.m,
scripts/pkg/private/get_forge_pkg.m,
scripts/pkg/private/get_unsatisfied_deps.m, scripts/pkg/private/install.m,
scripts/pkg/private/is_architecture_dependent.m,
scripts/pkg/private/list_forge_packages.m, scripts/pkg/private/rebuild.m,
scripts/pkg/private/shell.m, scripts/pkg/private/uninstall.m,
scripts/plot/axes.m, scripts/plot/box.m, scripts/plot/closereq.m,
scripts/plot/diffuse.m, scripts/plot/ezpolar.m, scripts/plot/findfigs.m,
scripts/plot/gco.m, scripts/plot/guidata.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/linkprop.m, scripts/plot/peaks.m,
scripts/plot/print.m, scripts/plot/private/__add_datasource__.m,
scripts/plot/private/__axis_label__.m, scripts/plot/private/__clabel__.m,
scripts/plot/private/__color_str_rgb__.m, scripts/plot/private/__contour__.m,
scripts/plot/private/__default_plot_options__.m,
scripts/plot/private/__errcomm__.m, scripts/plot/private/__file_filter__.m,
scripts/plot/private/__fltk_file_filter__.m,
scripts/plot/private/__getlegenddata__.m,
scripts/plot/private/__gnuplot_open_stream__.m,
scripts/plot/private/__gnuplot_print__.m,
scripts/plot/private/__go_draw_axes__.m,
scripts/plot/private/__interp_cube__.m, scripts/plot/private/__is_function__.m,
scripts/plot/private/__line__.m, scripts/plot/private/__marching_cube__.m,
scripts/plot/private/__next_line_style__.m, scripts/plot/private/__patch__.m,
scripts/plot/private/__pie__.m, scripts/plot/private/__pltopt__.m,
scripts/plot/private/__quiver__.m, scripts/plot/private/__scatter__.m,
scripts/plot/private/__stem__.m, scripts/plot/private/__uigetdir_fltk__.m,
scripts/plot/private/__uigetfile_fltk__.m,
scripts/plot/private/__uiobject_split_args__.m,
scripts/plot/private/__uiputfile_fltk__.m, scripts/plot/refresh.m,
scripts/plot/saveas.m, scripts/plot/shg.m, scripts/plot/specular.m,
scripts/plot/sphere.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/uicontextmenu.m, scripts/plot/uicontrol.m, scripts/plot/uipanel.m,
scripts/plot/uipushtool.m, scripts/plot/uiresume.m,
scripts/plot/uitoggletool.m, scripts/plot/uitoolbar.m, scripts/plot/uiwait.m,
scripts/plot/waitforbuttonpress.m, scripts/polynomial/pchip.m,
scripts/polynomial/polyeig.m, scripts/polynomial/ppval.m,
scripts/prefs/addpref.m, scripts/prefs/getpref.m, scripts/prefs/ispref.m,
scripts/prefs/private/loadprefs.m, scripts/prefs/private/prefsfile.m,
scripts/prefs/private/saveprefs.m, scripts/prefs/setpref.m,
scripts/set/private/validargs.m, scripts/set/unique.m,
scripts/signal/arch_fit.m, scripts/signal/arch_rnd.m,
scripts/signal/arch_test.m, scripts/signal/arma_rnd.m,
scripts/signal/durbinlevinson.m, scripts/signal/fractdiff.m,
scripts/signal/freqz.m, scripts/signal/freqz_plot.m, scripts/signal/hurst.m,
scripts/signal/periodogram.m, scripts/signal/private/rectangle_lw.m,
scripts/signal/private/rectangle_sw.m, scripts/signal/private/triangle_sw.m,
scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m,
scripts/signal/stft.m, scripts/signal/synthesis.m, scripts/signal/yulewalker.m,
scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m,
scripts/sparse/gmres.m, scripts/sparse/private/__sprand_impl__.m,
scripts/sparse/spdiags.m, scripts/sparse/sprandn.m, scripts/specfun/bessel.m,
scripts/specfun/betaln.m, scripts/specfun/expint.m,
scripts/special-matrix/gallery.m, scripts/startup/__finish__.m,
scripts/statistics/base/qqplot.m, scripts/statistics/distributions/tcdf.m,
scripts/statistics/distributions/wienrnd.m,
scripts/statistics/models/logistic_regression.m,
scripts/statistics/models/private/logistic_regression_derivatives.m,
scripts/statistics/models/private/logistic_regression_likelihood.m,
scripts/statistics/tests/anova.m, scripts/statistics/tests/bartlett_test.m,
scripts/statistics/tests/chisquare_test_homogeneity.m,
scripts/statistics/tests/chisquare_test_independence.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/f_test_regression.m,
scripts/statistics/tests/hotelling_test.m,
scripts/statistics/tests/hotelling_test_2.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/manova.m, scripts/statistics/tests/mcnemar_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/run_test.m,
scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m,
scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/strcat.m,
scripts/strings/strjoin.m, scripts/strings/strsplit.m,
scripts/testfun/__have_feature__.m, scripts/testfun/__printf_assert__.m,
scripts/testfun/__prog_output_assert__.m, scripts/testfun/__run_test_suite__.m,
scripts/time/clock.m, scripts/time/datenum.m, scripts/ui/errordlg.m,
scripts/ui/private/message_dialog.m: End m-files with 1 blank line.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 28 Aug 2013 08:33:02 -0700 |
parents | bc924baa2c4e |
children | 5ca5aff90ffd |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12931
diff
changeset
|
1 ## Copyright (C) 1994-2012 John W. Eaton |
10032 | 2 ## Copyright (C) 2009 Jaroslav Hajek |
2313 | 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 | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 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 | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
920 | 19 |
3361 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} strcat (@var{s1}, @var{s2}, @dots{}) | |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
22 ## Return a string containing all the arguments concatenated |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
23 ## horizontally. If the arguments are cells strings, @code{strcat} |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
24 ## returns a cell string with the individual cells concatenated. |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
25 ## For numerical input, each element is converted to the |
14821
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
26 ## corresponding ASCII character. Trailing white space for each of |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
27 ## the inputs (@var{s1}, @var{s2}, @dots{}) is eliminated before they |
14821
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
28 ## are concatenated. |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
29 ## |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10037
diff
changeset
|
30 ## For example: |
3426 | 31 ## |
3361 | 32 ## @example |
33 ## @group | |
14821
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
34 ## strcat ("|", " leading space is preserved", "|") |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
35 ## @result{} | leading space is perserved| |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
36 ## @end group |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
37 ## @end example |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
38 ## |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
39 ## @example |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
40 ## @group |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
41 ## strcat ("|", "trailing space is eliminated ", "|") |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
42 ## @result{} |trailing space is eliminated| |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
43 ## @end group |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
44 ## @end example |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
45 ## |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
46 ## @example |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
47 ## @group |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
48 ## strcat ("homogeneous space |", " ", "| is also eliminated") |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
49 ## @result{} homogeneous space || is also eliminated |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
50 ## @end group |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
51 ## @end example |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
52 ## |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
53 ## @example |
aad7d7ee8e8a
Clarify doc string for strcat.
Ben Abbott <bpabbott@mac.com>
parents:
14363
diff
changeset
|
54 ## @group |
3361 | 55 ## s = [ "ab"; "cde" ]; |
56 ## strcat (s, s, s) | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 ## @result{} |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
58 ## "ab ab ab " |
3361 | 59 ## "cdecdecde" |
60 ## @end group | |
61 ## @end example | |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
62 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
63 ## @example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
64 ## @group |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
65 ## s = @{ "ab"; "cde" @}; |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
66 ## strcat (s, s, s) |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
67 ## @result{} |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
68 ## @{ |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
69 ## [1,1] = ababab |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
70 ## [2,1] = cdecdecde |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
71 ## @} |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
72 ## @end group |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
73 ## @end example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
74 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8143
diff
changeset
|
75 ## @seealso{cstrcat, char, strvcat} |
3361 | 76 ## @end deftypefn |
2697 | 77 |
2314 | 78 ## Author: jwe |
79 | |
6138 | 80 function st = strcat (varargin) |
920 | 81 |
7504
ddcf233d765b
detect cellstr args in strcat
John W. Eaton <jwe@octave.org>
parents:
7411
diff
changeset
|
82 if (nargin > 0) |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
83 if (nargin == 1) |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
84 st = varargin{1}; |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
85 elseif (nargin > 1) |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
86 ## Convert to cells of strings |
11191
01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
87 uo = "uniformoutput"; |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
88 reals = cellfun ("isreal", varargin); |
10032 | 89 if (any (reals)) |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
90 varargin(reals) = cellfun ("char", varargin(reals), uo, false); |
10032 | 91 endif |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
92 chars = cellfun ("isclass", varargin, "char"); |
10032 | 93 allchar = all (chars); |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
94 varargin(chars) = cellfun ("cellstr", varargin(chars), uo, false); |
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
95 if (! all (cellfun ("isclass", varargin, "cell"))) |
10032 | 96 error ("strcat: inputs must be strings or cells of strings"); |
97 endif | |
7504
ddcf233d765b
detect cellstr args in strcat
John W. Eaton <jwe@octave.org>
parents:
7411
diff
changeset
|
98 |
10037
e60f038146e1
further simplify strcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10032
diff
changeset
|
99 ## We don't actually need to bring all cells to common size, because |
e60f038146e1
further simplify strcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10032
diff
changeset
|
100 ## cellfun can now expand scalar cells. |
e60f038146e1
further simplify strcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10032
diff
changeset
|
101 err = common_size (varargin{:}); |
10032 | 102 |
103 if (err) | |
104 error ("strcat: arguments must be the same size, or be scalars"); | |
105 endif | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
106 |
10037
e60f038146e1
further simplify strcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10032
diff
changeset
|
107 ## Cellfun handles everything for us. |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
108 st = cellfun ("horzcat", varargin{:}, uo, false); |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
109 |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
110 if (allchar) |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
111 ## If all inputs were strings, return strings. |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
112 st = char (st); |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
113 endif |
7504
ddcf233d765b
detect cellstr args in strcat
John W. Eaton <jwe@octave.org>
parents:
7411
diff
changeset
|
114 endif |
ddcf233d765b
detect cellstr args in strcat
John W. Eaton <jwe@octave.org>
parents:
7411
diff
changeset
|
115 else |
6046 | 116 print_usage (); |
920 | 117 endif |
118 | |
7504
ddcf233d765b
detect cellstr args in strcat
John W. Eaton <jwe@octave.org>
parents:
7411
diff
changeset
|
119 endfunction |
920 | 120 |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
121 |
6138 | 122 ## test the dimensionality |
123 ## 1d | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
124 %!assert (strcat ("ab ", "ab "), "abab") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
125 %!assert (strcat ({"ab "}, "ab "), {"ab ab"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
126 %!assert (strcat ("ab ", {"ab "}), {"abab "}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
127 %!assert (strcat ({"ab "}, {"ab "}), {"ab ab "}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
128 %!assert (strcat ("", "ab"), "ab") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
129 %!assert (strcat ("", {"ab"}, {""}), {"ab"}) |
6138 | 130 ## 2d |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
131 %!assert (strcat (["ab ";"cde"], ["ab ";"cde"]), ["abab ";"cdecde"]) |
7411 | 132 |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
133 ## test for deblanking implied trailing spaces of character input |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
134 %!assert (strcat ("foo", "bar"), "foobar") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
135 %!assert (strcat (["a"; "bb"], ["foo"; "bar"]), ["afoo "; "bbbar"]) |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
136 |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
137 ## test for mixing character and cell inputs |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
138 %!assert (strcat ("a", {"bc", "de"}, "f"), {"abcf", "adef"}) |
7411 | 139 |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
140 ## test for scalar strings with vector strings |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
141 %!assert (strcat (["a"; "b"], "c"), ["ac"; "bc"]) |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
142 |
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7504
diff
changeset
|
143 ## test with cells with strings of differing lengths |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
144 %!assert (all (strcmp (strcat ({"a", "bb"}, "ccc"), {"accc", "bbccc"}))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
145 %!assert (all (strcmp (strcat ("a", {"bb", "ccc"}), {"abb", "accc"}))) |
7411 | 146 |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14821
diff
changeset
|
147 %!assert (strcat (1, 2), strcat (char (1), char (2))) |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14821
diff
changeset
|
148 %!assert (strcat ("", 2), strcat ([], char (2))) |
7411 | 149 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
150 %!error strcat () |
8143
3a4694d67dbb
strcat.m: Compatibility of non-char data
Ben Abbott <bpabbott@mac.com>
parents:
7813
diff
changeset
|
151 |