annotate libinterp/corefcn/strfns.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents c9788d7f6e65
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30390
diff changeset
3 // Copyright (C) 1994-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21547
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
28 #endif
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
29
1355
94697d007075 [project @ 1995-09-05 20:04:15 by jwe]
jwe
parents: 1315
diff changeset
30 #include <cctype>
7528
26d8a92644de try to avoid ctype macro problems
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
31
8463
a74871446af7 Fchar, Fstrvcat: use queue to avoid duplicate calls to all_strings
John W. Eaton <jwe@octave.org>
parents: 8462
diff changeset
32 #include <queue>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5707
diff changeset
33 #include <sstream>
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
34
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
35 #include "dMatrix.h"
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
36 #include "localcharset-wrapper.h"
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
37 #include "uniconv-wrappers.h"
25412
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
38 #include "unistr-wrappers.h"
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
39
5416
9433f94acd29 [project @ 2005-07-18 18:36:29 by jwe]
jwe
parents: 5415
diff changeset
40 #include "Cell.h"
1355
94697d007075 [project @ 1995-09-05 20:04:15 by jwe]
jwe
parents: 1315
diff changeset
41 #include "defun.h"
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
42 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
43 #include "errwarn.h"
2366
c90105b99479 [project @ 1996-10-11 23:22:27 by jwe]
jwe
parents: 2267
diff changeset
44 #include "ov.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
45 #include "ovl.h"
4457
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4358
diff changeset
46 #include "unwind-prot.h"
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
47 #include "utils.h"
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
48
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
49 #include "oct-string.h"
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
50
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30896
diff changeset
51 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29823
diff changeset
52
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
53 DEFUN (char, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
54 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
55 @deftypefn {} {@var{C} =} char (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
56 @deftypefnx {} {@var{C} =} char (@var{A}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
57 @deftypefnx {} {@var{C} =} char (@var{str1}, @var{str2}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
58 @deftypefnx {} {@var{C} =} char (@var{cell_array})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
59 Create a string array from one or more numeric matrices, character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
60 matrices, or cell arrays.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
61
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
62 Arguments are concatenated vertically. The returned values are padded with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
63 blanks as needed to make each row of the string array have the same length.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
64 Empty input strings are significant and will concatenated in the output.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
65
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
66 For numerical input, each element is converted to the corresponding ASCII
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
67 character. A range error results if an input is outside the ASCII range
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
68 (0-255).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
69
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
70 For cell arrays, each element is concatenated separately. Cell arrays
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
71 converted through @code{char} can mostly be converted back with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
72 @code{cellstr}. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
73
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
74 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
75 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
76 char ([97, 98, 99], "", @{"98", "99", 100@}, "str1", ["ha", "lf"])
24439
09c81c841b6f Fix typo in cset 8354b505ad6b (bug #52702).
Rik <rik@octave.org>
parents: 24436
diff changeset
77 @result{} ["abc "
09c81c841b6f Fix typo in cset 8354b505ad6b (bug #52702).
Rik <rik@octave.org>
parents: 24436
diff changeset
78 " "
09c81c841b6f Fix typo in cset 8354b505ad6b (bug #52702).
Rik <rik@octave.org>
parents: 24436
diff changeset
79 "98 "
09c81c841b6f Fix typo in cset 8354b505ad6b (bug #52702).
Rik <rik@octave.org>
parents: 24436
diff changeset
80 "99 "
09c81c841b6f Fix typo in cset 8354b505ad6b (bug #52702).
Rik <rik@octave.org>
parents: 24436
diff changeset
81 "d "
09c81c841b6f Fix typo in cset 8354b505ad6b (bug #52702).
Rik <rik@octave.org>
parents: 24436
diff changeset
82 "str1"
09c81c841b6f Fix typo in cset 8354b505ad6b (bug #52702).
Rik <rik@octave.org>
parents: 24436
diff changeset
83 "half"]
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
84 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
85 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
86 @seealso{strvcat, cellstr}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
87 @end deftypefn */)
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
88 {
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
89 octave_value retval;
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
90
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
91 int nargin = args.length ();
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
92
13135
af36cdb552a6 char: return empty string if called with no arguments
John W. Eaton <jwe@octave.org>
parents: 12900
diff changeset
93 if (nargin == 0)
af36cdb552a6 char: return empty string if called with no arguments
John W. Eaton <jwe@octave.org>
parents: 12900
diff changeset
94 retval = "";
af36cdb552a6 char: return empty string if called with no arguments
John W. Eaton <jwe@octave.org>
parents: 12900
diff changeset
95 else if (nargin == 1)
5281
f3266e7dbb99 [project @ 2005-04-14 19:35:20 by jwe]
jwe
parents: 5280
diff changeset
96 retval = args(0).convert_to_str (true, true,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
97 args(0).is_dq_string () ? '"' : '\'');
13135
af36cdb552a6 char: return empty string if called with no arguments
John W. Eaton <jwe@octave.org>
parents: 12900
diff changeset
98 else
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
99 {
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
100 int n_elts = 0;
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
101
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
102 int max_len = 0;
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
103
8463
a74871446af7 Fchar, Fstrvcat: use queue to avoid duplicate calls to all_strings
John W. Eaton <jwe@octave.org>
parents: 8462
diff changeset
104 std::queue<string_vector> args_as_strings;
a74871446af7 Fchar, Fstrvcat: use queue to avoid duplicate calls to all_strings
John W. Eaton <jwe@octave.org>
parents: 8462
diff changeset
105
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
106 for (int i = 0; i < nargin; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
107 {
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20940
diff changeset
108 string_vector s = args(i).xstring_vector_value ("char: unable to convert some args to strings");
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
109
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
110 if (s.numel () > 0)
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
111 n_elts += s.numel ();
8353
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
112 else
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
113 n_elts += 1;
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
114
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
115 int s_max_len = s.max_length ();
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
116
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
117 if (s_max_len > max_len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
118 max_len = s_max_len;
8463
a74871446af7 Fchar, Fstrvcat: use queue to avoid duplicate calls to all_strings
John W. Eaton <jwe@octave.org>
parents: 8462
diff changeset
119
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
120 args_as_strings.push (s);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
121 }
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
122
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
123 string_vector result (n_elts);
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
124
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
125 int k = 0;
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
126
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
127 for (int i = 0; i < nargin; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
128 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
129 string_vector s = args_as_strings.front ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
130 args_as_strings.pop ();
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
131
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
132 int n = s.numel ();
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
133
8353
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
134 if (n > 0)
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
135 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
136 for (int j = 0; j < n; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
137 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
138 std::string t = s[j];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
139 int t_len = t.length ();
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
140
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
141 if (max_len > t_len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
142 t += std::string (max_len - t_len, ' ');
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
143
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
144 result[k++] = t;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
145 }
8353
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
146 }
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
147 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
148 result[k++] = std::string (max_len, ' ');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
149 }
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
150
5280
25c12c80ccc3 [project @ 2005-04-14 19:19:45 by jwe]
jwe
parents: 4734
diff changeset
151 retval = octave_value (result, '\'');
4358
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
152 }
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
153
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
154 return retval;
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
155 }
83d4452bc522 [project @ 2003-02-23 02:16:53 by jwe]
jwe
parents: 4233
diff changeset
156
8353
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
157 /*
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
158 %!assert (char (), '')
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
159 %!assert (char (100), "d")
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
160 %!assert (char (100,100), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
161 %!assert (char ({100,100}), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
162 %!assert (char ([100,100]), ["dd"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
163 %!assert (char ({100,{100}}), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
164 %!assert (char (100, [], 100), ["d";" ";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
165 %!assert (char ({100, [], 100}), ["d";" ";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
166 %!assert (char ({100,{100, {""}}}), ["d";"d";" "])
24461
0a034d34a686 Modify BIST tests to pass when string_fill_char is not ' '.
Rik <rik@octave.org>
parents: 24441
diff changeset
167 %!assert (char (["a ";"be"], {"c", 100}), ["a ";"be";"c ";"d "])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
168 %!assert (char ("a", "bb", "ccc"), ["a "; "bb "; "ccc"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
169 %!assert (char ([65, 83, 67, 73, 73]), "ASCII")
13140
98d23b0f16e1 maint: move test_string.m tests to source files
John W. Eaton <jwe@octave.org>
parents: 13135
diff changeset
170
98d23b0f16e1 maint: move test_string.m tests to source files
John W. Eaton <jwe@octave.org>
parents: 13135
diff changeset
171 %!test
98d23b0f16e1 maint: move test_string.m tests to source files
John W. Eaton <jwe@octave.org>
parents: 13135
diff changeset
172 %! x = char ("foo", "bar", "foobar");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
173 %! assert (x(1,:), "foo ");
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
174 %! assert (x(2,:), "bar ");
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
175 %! assert (x(3,:), "foobar");
8353
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
176 */
349a555729a9 keep empty strings in char
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7528
diff changeset
177
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
178 DEFUN (strvcat, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
179 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
180 @deftypefn {} {@var{C} =} strvcat (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
181 @deftypefnx {} {@var{C} =} strvcat (@var{A}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
182 @deftypefnx {} {@var{C} =} strvcat (@var{str1}, @var{str2}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
183 @deftypefnx {} {@var{C} =} strvcat (@var{cell_array})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
184 Create a character array from one or more numeric matrices, character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
185 matrices, or cell arrays.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
186
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
187 Arguments are concatenated vertically. The returned values are padded with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
188 blanks as needed to make each row of the string array have the same length.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
189 Unlike @code{char}, empty strings are removed and will not appear in the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
190 output.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
191
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
192 For numerical input, each element is converted to the corresponding ASCII
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
193 character. A range error results if an input is outside the ASCII range
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
194 (0-255).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
195
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
196 For cell arrays, each element is concatenated separately. Cell arrays
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
197 converted through @code{strvcat} can mostly be converted back with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
198 @code{cellstr}. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
199
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
200 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
201 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
202 strvcat ([97, 98, 99], "", @{"98", "99", 100@}, "str1", ["ha", "lf"])
24436
8354b505ad6b doc: Fix inconsistencies with char, strvcat, strread docstrings (bug #52702.
Rik <rik@octave.org>
parents: 23731
diff changeset
203 @result{} ["abc "
8354b505ad6b doc: Fix inconsistencies with char, strvcat, strread docstrings (bug #52702.
Rik <rik@octave.org>
parents: 23731
diff changeset
204 "98 "
8354b505ad6b doc: Fix inconsistencies with char, strvcat, strread docstrings (bug #52702.
Rik <rik@octave.org>
parents: 23731
diff changeset
205 "99 "
8354b505ad6b doc: Fix inconsistencies with char, strvcat, strread docstrings (bug #52702.
Rik <rik@octave.org>
parents: 23731
diff changeset
206 "d "
8354b505ad6b doc: Fix inconsistencies with char, strvcat, strread docstrings (bug #52702.
Rik <rik@octave.org>
parents: 23731
diff changeset
207 "str1"
8354b505ad6b doc: Fix inconsistencies with char, strvcat, strread docstrings (bug #52702.
Rik <rik@octave.org>
parents: 23731
diff changeset
208 "half"]
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
209 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
210 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
211 @seealso{char, strcat, cstrcat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
212 @end deftypefn */)
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
213 {
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
214 int nargin = args.length ();
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
215 int n_elts = 0;
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
216 std::size_t max_len = 0;
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
217 std::queue<string_vector> args_as_strings;
8463
a74871446af7 Fchar, Fstrvcat: use queue to avoid duplicate calls to all_strings
John W. Eaton <jwe@octave.org>
parents: 8462
diff changeset
218
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
219 for (int i = 0; i < nargin; i++)
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
220 {
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20940
diff changeset
221 string_vector s = args(i).xstring_vector_value ("strvcat: unable to convert some args to strings");
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
222
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
223 std::size_t n = s.numel ();
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
224
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
225 // do not count empty strings in calculation of number of elements
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
226 if (n > 0)
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
227 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
228 for (std::size_t j = 0; j < n; j++)
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
229 {
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23732
diff changeset
230 if (! s[j].empty ())
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
231 n_elts++;
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
232 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
233 }
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
234
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
235 std::size_t s_max_len = s.max_length ();
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
236
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
237 if (s_max_len > max_len)
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
238 max_len = s_max_len;
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
239
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
240 args_as_strings.push (s);
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
241 }
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
242
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
243 string_vector result (n_elts);
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
244
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
245 octave_idx_type k = 0;
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
246
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
247 for (int i = 0; i < nargin; i++)
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
248 {
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
249 string_vector s = args_as_strings.front ();
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
250 args_as_strings.pop ();
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
251
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
252 std::size_t n = s.numel ();
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
253
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
254 if (n > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
255 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
256 for (std::size_t j = 0; j < n; j++)
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
257 {
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
258 std::string t = s[j];
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
259 if (t.length () > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
260 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
261 std::size_t t_len = t.length ();
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
262
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
263 if (max_len > t_len)
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
264 t += std::string (max_len - t_len, ' ');
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
265
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
266 result[k++] = t;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
267 }
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
268 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10234
diff changeset
269 }
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
270 }
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
271
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21100
diff changeset
272 // Cannot use ovl. Relies on overloaded octave_value call.
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21017
diff changeset
273 return octave_value (result, '\'');
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
274 }
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
275
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
276 /*
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
277 %!assert (strvcat (""), "")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
278 %!assert (strvcat (100) == "d")
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
279 %!assert (strvcat (100,100), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
280 %!assert (strvcat ({100,100}), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
281 %!assert (strvcat ([100,100]), ["dd"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
282 %!assert (strvcat ({100,{100}}), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
283 %!assert (strvcat (100, [], 100), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
284 %!assert (strvcat ({100, [], 100}), ["d";"d"])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
285 %!assert (strvcat ({100,{100, {""}}}), ["d";"d"])
24461
0a034d34a686 Modify BIST tests to pass when string_fill_char is not ' '.
Rik <rik@octave.org>
parents: 24441
diff changeset
286 %!assert (strvcat (["a ";"be"], {"c", 100}), ["a ";"be";"c ";"d "])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
287 %!assert (strvcat ("a", "bb", "ccc"), ["a "; "bb "; "ccc"])
20166
196871335aa8 Allow call with empty argument list in strcat related functions (bug #44981)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
288 %!assert (strvcat (), "")
8462
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
289 */
ebdf1e058d85 Make strvcat an internal function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8461
diff changeset
290
4535
a5f23212a3d8 [project @ 2003-10-16 02:39:15 by jwe]
jwe
parents: 4457
diff changeset
291 DEFUN (ischar, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
292 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30391
diff changeset
293 @deftypefn {} {@var{tf} =} ischar (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
294 Return true if @var{x} is a character array.
24474
0b65949870e3 isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents: 24461
diff changeset
295 @seealso{isfloat, isinteger, islogical, isnumeric, isstring, iscellstr, isa}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
296 @end deftypefn */)
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
297 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
298 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5765
diff changeset
299 print_usage ();
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
300
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
301 return ovl (args(0).is_string ());
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
302 }
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
303
8461
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
304 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
305 %!assert (ischar ("a"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
306 %!assert (ischar (["ab";"cd"]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
307 %!assert (ischar ({"ab"}), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
308 %!assert (ischar (1), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
309 %!assert (ischar ([1, 2]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
310 %!assert (ischar ([]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
311 %!assert (ischar ([1, 2; 3, 4]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
312 %!assert (ischar (""), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
313 %!assert (ischar ("test"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
314 %!assert (ischar (["test"; "ing"]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
315 %!assert (ischar (struct ("foo", "bar")), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
316
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
317 %!error ischar ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
318 %!error ischar ("test", 1)
13140
98d23b0f16e1 maint: move test_string.m tests to source files
John W. Eaton <jwe@octave.org>
parents: 13135
diff changeset
319 */
8461
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
320
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
321 static octave_value
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
322 do_strcmp_fcn (const octave_value& arg0, const octave_value& arg1,
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
323 octave_idx_type n, const char *fcn_name,
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
324 bool (*array_op) (const Array<char>&, const Array<char>&,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
325 octave_idx_type),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
326 bool (*str_op) (const std::string&, const std::string&,
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
327 std::string::size_type))
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
328
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
329 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
330 octave_value retval;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
331
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
332 bool s1_string = arg0.is_string ();
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
333 bool s1_cell = arg0.iscell ();
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
334 bool s2_string = arg1.is_string ();
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
335 bool s2_cell = arg1.iscell ();
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
336
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
337 if (s1_string && s2_string)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
338 retval = array_op (arg0.char_array_value (), arg1.char_array_value (), n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
339 else if ((s1_string && s2_cell) || (s1_cell && s2_string))
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
340 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
341 octave_value str_val, cell_val;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
342
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
343 if (s1_string)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
344 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
345 str_val = arg0;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
346 cell_val = arg1;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
347 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
348 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
349 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
350 str_val = arg1;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
351 cell_val = arg0;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
352 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
353
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
354 const Cell cell = cell_val.cell_value ();
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20940
diff changeset
355 const string_vector str = str_val.string_vector_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
356 octave_idx_type r = str.numel ();
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
357
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
358 if (r == 0 || r == 1)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
359 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
360 // Broadcast the string.
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
361
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
362 boolNDArray output (cell_val.dims (), false);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
363
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23396
diff changeset
364 std::string s = (r == 0 ? "" : str[0]);
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
365
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23457
diff changeset
366 if (cell_val.iscellstr ())
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
367 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
368 const Array<std::string> cellstr = cell_val.cellstr_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
369 for (octave_idx_type i = 0; i < cellstr.numel (); i++)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
370 output(i) = str_op (cellstr(i), s, n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
371 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
372 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
373 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
374 // FIXME: should we warn here?
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
375 for (octave_idx_type i = 0; i < cell.numel (); i++)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
376 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
377 if (cell(i).is_string ())
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
378 output(i) = str_op (cell(i).string_value (), s, n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
379 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
380 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
381
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
382 retval = output;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
383 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
384 else if (r > 1)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
385 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
386 if (cell.numel () == 1)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
387 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
388 // Broadcast the cell.
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
389
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
390 const dim_vector dv (r, 1);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
391 boolNDArray output (dv, false);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
392
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
393 if (cell(0).is_string ())
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
394 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
395 const std::string str2 = cell(0).string_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
396
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
397 for (octave_idx_type i = 0; i < r; i++)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
398 output(i) = str_op (str[i], str2, n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
399 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
400
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
401 retval = output;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
402 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
403 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
404 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
405 // Must match in all dimensions.
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
406
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
407 boolNDArray output (cell.dims (), false);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
408
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
409 if (cell.numel () == r)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
410 {
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23457
diff changeset
411 if (cell_val.iscellstr ())
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
412 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
413 const Array<std::string> cellstr
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
414 = cell_val.cellstr_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
415 for (octave_idx_type i = 0; i < cellstr.numel (); i++)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
416 output(i) = str_op (str[i], cellstr(i), n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
417 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
418 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
419 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
420 // FIXME: should we warn here?
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
421 for (octave_idx_type i = 0; i < r; i++)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
422 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
423 if (cell(i).is_string ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
424 output(i) = str_op (str[i],
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
425 cell(i).string_value (), n);
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
426 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
427 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
428
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
429 retval = output;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
430 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
431 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
432 retval = false;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
433 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
434 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
435 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
436 else if (s1_cell && s2_cell)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
437 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
438 octave_value cell1_val, cell2_val;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
439 octave_idx_type r1 = arg0.numel (), r2;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
440
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
441 if (r1 == 1)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
442 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
443 // Make the singleton cell2.
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
444
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
445 cell1_val = arg1;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
446 cell2_val = arg0;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
447 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
448 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
449 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
450 cell1_val = arg0;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
451 cell2_val = arg1;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
452 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
453
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
454 const Cell cell1 = cell1_val.cell_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
455 const Cell cell2 = cell2_val.cell_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
456 r1 = cell1.numel ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
457 r2 = cell2.numel ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
458
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
459 const dim_vector size1 = cell1.dims ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
460 const dim_vector size2 = cell2.dims ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
461
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
462 boolNDArray output (size1, false);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
463
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
464 if (r2 == 1)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
465 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
466 // Broadcast cell2.
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
467
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
468 if (cell2(0).is_string ())
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
469 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
470 const std::string str2 = cell2(0).string_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
471
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23457
diff changeset
472 if (cell1_val.iscellstr ())
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
473 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
474 const Array<std::string> cellstr = cell1_val.cellstr_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20193
diff changeset
475 for (octave_idx_type i = 0; i < cellstr.numel (); i++)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
476 output(i) = str_op (cellstr(i), str2, n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
477 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
478 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
479 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
480 // FIXME: should we warn here?
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
481 for (octave_idx_type i = 0; i < r1; i++)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
482 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
483 if (cell1(i).is_string ())
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
484 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
485 const std::string str1 = cell1(i).string_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
486 output(i) = str_op (str1, str2, n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
487 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
488 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
489 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
490 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
491 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
492 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
493 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
494 if (size1 != size2)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20804
diff changeset
495 error ("%s: nonconformant cell arrays", fcn_name);
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
496
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23457
diff changeset
497 if (cell1.iscellstr () && cell2.iscellstr ())
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
498 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
499 const Array<std::string> cellstr1 = cell1_val.cellstr_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
500 const Array<std::string> cellstr2 = cell2_val.cellstr_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
501 for (octave_idx_type i = 0; i < r1; i++)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
502 output (i) = str_op (cellstr1(i), cellstr2(i), n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
503 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
504 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
505 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
506 // FIXME: should we warn here?
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
507 for (octave_idx_type i = 0; i < r1; i++)
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
508 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
509 if (cell1(i).is_string () && cell2(i).is_string ())
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
510 {
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
511 const std::string str1 = cell1(i).string_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
512 const std::string str2 = cell2(i).string_value ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
513 output(i) = str_op (str1, str2, n);
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
514 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
515 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
516 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
517 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
518
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
519 retval = output;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
520 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
521 else
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
522 retval = false;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
523
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
524 return retval;
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
525 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
526
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
527
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
528 // These are required so that they match the same signature as strncmp
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
529 // and strncmpi and can therefore be used in do_strcmp_fcn.
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
530
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
531 template <typename T, typename T_size_type>
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
532 static bool
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
533 strcmp_ignore_n (const T& s1, const T& s2, T_size_type)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
534 { return string::strcmp (s1, s2); }
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
535
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
536 template <typename T, typename T_size_type>
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
537 static bool
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
538 strcmpi_ignore_n (const T& s1, const T& s2, T_size_type)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
539 { return string::strcmpi (s1, s2); }
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
540
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
541
5415
1fbae9f046e3 [project @ 2005-07-18 18:16:12 by jwe]
jwe
parents: 5307
diff changeset
542 DEFUN (strcmp, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
543 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
544 @deftypefn {} {@var{tf} =} strcmp (@var{str1}, @var{str2})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
545 Return 1 if the character strings @var{str1} and @var{str2} are the same,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
546 and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
547
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
548 If either @var{str1} or @var{str2} is a cell array of strings, then an array
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
549 of the same size is returned, containing the values described above for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
550 every member of the cell array. The other argument may also be a cell
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
551 array of strings (of the same size or with only one element), char matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
552 or character string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
553
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
554 @strong{Caution:} For compatibility with @sc{matlab}, Octave's strcmp
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
555 function returns 1 if the character strings are equal, and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
556 This is just the opposite of the corresponding C library function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
557 @seealso{strcmpi, strncmp, strncmpi}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
558 @end deftypefn */)
5415
1fbae9f046e3 [project @ 2005-07-18 18:16:12 by jwe]
jwe
parents: 5307
diff changeset
559 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
560 if (args.length () != 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5765
diff changeset
561 print_usage ();
5415
1fbae9f046e3 [project @ 2005-07-18 18:16:12 by jwe]
jwe
parents: 5307
diff changeset
562
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
563 return ovl (do_strcmp_fcn (args(0), args(1), 0, "strcmp",
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
564 strcmp_ignore_n, strcmp_ignore_n));
5415
1fbae9f046e3 [project @ 2005-07-18 18:16:12 by jwe]
jwe
parents: 5307
diff changeset
565 }
1fbae9f046e3 [project @ 2005-07-18 18:16:12 by jwe]
jwe
parents: 5307
diff changeset
566
5862
2b35a7fe9302 [project @ 2006-06-20 04:31:56 by jwe]
jwe
parents: 5823
diff changeset
567 /*
2b35a7fe9302 [project @ 2006-06-20 04:31:56 by jwe]
jwe
parents: 5823
diff changeset
568 %!shared x
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
569 %! x = char (zeros (0, 2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
570 %!assert (strcmp ("", x), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
571 %!assert (strcmp (x, ""), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
572 %!assert (strcmp (x, x), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
573 ## %!assert (strcmp ({""}, x), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
574 ## %!assert (strcmp ({x}, ""), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
575 ## %!assert (strcmp ({x}, x), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
576 ## %!assert (strcmp ("", {x}), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
577 ## %!assert (strcmp (x, {""}), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
578 ## %!assert (strcmp (x, {x}), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
579 ## %!assert (strcmp ({x; x}, ""), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
580 ## %!assert (strcmp ({x; x}, {""}), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
581 ## %!assert (strcmp ("", {x; x}), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
582 ## %!assert (strcmp ({""}, {x; x}), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
583 %!assert (strcmp ({"foo"}, x), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
584 %!assert (strcmp ({"foo"}, "foo"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
585 %!assert (strcmp ({"foo"}, x), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
586 %!assert (strcmp (x, {"foo"}), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
587 %!assert (strcmp ("foo", {"foo"}), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
588 %!assert (strcmp (x, {"foo"}), false)
5862
2b35a7fe9302 [project @ 2006-06-20 04:31:56 by jwe]
jwe
parents: 5823
diff changeset
589 %!shared y
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
590 %! y = char (zeros (2, 0));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
591 %!assert (strcmp ("", y), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
592 %!assert (strcmp (y, ""), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
593 %!assert (strcmp (y, y), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
594 %!assert (strcmp ({""}, y), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
595 %!assert (strcmp ({y}, ""), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
596 %!assert (strcmp ({y}, y), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
597 %!assert (strcmp ("", {y}), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
598 %!assert (strcmp (y, {""}), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
599 %!assert (strcmp (y, {y}), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
600 %!assert (strcmp ({y; y}, ""), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
601 %!assert (strcmp ({y; y}, {""}), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
602 %!assert (strcmp ("", {y; y}), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
603 %!assert (strcmp ({""}, {y; y}), [true; true])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
604 %!assert (strcmp ({"foo"}, y), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
605 %!assert (strcmp ({"foo"}, y), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
606 %!assert (strcmp (y, {"foo"}), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
607 %!assert (strcmp (y, {"foo"}), [false; false])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
608 %!assert (strcmp ("foobar", "foobar"), true)
23731
0056bcaeb01c make strncmp case sensitive again (bug #51384)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
609 %!assert (strcmp ("foobar", "fooBar"), false)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
610 %!assert (strcmp ("fooba", "foobar"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
611
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
612 %!error strcmp ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
613 %!error strcmp ("foo", "bar", 3)
5862
2b35a7fe9302 [project @ 2006-06-20 04:31:56 by jwe]
jwe
parents: 5823
diff changeset
614 */
2b35a7fe9302 [project @ 2006-06-20 04:31:56 by jwe]
jwe
parents: 5823
diff changeset
615
6250
ff5e6cf72bda [project @ 2007-01-23 18:37:52 by jwe]
jwe
parents: 5911
diff changeset
616 DEFUN (strncmp, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
617 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
618 @deftypefn {} {@var{tf} =} strncmp (@var{str1}, @var{str2}, @var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
619 Return 1 if the first @var{n} characters of strings @var{str1} and @var{str2}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
620 are the same, and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
621
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
622 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
623 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
624 strncmp ("abce", "abcd", 3)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
625 @result{} 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
626 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
627 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
628
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
629 If either @var{str1} or @var{str2} is a cell array of strings, then an array
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
630 of the same size is returned, containing the values described above for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
631 every member of the cell array. The other argument may also be a cell
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
632 array of strings (of the same size or with only one element), char matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
633 or character string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
634
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
635 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
636 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
637 strncmp ("abce", @{"abcd", "bca", "abc"@}, 3)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
638 @result{} [1, 0, 1]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
639 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
640 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
641
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
642 @strong{Caution:} For compatibility with @sc{matlab}, Octave's strncmp
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
643 function returns 1 if the character strings are equal, and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
644 This is just the opposite of the corresponding C library function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
645 @seealso{strncmpi, strcmp, strcmpi}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
646 @end deftypefn */)
6250
ff5e6cf72bda [project @ 2007-01-23 18:37:52 by jwe]
jwe
parents: 5911
diff changeset
647 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
648 if (args.length () != 3)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
649 print_usage ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
650
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
651 octave_idx_type n = args(2).idx_type_value ();
6250
ff5e6cf72bda [project @ 2007-01-23 18:37:52 by jwe]
jwe
parents: 5911
diff changeset
652
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
653 if (n > 0)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
654 return ovl (do_strcmp_fcn (args(0), args(1), n, "strncmp",
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
655 string::strncmp,
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
656 string::strncmp));
6250
ff5e6cf72bda [project @ 2007-01-23 18:37:52 by jwe]
jwe
parents: 5911
diff changeset
657 else
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
658 error ("strncmp: N must be greater than 0");
6250
ff5e6cf72bda [project @ 2007-01-23 18:37:52 by jwe]
jwe
parents: 5911
diff changeset
659 }
ff5e6cf72bda [project @ 2007-01-23 18:37:52 by jwe]
jwe
parents: 5911
diff changeset
660
8461
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
661 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
662 %!assert (strncmp ("abce", "abc", 3), true)
23731
0056bcaeb01c make strncmp case sensitive again (bug #51384)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
663 %!assert (strncmp ("abce", "aBc", 3), false)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
664 %!assert (strncmp (100, 100, 1), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
665 %!assert (strncmp ("abce", {"abcd", "bca", "abc"}, 3), logical ([1, 0, 1]))
25698
ac386820f2b6 Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents: 25692
diff changeset
666 %!assert (strncmp ("abc", {"abcd", "bca", "abc"}, 4), logical ([0, 0, 1]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
667 %!assert (strncmp ({"abcd", "bca", "abc"},"abce", 3), logical ([1, 0, 1]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
668 %!assert (strncmp ({"abcd", "bca", "abc"},{"abcd", "bca", "abe"}, 3),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
669 %! logical ([1, 1, 0]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
670 %!assert (strncmp ("abc", {"abcd", 10}, 2), logical ([1, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
671
25698
ac386820f2b6 Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents: 25692
diff changeset
672 %!assert <*54373> (strncmp ("abc", "abc", 100))
ac386820f2b6 Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents: 25692
diff changeset
673
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
674 %!error strncmp ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
675 %!error strncmp ("abc", "def")
8461
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
676 */
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
677
10316
9966f1f71c32 use DEFUNX instead of DEFUN for strcmpi and strncmpi
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
678 DEFUNX ("strcmpi", Fstrcmpi, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
679 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
680 @deftypefn {} {@var{tf} =} strcmpi (@var{str1}, @var{str2})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
681 Return 1 if the character strings @var{str1} and @var{str2} are the same,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
682 disregarding case of alphabetic characters, and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
683
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
684 If either @var{str1} or @var{str2} is a cell array of strings, then an array
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
685 of the same size is returned, containing the values described above for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
686 every member of the cell array. The other argument may also be a cell
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
687 array of strings (of the same size or with only one element), char matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
688 or character string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
689
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
690 @strong{Caution:} For compatibility with @sc{matlab}, Octave's strcmp
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
691 function returns 1 if the character strings are equal, and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
692 This is just the opposite of the corresponding C library function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
693
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
694 @strong{Caution:} National alphabets are not supported.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
695 @seealso{strcmp, strncmp, strncmpi}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
696 @end deftypefn */)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
697 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
698 if (args.length () != 2)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
699 print_usage ();
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
700
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
701 return ovl (do_strcmp_fcn (args(0), args(1), 0, "strcmpi",
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
702 strcmpi_ignore_n, strcmpi_ignore_n));
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
703 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
704
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
705 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
706 %!assert (strcmpi ("abc123", "ABC123"), true)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
707 */
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
708
10318
f0ac2fa91733 fix incorrect strncmpi change
John W. Eaton <jwe@octave.org>
parents: 10316
diff changeset
709 DEFUNX ("strncmpi", Fstrncmpi, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
710 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
711 @deftypefn {} {@var{tf} =} strncmpi (@var{str1}, @var{str2}, @var{n})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
712 Return 1 if the first @var{n} character of @var{s1} and @var{s2} are the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
713 same, disregarding case of alphabetic characters, and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
714
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
715 If either @var{str1} or @var{str2} is a cell array of strings, then an array
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
716 of the same size is returned, containing the values described above for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
717 every member of the cell array. The other argument may also be a cell
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
718 array of strings (of the same size or with only one element), char matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
719 or character string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
720
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
721 @strong{Caution:} For compatibility with @sc{matlab}, Octave's strncmpi
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
722 function returns 1 if the character strings are equal, and 0 otherwise.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
723 This is just the opposite of the corresponding C library function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
724
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
725 @strong{Caution:} National alphabets are not supported.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
726 @seealso{strncmp, strcmp, strcmpi}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
727 @end deftypefn */)
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
728 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
729 if (args.length () != 3)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
730 print_usage ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
731
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
732 octave_idx_type n = args(2).idx_type_value ();
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
733
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
734 if (n > 0)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
735 return ovl (do_strcmp_fcn (args(0), args(1), n, "strncmpi",
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
736 string::strncmpi,
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
737 string::strncmpi));
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
738 else
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
739 error ("strncmpi: N must be greater than 0");
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
740 }
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
741
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
742 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
743 %!assert (strncmpi ("abc123", "ABC456", 3), true)
25698
ac386820f2b6 Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents: 25692
diff changeset
744
ac386820f2b6 Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents: 25692
diff changeset
745 %!assert <*54373> (strncmpi ("abc", "abC", 100))
10108
06e11df4592d implement built-in strcmpi/strncmpi, reduce some code duplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
746 */
8461
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
747
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
748 DEFUN (str2double, args, ,
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
749 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
750 @deftypefn {} {@var{d} =} str2double (@var{str})
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
751 Convert a string to a real or complex number.
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
752
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
753 The string must be in one of the following formats where a and b are real
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
754 numbers and the complex unit is @qcode{'i'} or @qcode{'j'}:
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
755
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
756 @itemize
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
757 @item a + bi
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
758
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
759 @item a + b*i
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
760
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
761 @item a + i*b
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
762
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
763 @item bi + a
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
764
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
765 @item b*i + a
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
766
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
767 @item i*b + a
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
768 @end itemize
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
769
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
770 If present, a and/or b are of the form @nospell{[+-]d[,.]d[[eE][+-]d]} where
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
771 the brackets indicate optional arguments and @qcode{'d'} indicates zero or
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
772 more digits. The special input values @code{Inf}, @code{NaN}, and @code{NA}
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
773 are also accepted.
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
774
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
775 @var{str} may be a character string, character matrix, or cell array. For
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
776 character arrays the conversion is repeated for every row, and a double or
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
777 complex array is returned. Empty rows in @var{s} are deleted and not
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
778 returned in the numeric array. For cell arrays each character string
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
779 element is processed and a double or complex array of the same dimensions as
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
780 @var{str} is returned.
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
781
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
782 For unconvertible scalar or character string input @code{str2double} returns
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
783 a NaN@. Similarly, for character array input @code{str2double} returns a
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
784 NaN for any row of @var{s} that could not be converted. For a cell array,
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
785 @code{str2double} returns a NaN for any element of @var{s} for which
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
786 conversion fails. Note that numeric elements in a mixed string/numeric
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
787 cell array are not strings and the conversion will fail for these elements
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
788 and return NaN.
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
789
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
790 Programming Note: @code{str2double} can replace @code{str2num}, is more
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
791 efficient, and avoids the security risk of using @code{eval} on unknown data.
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
792 @seealso{str2num}
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
793 @end deftypefn */)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
794 {
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
795 if (args.length () != 1)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
796 print_usage ();
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
797
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
798 octave_value retval;
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
799
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
800 if (args(0).is_string ())
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
801 {
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
802 if (args(0).rows () == 0 || args(0).columns () == 0)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
803 retval = Matrix (1, 1, numeric_limits<double>::NaN ());
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
804 else if (args(0).rows () == 1 && args(0).ndims () == 2)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
805 retval = string::str2double (args(0).string_value ());
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
806 else
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
807 {
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
808 const string_vector sv = args(0).string_vector_value ();
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
809
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
810 retval = sv.map<Complex> (string::str2double);
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
811 }
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
812 }
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
813 else if (args(0).iscell ())
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
814 {
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
815 const Cell cell = args(0).cell_value ();
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
816
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
817 ComplexNDArray output (cell.dims (), numeric_limits<double>::NaN ());
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
818
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
819 for (octave_idx_type i = 0; i < cell.numel (); i++)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
820 {
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
821 if (cell(i).is_string ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
822 output(i) = string::str2double (cell(i).string_value ());
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
823 }
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
824 retval = output;
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
825 }
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
826 else
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
827 retval = Matrix (1, 1, numeric_limits<double>::NaN ());
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
828
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
829 return retval;
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
830 }
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
831
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
832 /*
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
833 %!assert (str2double ("1"), 1)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
834 %!assert (str2double ("-.1e-5"), -1e-6)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
835 %!testif ; ! ismac ()
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
836 %! assert (str2double (char ("1", "2 3", "4i")), [1; NaN; 4i]);
29494
76269aa97398 if bug number is supplied, prefer '%!test' over '%!xtest'
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
837 %!test <47413>
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
838 %! ## Same test code as above, but intended only for test statistics on Mac.
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
839 %! if (! ismac ()), return; endif
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
840 %! assert (str2double (char ("1", "2 3", "4i")), [1; NaN; 4i]);
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
841 %!assert (str2double ("1,222.5"), 1222.5)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
842 %!assert (str2double ("i"), i)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
843 %!assert (str2double ("2j"), 2i)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
844 %!assert (str2double ("2 + j"), 2+j)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
845 %!assert (str2double ("i*2 + 3"), 3+2i)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
846 %!assert (str2double (".5*i + 3.5"), 3.5+0.5i)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
847 %!assert (str2double ("1e-3 + i*.25"), 1e-3 + 0.25i)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
848 %!assert (str2double (char ("2 + j","1.25e-3","-05")), [2+i; 1.25e-3; -5])
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
849 %!assert (str2double ({"2 + j","1.25e-3","-05"}), [2+i, 1.25e-3, -5])
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
850 %!assert (str2double (1), NaN)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
851 %!assert (str2double ("1 2 3 4"), NaN)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
852 %!assert (str2double ("Hello World"), NaN)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
853 %!assert (str2double ("NaN"), NaN)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
854 %!assert (str2double ("NA"), NA)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
855 %!assert (str2double ("Inf"), Inf)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
856 %!assert (str2double ("iNF"), Inf)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
857 %!assert (str2double ("-Inf"), -Inf)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
858 %!assert (str2double ("Inf*i"), complex (0, Inf))
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
859 %!assert (str2double ("iNF*i"), complex (0, Inf))
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
860 %!assert (str2double ("NaN + Inf*i"), complex (NaN, Inf))
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
861 %!assert (str2double ("Inf - Inf*i"), complex (Inf, -Inf))
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
862 %!assert (str2double ("-i*NaN - Inf"), complex (-Inf, -NaN))
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
863 %!testif ; ! ismac ()
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
864 %! assert (str2double ({"abc", "4i"}), [NaN + 0i, 4i]);
29494
76269aa97398 if bug number is supplied, prefer '%!test' over '%!xtest'
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
865 %!test <47413>
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
866 %! if (! ismac ()), return; endif
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
867 %! assert (str2double ({"abc", "4i"}), [NaN + 0i, 4i]);
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
868 %!testif ; ! ismac ()
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
869 %! assert (str2double ({2, "4i"}), [NaN + 0i, 4i])
29494
76269aa97398 if bug number is supplied, prefer '%!test' over '%!xtest'
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
870 %!test <47413>
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
871 %! if (! ismac ()), return; endif
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
872 %! assert (str2double ({2, "4i"}), [NaN + 0i, 4i])
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
873 %!assert (str2double (zeros (3,1,2)), NaN)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
874 %!assert (str2double (''), NaN)
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
875 %!assert (str2double ([]), NaN)
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28914
diff changeset
876 %!assert (str2double (char (zeros (3,0))), NaN)
26110
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
877 */
b543cf12c63f Move octave_str2double to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25698
diff changeset
878
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
879 DEFUN (__native2unicode__, args, ,
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
880 doc: /* -*- texinfo -*-
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
881 @deftypefn {} {@var{utf8_str} =} __native2unicode__ (@var{native_bytes}, @var{codepage})
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
882 Convert byte stream @var{native_bytes} to UTF-8 using @var{codepage}.
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
883
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
884 @seealso{native2unicode, __unicode2native__}
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
885 @end deftypefn */)
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
886 {
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
887 if (args(0).is_string ())
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
888 return ovl (args(0));
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
889
27366
4fef3ab19046 Remove input checks from internal unicode2native, native2unicode functions (bug #56805).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27265
diff changeset
890 std::string tmp = args(1).string_value ();
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
891 const char *codepage
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23396
diff changeset
892 = (tmp.empty () ? octave_locale_charset_wrapper () : tmp.c_str ());
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
893
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
894 charNDArray native_bytes = args(0).char_array_value ();
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
895
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
896 const char *src = native_bytes.data ();
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
897 std::size_t srclen = native_bytes.numel ();
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
898
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
899 std::size_t length;
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
900 uint8_t *utf8_str = nullptr;
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
901
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
902 utf8_str = octave_u8_conv_from_encoding (codepage, src, srclen, &length);
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
903
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
904 if (! utf8_str)
25691
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
905 {
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
906 if (errno == ENOSYS)
29578
b20fb3769277 Code cleanup in strfns.cc.
Rik <rik@octave.org>
parents: 29572
diff changeset
907 error ("native2unicode: iconv() is not supported. Installing GNU "
25691
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
908 "libiconv and then re-compiling Octave could fix this.");
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
909 else
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
910 error ("native2unicode: converting from codepage '%s' to UTF-8: %s",
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
911 codepage, std::strerror (errno));
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
912 }
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
913
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
914 unwind_action free_utf8_str ([=] () { ::free (utf8_str); });
24379
56d1e4d9975e avoid memory leak in utf8 conversion functions
John W. Eaton <jwe@octave.org>
parents: 23812
diff changeset
915
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
916 octave_idx_type len = length;
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
917
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
918 charNDArray retval (dim_vector (1, len));
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
919
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
920 for (octave_idx_type i = 0; i < len; i++)
29578
b20fb3769277 Code cleanup in strfns.cc.
Rik <rik@octave.org>
parents: 29572
diff changeset
921 retval.xelem (i) = utf8_str[i];
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
922
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
923 return ovl (retval);
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
924 }
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
925
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
926 DEFUN (__unicode2native__, args, ,
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
927 doc: /* -*- texinfo -*-
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
928 @deftypefn {} {@var{native_bytes} =} __unicode2native__ (@var{utf8_str}, @var{codepage})
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
929 Convert UTF-8 string @var{utf8_str} to byte stream @var{native_bytes} using
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
930 @var{codepage}.
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
931
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
932 @seealso{unicode2native, __native2unicode__}
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
933 @end deftypefn */)
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
934 {
27366
4fef3ab19046 Remove input checks from internal unicode2native, native2unicode functions (bug #56805).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27265
diff changeset
935 std::string tmp = args(1).string_value ();
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
936 const char *codepage
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23396
diff changeset
937 = (tmp.empty () ? octave_locale_charset_wrapper () : tmp.c_str ());
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
938
27366
4fef3ab19046 Remove input checks from internal unicode2native, native2unicode functions (bug #56805).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27265
diff changeset
939 charNDArray utf8_str = args(0).char_array_value ();
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
940
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
941 const uint8_t *src = reinterpret_cast<const uint8_t *> (utf8_str.data ());
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
942 std::size_t srclen = utf8_str.numel ();
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
943
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
944 std::size_t length;
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
945 char *native_bytes = nullptr;
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
946
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
947 native_bytes = octave_u8_conv_to_encoding (codepage, src, srclen, &length);
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
948
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
949 if (! native_bytes)
25691
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
950 {
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
951 if (errno == ENOSYS)
29578
b20fb3769277 Code cleanup in strfns.cc.
Rik <rik@octave.org>
parents: 29572
diff changeset
952 error ("unicode2native: iconv() is not supported. Installing GNU "
25691
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
953 "libiconv and then re-compiling Octave could fix this.");
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
954 else
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
955 error ("unicode2native: converting from UTF-8 to codepage '%s': %s",
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
956 codepage, std::strerror (errno));
25691
e866bb226d38 Improve error message if iconv is not available (bug #54384).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
957 }
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
958
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
959 unwind_action free_native_bytes ([=] () { ::free (native_bytes); });
24379
56d1e4d9975e avoid memory leak in utf8 conversion functions
John W. Eaton <jwe@octave.org>
parents: 23812
diff changeset
960
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
961 octave_idx_type len = length;
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
962
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
963 uint8NDArray retval (dim_vector (1, len));
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
964
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
965 for (octave_idx_type i = 0; i < len; i++)
29578
b20fb3769277 Code cleanup in strfns.cc.
Rik <rik@octave.org>
parents: 29572
diff changeset
966 retval.xelem (i) = native_bytes[i];
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
967
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
968 return ovl (retval);
23122
e310b5b6da6f Add functions native2unicode and unicode2native (bug #49842).
Markus Mützel <markus.muetzel@gmx.de>
parents: 23084
diff changeset
969 }
23123
c6ca5fe1505c use wrappers for uniconv functions; style fixes for unicode conv fcns
John W. Eaton <jwe@octave.org>
parents: 23122
diff changeset
970
27265
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
971 DEFUN (__locale_charset__, , ,
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
972 doc: /* -*- texinfo -*-
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
973 @deftypefn {} {@var{charset} =} __locale_charset__ ()
27795
afbaad39d25c doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 27785
diff changeset
974 Return the identifier for the charset used if the encoding is set to
afbaad39d25c doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 27785
diff changeset
975 @qcode{"locale"}.
27265
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
976 @end deftypefn */)
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
977 {
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
978 const char *charset = octave_locale_charset_wrapper ();
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
979 std::string charset_str (charset);
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
980 return ovl (charset_str);
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
981 }
5f65319c7835 Add new function for querying the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27141
diff changeset
982
25412
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
983 DEFUN (unicode_idx, args, ,
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
984 doc: /* -*- texinfo -*-
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
985 @deftypefn {} {@var{idx} =} unicode_idx (@var{str})
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
986 Return an array with the indices for each UTF-8 encoded character in @var{str}.
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
987
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
988 @example
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
989 @group
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
990 unicode_idx ("aäbc")
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
991 @result{} [1, 2, 2, 3, 4]
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
992 @end group
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
993 @end example
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
994
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
995 @end deftypefn */)
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
996 {
28946
ef2b0a00daef maint: Don't declare nargin in C++ files if it is used only once.
Rik <rik@octave.org>
parents: 28915
diff changeset
997 if (args.length () != 1)
25412
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
998 print_usage ();
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
999
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1000 charNDArray str = args(0).xchar_array_value ("STR must be a string");
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1001 Array<octave_idx_type> p (dim_vector (str.ndims (), 1));
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1002 charNDArray str_p;
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1003 if (str.ndims () > 1)
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1004 {
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1005 for (octave_idx_type i=0; i < str.ndims (); i++)
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1006 p(i) = i;
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1007 p(0) = 1;
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1008 p(1) = 0;
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1009 str_p = str.permute (p);
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1010 }
25412
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1011
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1012 const uint8_t *src = reinterpret_cast<const uint8_t *> (str_p.data ());
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1013 octave_idx_type srclen = str.numel ();
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1014
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1015 NDArray idx (str_p.dims ());
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1016
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1017 octave_idx_type u8_char_num = 1;
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1018 for (octave_idx_type i = 0; i < srclen; u8_char_num++)
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1019 {
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1020 int mblen = octave_u8_strmblen_wrapper (src + i);
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1021 if (mblen < 1)
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1022 mblen = 1;
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1023 for (octave_idx_type j = 0; j < mblen; j++)
29823
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1024 idx(i+j) = u8_char_num;
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1025 i += mblen;
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1026 }
25436
996d78102a71 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25412
diff changeset
1027
29823
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1028 return ovl (str.ndims () > 1 ? idx.permute (p, true) : idx);
25412
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1029 }
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1030
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1031 /*
28907
11f1207111c5 maint: Don't use semicolon at end of single-line BIST tests.
Rik <rik@octave.org>
parents: 28888
diff changeset
1032 %!assert (unicode_idx (["aäou"; "Ä∞"]), [1 2 2 3 4; 5 5 6 6 6])
25412
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1033 */
922a93fc73ec Add function to index characters in UTF-8 encoded strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
1034
29823
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1035 DEFUN (__unicode_length__, args, ,
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1036 doc: /* -*- texinfo -*-
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1037 @deftypefn {} {@var{len} =} __unicode_length__ (@var{str})
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1038 Return number of Unicode code points in @var{str}.
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1039
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1040 The input @var{str} must be a UTF-8 encoded character vector or cell string.
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1041
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1042 @example
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1043 @group
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1044 length ("aäbc")
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1045 @result{} 5
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1046 __unicode_length__ ("aäbc")
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1047 @result{} 4
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1048 @end group
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1049 @end example
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1050
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1051 @end deftypefn */)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1052 {
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1053 if (args.length () != 1)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1054 print_usage ();
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1055
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1056 bool arg_char = args(0).is_char_matrix ();
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1057
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1058 if (! arg_char && ! args(0).iscellstr ())
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1059 error ("STR must be a character array or cell string.");
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1060
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1061 octave_value_list retval;
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1062
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1063 if (arg_char)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1064 {
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1065 charNDArray str = args(0).char_array_value ();
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1066 Array<octave_idx_type> p (dim_vector (str.ndims (), 1));
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1067 if (str.ndims () > 1)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1068 {
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1069 for (octave_idx_type i=0; i < str.ndims (); i++)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1070 p(i) = i;
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1071 p(0) = 1;
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1072 p(1) = 0;
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1073 str = str.permute (p);
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1074 }
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1075
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1076 const uint8_t *src = reinterpret_cast<const uint8_t *> (str.data ());
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1077 octave_idx_type mbsnlen = octave_u8_mbsnlen_wrapper (src, str.numel ());
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1078
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1079 retval = ovl (mbsnlen);
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1080 }
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1081 else
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1082 {
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1083 const Array<std::string> cellstr = args(0).cellstr_value ();
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1084 NDArray output (args(0).dims (), false);
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1085 for (octave_idx_type i = 0; i < cellstr.numel (); i++)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1086 {
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29961
diff changeset
1087 const uint8_t *src
29823
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1088 = reinterpret_cast<const uint8_t *> (cellstr(i).c_str ());
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1089 output(i) = octave_u8_mbsnlen_wrapper (src, cellstr(i).size ());
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1090 }
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1091
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1092 retval = ovl (output);
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1093 }
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1094
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1095 return retval;
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1096 }
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1097
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1098 /*
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1099 %!assert (__unicode_length__ (""), 0)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1100 %!assert (__unicode_length__ ("aäbc"), 4)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1101 %!assert (__unicode_length__ (["aä"; "öo"]), 4)
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1102 %!assert (__unicode_length__ ({"aäbc", "abc"}), [4, 3])
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1103 */
7917b91a3c58 __unicode_length__: New function to get number of Unicode code points (bug #50855).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29655
diff changeset
1104
27785
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1105 DEFUN (__u8_validate__, args, ,
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1106 doc: /* -*- texinfo -*-
27807
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1107 @deftypefn {} {@var{out_str} =} __u8_validate__ (in_str, mode)
27785
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1108 Return string with valid UTF-8.
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1109
27807
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1110 On encountering invalid UTF-8 in @var{in_str}, the bytes are either replaced by
28753
e82484e1b2f6 doc: grammarcheck documentation.
Rik <rik@octave.org>
parents: 28752
diff changeset
1111 the replacement character @qcode{"�"} (if @var{mode} is omitted or is the
e82484e1b2f6 doc: grammarcheck documentation.
Rik <rik@octave.org>
parents: 28752
diff changeset
1112 string @qcode{"replace"}) or interpreted as the Unicode code points
e82484e1b2f6 doc: grammarcheck documentation.
Rik <rik@octave.org>
parents: 28752
diff changeset
1113 U+0080–U+00FF with the same value as the byte (if @var{mode} is the string
e82484e1b2f6 doc: grammarcheck documentation.
Rik <rik@octave.org>
parents: 28752
diff changeset
1114 @qcode{"unicode"}), thus interpreting the bytes according to ISO-8859-1.
27785
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1115 @end deftypefn */)
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1116 {
28752
810eb29fc227 maint: Use C++ raw string literals to simplify backlsashing.
Rik <rik@octave.org>
parents: 27932
diff changeset
1117 int nargin = args.length ();
810eb29fc227 maint: Use C++ raw string literals to simplify backlsashing.
Rik <rik@octave.org>
parents: 27932
diff changeset
1118
810eb29fc227 maint: Use C++ raw string literals to simplify backlsashing.
Rik <rik@octave.org>
parents: 27932
diff changeset
1119 if (nargin < 1 || nargin > 2)
27785
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1120 print_usage ();
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1121
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1122 // Input check
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1123 std::string in_str =
28752
810eb29fc227 maint: Use C++ raw string literals to simplify backlsashing.
Rik <rik@octave.org>
parents: 27932
diff changeset
1124 args(0).xstring_value ("__u8_validate__: IN_STR must be a string");
27807
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1125
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1126 std::string mode = "replace";
28752
810eb29fc227 maint: Use C++ raw string literals to simplify backlsashing.
Rik <rik@octave.org>
parents: 27932
diff changeset
1127 if (nargin == 2)
810eb29fc227 maint: Use C++ raw string literals to simplify backlsashing.
Rik <rik@octave.org>
parents: 27932
diff changeset
1128 mode = args(1).xstring_value ("__u8_validate__: MODE must be a string");
27785
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1129
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1130 string::u8_fallback_type fb_type;
27807
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1131 if (mode == "replace")
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1132 fb_type = string::U8_REPLACEMENT_CHAR;
27807
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1133 else if (mode == "unicode")
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1134 fb_type = string::U8_ISO_8859_1;
27807
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1135 else
28752
810eb29fc227 maint: Use C++ raw string literals to simplify backlsashing.
Rik <rik@octave.org>
parents: 27932
diff changeset
1136 error (R"(__u8_validate__: MODE must be either "replace" or "unicode")");
27807
1626e50fa8ee Add type switch to "__u8_validate__".
Markus Mützel <markus.muetzel@gmx.de>
parents: 27797
diff changeset
1137
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1138 string::u8_validate ("__u8_validate__", in_str, fb_type);
27785
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1139
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1140 return ovl (in_str);
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1141 }
3f5026fd8da8 Create valid UTF-8 from .m file content (bug #57341).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27366
diff changeset
1142
27141
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1143 DEFUN (newline, args, ,
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1144 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1145 @deftypefn {} {@var{c} =} newline
27141
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1146 Return the character corresponding to a newline.
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1147
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 28946
diff changeset
1148 This is equivalent to @qcode{"@backslashchar{}n"}.
27141
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1149
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1150 Example Code
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1151
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1152 @example
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1153 @group
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1154 joined_string = [newline "line1" newline "line2"]
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1155 @result{}
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1156 line1
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1157 line2
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1158 @end group
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1159 @end example
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1160
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1161 @seealso{strcat, strjoin, strsplit}
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1162 @end deftypefn */)
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1163 {
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1164 if (args.length () != 0)
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1165 print_usage ();
27797
5dcdd5bd46e2 maint: remove trailing spaces from code.
Rik <rik@octave.org>
parents: 27795
diff changeset
1166
27141
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1167 static octave_value_list retval = ovl ("\n");
27797
5dcdd5bd46e2 maint: remove trailing spaces from code.
Rik <rik@octave.org>
parents: 27795
diff changeset
1168
27141
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1169 return retval;
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1170 }
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1171
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1172 /*
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1173 %!assert (newline (), "\n")
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1174
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1175 %!error newline (1)
28913
c11bebb62369 Temporary fix for newline() BIST test until bug #59265 is resolved.
Rik <rik@octave.org>
parents: 28907
diff changeset
1176 ## FIXME: The next error() test requires a semicolon at EOL until
c11bebb62369 Temporary fix for newline() BIST test until bug #59265 is resolved.
Rik <rik@octave.org>
parents: 28907
diff changeset
1177 ## bug #59265 is resolved.
27141
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1178 %!error [a, b] = newline ();
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1179 */
f26b13c80e45 Implement new function "newline" for Matlab compatibility (bug #56419).
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 26376
diff changeset
1180
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5674
diff changeset
1181 DEFUN (list_in_columns, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1182 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1183 @deftypefn {} {@var{str} =} list_in_columns (@var{arg}, @var{width}, @var{prefix})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1184 Return a string containing the elements of @var{arg} listed in columns with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1185 an overall maximum width of @var{width} and optional prefix @var{prefix}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1186
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1187 The argument @var{arg} must be a cell array of character strings or a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1188 character array.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1189
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1190 If @var{width} is not specified or is an empty matrix, or less than or equal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1191 to zero, the width of the terminal screen is used. Newline characters are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1192 used to break the lines in the output string. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1193 @c Set example in small font to prevent overfull line
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1194
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1195 @smallexample
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1196 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1197 list_in_columns (@{"abc", "def", "ghijkl", "mnop", "qrs", "tuv"@}, 20)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1198 @result{} abc mnop
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1199 def qrs
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1200 ghijkl tuv
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1201
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1202 whos ans
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1203 @result{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1204 Variables in the current scope:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1205
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1206 Attr Name Size Bytes Class
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1207 ==== ==== ==== ===== =====
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1208 ans 1x37 37 char
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1209
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1210 Total is 37 elements using 37 bytes
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1211 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1212 @end smallexample
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1213
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1214 @seealso{terminal_size}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1215 @end deftypefn */)
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5674
diff changeset
1216 {
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5674
diff changeset
1217 int nargin = args.length ();
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5674
diff changeset
1218
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1219 if (nargin < 1 || nargin > 3)
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
1220 print_usage ();
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1221
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20940
diff changeset
1222 string_vector s = args(0).xstring_vector_value ("list_in_columns: ARG must be a cellstr or char array");
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1223
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1224 int width = -1;
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1225
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1226 if (nargin > 1 && ! args(1).isempty ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1227 width = args(1).xint_value ("list_in_columns: WIDTH must be an integer");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1228
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1229 std::string prefix;
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5674
diff changeset
1230
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1231 if (nargin > 2)
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20581
diff changeset
1232 prefix = args(2).xstring_value ("list_in_columns: PREFIX must be a string");
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1233
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1234 std::ostringstream buf;
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1235
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1236 s.list_in_columns (buf, width, prefix);
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1237
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1238 return ovl (buf.str ());
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5674
diff changeset
1239 }
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5674
diff changeset
1240
807
c03b179482fc [project @ 1994-10-14 14:21:58 by jwe]
jwe
parents:
diff changeset
1241 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1242 %!test
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1243 %! input = {"abc", "def", "ghijkl", "mnop", "qrs", "tuv"};
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1244 %! result = "abc mnop\ndef qrs\nghijkl tuv\n";
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1245 %! assert (list_in_columns (input, 20), result);
8461
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
1246 %!test
24461
0a034d34a686 Modify BIST tests to pass when string_fill_char is not ' '.
Rik <rik@octave.org>
parents: 24441
diff changeset
1247 %! input = char ("abc", "def", "ghijkl", "mnop", "qrs", "tuv");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1248 %! result = "abc mnop \ndef qrs \nghijkl tuv \n";
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1249 %! assert (list_in_columns (input, 20), result);
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1250 %!test
24461
0a034d34a686 Modify BIST tests to pass when string_fill_char is not ' '.
Rik <rik@octave.org>
parents: 24441
diff changeset
1251 %! input = char ("abc", "def", "ghijkl", "mnop", "qrs", "tuv");
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1252 %! result = " abc mnop \n def qrs \n ghijkl tuv \n";
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1253 %! assert (list_in_columns (input, 20, " "), result);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1254
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1255 %!error list_in_columns ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1256 %!error list_in_columns (["abc", "def"], 20, 2)
14841
afa5e1d20671 * str-vec.h, str-vec.cc (string_vector::list_in_columns): Accept prefix.
John W. Eaton <jwe@octave.org>
parents: 14429
diff changeset
1257 %!error list_in_columns (["abc", "def"], 20, " ", 3)
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1258 %!error <list_in_columns: WIDTH must be an integer> list_in_columns (["abc", "def"], "a")
8461
9d456730b7a8 strfns.cc: improve documentation strings, add examples and tests
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8372
diff changeset
1259 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29823
diff changeset
1260
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30896
diff changeset
1261 OCTAVE_END_NAMESPACE(octave)