annotate libinterp/corefcn/regexp.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 864d29fb932b
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: 29961
diff changeset
3 // Copyright (C) 2002-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 ////////////////////////////////////////////////////////////////////////
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21575
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"
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
28 #endif
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
29
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
30 #include <list>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
31 #include <sstream>
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
32
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
33 #include "base-list.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
34 #include "oct-locbuf.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
35 #include "quit.h"
16940
99122191d3dd maint: Rename regexp.h to lo-regexp.h, regexp.cc to lo-regexp.cc in liboctave.
Rik <rik@octave.org>
parents: 16919
diff changeset
36 #include "lo-regexp.h"
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
37 #include "str-vec.h"
8093
dcc31f473596 Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
38
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
39 #include "defun.h"
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
40 #include "Cell.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
41 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21055
diff changeset
42 #include "errwarn.h"
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
43 #include "oct-map.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
44 #include "ovl.h"
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
45 #include "utils.h"
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
46
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31483
diff changeset
47 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
48
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
49 // Replace backslash escapes in a string with the real values. We need
15541
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
50 // two special functions instead of the one in utils.cc because the set
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
51 // of escape sequences used for regexp patterns and replacement strings
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
52 // is different from those used in the *printf functions.
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
53
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
54 static std::string
22722
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
55 do_regexp_ptn_string_escapes (const std::string& s, bool is_sq_str)
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
56 {
27565
74173f04d2a3 Use syntax for UTF-8 mode with PCRE that is used in the configure test (bug #35910).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27537
diff changeset
57 std::string retval;
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
58
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
59 std::size_t i = 0;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
60 std::size_t j = 0;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
61 std::size_t len = s.length ();
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
62
29345
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
63 retval.resize (len);
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
64
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
65 while (j < len)
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
66 {
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
67 if (s[j] == '\\' && j+1 < len)
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
68 {
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
69 switch (s[++j])
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
70 {
15541
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
71 case 'b': // backspace
22722
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
72 if (is_sq_str)
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
73 retval[i] = '\b';
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
74 else
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
75 {
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
76 // Pass escape sequence through
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
77 retval[i] = '\\';
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
78 retval[++i] = 'b';
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
79 }
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
80 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
81
29345
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
82 // Translate \< and \> to PCRE patterns for pseudo-word boundary
16918
ab46b5c77669 Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents: 16816
diff changeset
83 case '<': // begin word boundary
29345
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
84 retval.insert (i, "(?<=\\W|^)");
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
85 i += 8;
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
86 break;
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
87
16918
ab46b5c77669 Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents: 16816
diff changeset
88 case '>': // end word boundary
29345
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
89 retval.insert (i, "(?=\\W|$)");
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
90 i += 7;
16918
ab46b5c77669 Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents: 16816
diff changeset
91 break;
ab46b5c77669 Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents: 16816
diff changeset
92
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
93 case 'o': // octal input
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
94 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
95 bool bad_esc_seq = (j+1 >= len);
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
96
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
97 bool brace = false;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
98 if (! bad_esc_seq && s[++j] == '{')
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
99 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
100 brace = true;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
101 j++;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
102 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
103
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
104 int tmpi = 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
105 std::size_t k;
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
106 for (k = j; k < std::min (j+3+brace, len); k++)
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
107 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
108 int digit = s[k] - '0';
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
109 if (digit < 0 || digit > 7)
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
110 break;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
111 tmpi <<= 3;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
112 tmpi += digit;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
113 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
114 if (bad_esc_seq || (brace && s[k++] != '}'))
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
115 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
116 tmpi = 0;
23804
8057d3f0673d Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents: 23777
diff changeset
117 warning (R"(malformed octal escape sequence '\o' -- converting to '\0')");
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
118 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
119 retval[i] = tmpi;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
120 j = k - 1;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
121 break;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
122 }
15541
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
123
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
124 default: // pass escape sequence through
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
125 retval[i] = '\\';
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
126 retval[++i] = s[j];
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
127 break;
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
128 }
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
129 }
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
130 else
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
131 {
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
132 retval[i] = s[j];
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
133 }
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
134
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
135 i++;
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
136 j++;
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
137 }
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
138
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
139 retval.resize (i);
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
140
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
141 return retval;
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
142 }
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
143
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
144 static std::string
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
145 do_regexp_rep_string_escapes (const std::string& s)
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
146 {
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
147 std::string retval;
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
148
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
149 std::size_t i = 0;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
150 std::size_t j = 0;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
151 std::size_t len = s.length ();
15541
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
152
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
153 retval.resize (len);
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
154
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
155 while (j < len)
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
156 {
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
157 if (s[j] == '\\' && j+1 < len)
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
158 {
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
159 switch (s[++j])
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
160 {
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
161 case 'a': // alarm
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
162 retval[i] = '\a';
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
163 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
164
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
165 case 'b': // backspace
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
166 retval[i] = '\b';
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
167 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
168
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
169 case 'f': // formfeed
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
170 retval[i] = '\f';
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
171 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
172
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
173 case 'n': // newline
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
174 retval[i] = '\n';
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
175 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
176
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
177 case 'r': // carriage return
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
178 retval[i] = '\r';
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
179 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
180
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
181 case 't': // horizontal tab
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
182 retval[i] = '\t';
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
183 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
184
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
185 case 'v': // vertical tab
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
186 retval[i] = '\v';
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
187 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
188
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
189 case '0':
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
190 case '1':
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
191 case '2':
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
192 case '3':
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
193 case '4':
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
194 case '5':
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
195 case '6':
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
196 case '7': // octal input
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
197 {
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
198 std::size_t k;
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
199 int tmpi = s[j] - '0';
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
200 for (k = j+1; k < std::min (j+3, len); k++)
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
201 {
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
202 int digit = s[k] - '0';
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
203 if (digit < 0 || digit > 7)
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
204 break;
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
205 tmpi <<= 3;
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
206 tmpi += digit;
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
207 }
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
208 retval[i] = tmpi;
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
209 j = k - 1;
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
210 break;
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
211 }
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
212
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
213 case 'o': // octal input
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
214 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
215 bool bad_esc_seq = (j+1 >= len);
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
216
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
217 bool brace = false;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
218 if (! bad_esc_seq && s[++j] == '{')
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
219 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
220 brace = true;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
221 j++;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
222 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
223
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
224 int tmpi = 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
225 std::size_t k;
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
226 for (k = j; k < std::min (j+3+brace, len); k++)
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
227 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
228 int digit = s[k] - '0';
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
229 if (digit < 0 || digit > 7)
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
230 break;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
231 tmpi <<= 3;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
232 tmpi += digit;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
233 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
234 if (bad_esc_seq || (brace && s[k++] != '}'))
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
235 {
23804
8057d3f0673d Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents: 23777
diff changeset
236 warning (R"(malformed octal escape sequence '\o' -- converting to '\0')");
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
237 tmpi = 0;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
238 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
239 retval[i] = tmpi;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
240 j = k - 1;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
241 break;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
242 }
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
243
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
244 case 'x': // hex input
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
245 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
246 bool bad_esc_seq = (j+1 >= len);
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
247
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
248 bool brace = false;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
249 if (! bad_esc_seq && s[++j] == '{')
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
250 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
251 brace = true;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
252 j++;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
253 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
254
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
255 int tmpi = 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
256 std::size_t k;
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
257 for (k = j; k < std::min (j+2+brace, len); k++)
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
258 {
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
259 if (! isxdigit (s[k]))
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
260 break;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
261
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
262 tmpi <<= 4;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
263 int digit = s[k];
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
264 if (digit >= 'a')
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
265 tmpi += digit - 'a' + 10;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
266 else if (digit >= 'A')
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
267 tmpi += digit - 'A' + 10;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
268 else
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
269 tmpi += digit - '0';
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
270 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
271 if (bad_esc_seq || (brace && s[k++] != '}'))
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
272 {
23804
8057d3f0673d Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents: 23777
diff changeset
273 warning (R"(malformed hex escape sequence '\x' -- converting to '\0')");
20211
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
274 tmpi = 0;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
275 }
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
276 retval[i] = tmpi;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
277 j = k - 1;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
278 break;
f2bc7d23295d Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents: 20172
diff changeset
279 }
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
280
20290
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
281 // Both dollar sign (for capture buffer) and backslash are
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
282 // passed through with their escape backslash. The processing
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
283 // for these must occur during the actual replacement operation
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
284 // in lo-regexp.cc.
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
285 case '$': // pass dollar sign through with escape
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
286 retval[i] = '\\'; retval[++i] = '$';
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
287 break;
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
288
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
289 case '\\': // pass backslash through with escape
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
290 retval[i] = '\\'; retval[++i] = '\\';
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
291 break;
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
292
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
293 default: // convert escaped character to unescaped char
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
294 retval[i] = s[j];
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
295 break;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
296 }
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
297 }
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
298 else
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
299 {
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
300 retval[i] = s[j];
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
301 }
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
302
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
303 i++;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
304 j++;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
305 }
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
306
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
307 retval.resize (i);
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
308
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
309 return retval;
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
310 }
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
311
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
312 static void
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
313 parse_options (regexp::opts& options, const octave_value_list& args,
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
314 const std::string& who, int skip, bool& extra_args)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
315 {
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
316 extra_args = false;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
317
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20801
diff changeset
318 for (int i = skip; i < args.length (); i++)
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
319 {
19403
03067dab10ca Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents: 17861
diff changeset
320 std::string str;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
321
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20581
diff changeset
322 str = args(i).xstring_value ("%s: optional arguments must be strings", who.c_str ());
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
323
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
324 std::transform (str.begin (), str.end (), str.begin (), tolower);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
325
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
326 if (str.find ("once", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
327 options.once (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
328 else if (str.find ("matchcase", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
329 options.case_insensitive (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
330 else if (str.find ("ignorecase", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
331 options.case_insensitive (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
332 else if (str.find ("dotall", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
333 options.dotexceptnewline (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
334 else if (str.find ("stringanchors", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
335 options.lineanchors (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
336 else if (str.find ("literalspacing", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
337 options.freespacing (false);
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
338 else if (str.find ("noemptymatch", 0) == 0)
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
339 options.emptymatch (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
340 else if (str.find ("dotexceptnewline", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
341 options.dotexceptnewline (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
342 else if (str.find ("lineanchors", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
343 options.lineanchors (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
344 else if (str.find ("freespacing", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
345 options.freespacing (true);
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
346 else if (str.find ("emptymatch", 0) == 0)
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
347 options.emptymatch (true);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
348 else if (str.find ("start", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
349 || str.find ("end", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
350 || str.find ("tokenextents", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
351 || str.find ("match", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
352 || str.find ("tokens", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
353 || str.find ("names", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
354 || str.find ("split", 0) == 0)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
355 extra_args = true;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
356 else
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
357 error ("%s: unrecognized option", who.c_str ());
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
358 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
359 }
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
360
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
361 static octave_value_list
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
362 octregexp (const octave_value_list& args, int nargout,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
363 const std::string& who, bool case_insensitive = false)
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
364 {
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
365 octave_value_list retval;
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
366
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
367 int nargin = args.length ();
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
368
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
369 // Make sure we have string, pattern
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
370 const std::string buffer = args(0).string_value ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
371
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
372 std::string pattern = args(1).string_value ();
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
373
22722
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
374 // Rewrite pattern for PCRE
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
375 pattern = do_regexp_ptn_string_escapes (pattern, args(1).is_sq_string ());
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
376
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
377 regexp::opts options;
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
378 options.case_insensitive (case_insensitive);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
379 bool extra_options = false;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
380 parse_options (options, args, who, 2, extra_options);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
381
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
382 const regexp::match_data rx_lst
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
383 = regexp::match (pattern, buffer, options, who);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
384
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
385 string_vector named_pats = rx_lst.named_patterns ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
386
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
387 std::size_t sz = rx_lst.size ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
388
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
389 // Converted the linked list in the correct form for the return values
12464
dfeea9cae79e require PCRE to build Octave
John W. Eaton <jwe@octave.org>
parents: 12462
diff changeset
390
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
391 octave_map nmap (dim_vector ((sz == 0 ? 0 : 1), sz), named_pats);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
392
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
393 retval.resize (7);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
394
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
395 if (sz != 0)
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
396 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
397 for (int j = 0; j < named_pats.numel (); j++)
7893
eb9ccb44ea41 make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7520
diff changeset
398 {
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
399 Cell ctmp (dim_vector (1, sz));
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
400 octave_idx_type i = 0;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
401
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
402 for (const auto& match_data : rx_lst)
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
403 {
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
404 string_vector named_tokens = match_data.named_tokens ();
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
405
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
406 ctmp(i++) = named_tokens(j);
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
407 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
408
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
409 nmap.assign (named_pats(j), ctmp);
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
410 }
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
411 }
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
412 retval(5) = nmap;
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
413
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
414 if (options.once ())
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
415 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
416 auto p = rx_lst.begin ();
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
417
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
418 retval(4) = (sz ? p->tokens () : Cell ());
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
419 retval(3) = (sz ? p->match_string () : "");
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
420 retval(2) = (sz ? p->token_extents () : Matrix ());
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
421
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
422 if (sz)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
423 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
424 double start = p->start ();
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
425 double end = p->end ();
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
426
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
427 Cell split (dim_vector (1, 2));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
428 split(0) = buffer.substr (0, start-1);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
429 split(1) = buffer.substr (end);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
430
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
431 retval(6) = split;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
432 retval(1) = end;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
433 retval(0) = start;
7893
eb9ccb44ea41 make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7520
diff changeset
434 }
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
435 else
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
436 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
437 retval(6) = buffer;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
438 retval(1) = Matrix ();
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
439 retval(0) = Matrix ();
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
440 }
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
441 }
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
442 else
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
443 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
444 Cell tokens (dim_vector (1, sz));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
445 Cell match_string (dim_vector (1, sz));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
446 Cell token_extents (dim_vector (1, sz));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
447 NDArray end (dim_vector (1, sz));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
448 NDArray start (dim_vector (1, sz));
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
449 Cell split (dim_vector (1, sz+1));
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
450 std::size_t sp_start = 0;
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
451
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
452 octave_idx_type i = 0;
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
453 for (const auto& match_data : rx_lst)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
454 {
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
455 double s = match_data.start ();
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
456 double e = match_data.end ();
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
457
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
458 string_vector tmp = match_data.tokens ();
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
459 tokens(i) = Cell (dim_vector (1, tmp.numel ()), tmp);
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
460 match_string(i) = match_data.match_string ();
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
461 token_extents(i) = match_data.token_extents ();
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
462 end(i) = e;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
463 start(i) = s;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
464 split(i) = buffer.substr (sp_start, s-sp_start-1);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
465 sp_start = e;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
466 i++;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
467 }
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
468
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
469 split(i) = buffer.substr (sp_start);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
470
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
471 retval(6) = split;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
472 retval(4) = tokens;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
473 retval(3) = match_string;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
474 retval(2) = token_extents;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
475 retval(1) = end;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
476 retval(0) = start;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
477 }
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
478
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
479 // Alter the order of the output arguments
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
480
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
481 if (extra_options)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
482 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
483 int n = 0;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
484 octave_value_list new_retval;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
485 new_retval.resize (nargout);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
486
26476
54ad1294ed70 regexp.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
487 bool arg_used[7] {};
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
488
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
489 for (int j = 2; j < nargin; j++)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
490 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
491 int k = 0;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
492 std::string str = args(j).string_value ();
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
493 std::transform (str.begin (), str.end (), str.begin (), tolower);
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
494
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
495 if (str.find ("once", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
496 || str.find ("stringanchors", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
497 || str.find ("lineanchors", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
498 || str.find ("matchcase", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
499 || str.find ("ignorecase", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
500 || str.find ("dotall", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
501 || str.find ("dotexceptnewline", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
502 || str.find ("literalspacing", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
503 || str.find ("freespacing", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
504 || str.find ("noemptymatch", 0) == 0
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
505 || str.find ("emptymatch", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
506 continue;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
507 else if (str.find ("start", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
508 k = 0;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
509 else if (str.find ("end", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
510 k = 1;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
511 else if (str.find ("tokenextents", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
512 k = 2;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
513 else if (str.find ("match", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
514 k = 3;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
515 else if (str.find ("tokens", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
516 k = 4;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
517 else if (str.find ("names", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
518 k = 5;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
519 else if (str.find ("split", 0) == 0)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
520 k = 6;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
521
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
522 new_retval(n++) = retval(k);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
523 arg_used[k] = true;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
524
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
525 if (n == nargout)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
526 break;
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
527 }
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
528
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
529 // Fill in the rest of the arguments
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
530 if (n < nargout)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
531 {
23769
fdce2b73f5ce regexp.cc: Correctly size temporary buffer to avoid segfault when re-arranging outputs.
Rik <rik@octave.org>
parents: 23219
diff changeset
532 for (int j = 0; j < 7; j++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
533 {
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
534 if (! arg_used[j])
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
535 new_retval(n++) = retval(j);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
536 }
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
537 }
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
538
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
539 retval = new_retval;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
540 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
541
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
542 return retval;
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
543 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
544
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
545 static octave_value_list
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
546 octcellregexp (const octave_value_list& args, int nargout,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
547 const std::string& who, bool case_insensitive = false)
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
548 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
549 octave_value_list retval;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
550
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
551 if (args(0).iscell ())
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
552 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
553 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
554 octave_value_list new_args = args;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
555 Cell cellstr = args(0).cell_value ();
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
556 if (args(1).iscell ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
557 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
558 Cell cellpat = args(1).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
559
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
560 if (cellpat.numel () == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
561 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
562 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
563 newretval[j].resize (cellstr.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
564
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
565 new_args(1) = cellpat(0);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
566
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
567 for (octave_idx_type i = 0; i < cellstr.numel (); i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
568 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
569 new_args(0) = cellstr(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
570 octave_value_list tmp = octregexp (new_args, nargout, who,
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
571 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
572
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
573 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
574 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
575 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
576 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
577 else if (cellstr.numel () == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
578 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
579 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
580 newretval[j].resize (cellpat.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
581
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
582 new_args(0) = cellstr(0);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
583
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
584 for (octave_idx_type i = 0; i < cellpat.numel (); i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
585 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
586 new_args(1) = cellpat(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
587 octave_value_list tmp = octregexp (new_args, nargout, who,
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
588 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
589
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
590 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
591 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
592 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
593 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
594 else if (cellstr.numel () == cellpat.numel ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
595 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
596 if (cellstr.dims () != cellpat.dims ())
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
597 error ("%s: inconsistent cell array dimensions", who.c_str ());
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
598
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
599 for (int j = 0; j < nargout; j++)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
600 newretval[j].resize (cellstr.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
601
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
602 for (octave_idx_type i = 0; i < cellstr.numel (); i++)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
603 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
604 new_args(0) = cellstr(i);
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
605 new_args(1) = cellpat(i);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
606
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
607 octave_value_list tmp = octregexp (new_args, nargout, who,
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
608 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
609
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
610 for (int j = 0; j < nargout; j++)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21017
diff changeset
611 newretval[j](i) = tmp(j);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
612 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
613 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
614 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
615 error ("regexp: cell array arguments must be scalar or equal size");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
616 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
617 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
618 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
619 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
620 newretval[j].resize (cellstr.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
621
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
622 for (octave_idx_type i = 0; i < cellstr.numel (); i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
623 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
624 new_args(0) = cellstr(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
625 octave_value_list tmp = octregexp (new_args, nargout, who,
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
626 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
627
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
628 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
629 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
630 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
631 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
632
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
633 for (int j = 0; j < nargout; j++)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
634 retval(j) = octave_value (newretval[j]);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
635 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
636 else if (args(1).iscell ())
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
637 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
638 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
639 octave_value_list new_args = args;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
640 Cell cellpat = args(1).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
641
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
642 for (int j = 0; j < nargout; j++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
643 newretval[j].resize (cellpat.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
644
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
645 for (octave_idx_type i = 0; i < cellpat.numel (); i++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
646 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
647 new_args(1) = cellpat(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
648 octave_value_list tmp = octregexp (new_args, nargout, who,
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
649 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
650
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
651 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
652 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
653 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
654
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
655 for (int j = 0; j < nargout; j++)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
656 retval(j) = octave_value (newretval[j]);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
657 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
658 else
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
659 retval = octregexp (args, nargout, who, case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
660
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
661 return retval;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
662
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
663 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
664
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
665 DEFUN (regexp, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
666 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
667 @deftypefn {} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexp (@var{str}, @var{pat})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
668 @deftypefnx {} {[@dots{}] =} regexp (@var{str}, @var{pat}, "@var{opt1}", @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
669 Regular expression string matching.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
670
27537
7dc31256c5e4 Document that regexp* functions need UTF-8 encoded input (bug #35910).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27278
diff changeset
671 Search for @var{pat} in UTF-8 encoded @var{str} and return the positions and
7dc31256c5e4 Document that regexp* functions need UTF-8 encoded input (bug #35910).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27278
diff changeset
672 substrings of any matches, or empty values if there are none.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
673
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
674 The matched pattern @var{pat} can include any of the standard regex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
675 operators, including:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
676
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
677 @table @code
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
678 @item .
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
679 Match any character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
680
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
681 @item * + ? @{@}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
682 Repetition operators, representing
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
683
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
684 @table @code
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
685 @item *
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
686 Match zero or more times
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
687
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
688 @item +
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
689 Match one or more times
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
690
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
691 @item ?
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
692 Match zero or one times
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
693
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
694 @item @{@var{n}@}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
695 Match exactly @var{n} times
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
696
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
697 @item @{@var{n},@}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
698 Match @var{n} or more times
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
699
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
700 @item @{@var{m},@var{n}@}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
701 Match between @var{m} and @var{n} times
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
702 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
703
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
704 @item [@dots{}] [^@dots{}]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
705
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 22197
diff changeset
706 List operators. The pattern will match any character listed between
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 22197
diff changeset
707 @qcode{"["} and @qcode{"]"}. If the first character is @qcode{"^"} then the
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 22197
diff changeset
708 pattern is inverted and any character except those listed between brackets
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 22197
diff changeset
709 will match.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
710
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
711 Escape sequences defined below can also be used inside list operators. For
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
712 example, a template for a floating point number might be @code{[-+.\d]+}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
713
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
714 @item () (?:)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
715 Grouping operator. The first form, parentheses only, also creates a token.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
716
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
717 @item |
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
718 Alternation operator. Match one of a choice of regular expressions. The
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
719 alternatives must be delimited by the grouping operator @code{()} above.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
720
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
721 @item ^ $
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
722 Anchoring operators. Requires pattern to occur at the start (@code{^}) or
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
723 end (@code{$}) of the string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
724 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
725
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
726 In addition, the following escaped characters have special meaning.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
727
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
728 @table @code
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
729
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
730 @item \d
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
731 Match any digit
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
732
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
733 @item \D
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
734 Match any non-digit
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
735
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
736 @item \s
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
737 Match any whitespace character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
738
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
739 @item \S
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
740 Match any non-whitespace character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
741
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
742 @item \w
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
743 Match any word character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
744
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
745 @item \W
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
746 Match any non-word character
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
747
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
748 @item \<
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
749 Match the beginning of a word
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
750
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
751 @item \>
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
752 Match the end of a word
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
753
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
754 @item \B
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
755 Match within a word
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
756 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
757
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
758 Implementation Note: For compatibility with @sc{matlab}, escape sequences
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 28961
diff changeset
759 in @var{pat} (e.g., @qcode{"@backslashchar{}n"} => newline) are expanded
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
760 even when @var{pat} has been defined with single quotes. To disable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
761 expansion use a second backslash before the escape sequence (e.g.,
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 28961
diff changeset
762 "@backslashchar{}@backslashchar{}n") or use the @code{regexptranslate}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
763 function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
764
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
765 The outputs of @code{regexp} default to the order given below
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
766
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
767 @table @var
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
768 @item s
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
769 The start indices of each matching substring
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
770
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
771 @item e
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
772 The end indices of each matching substring
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
773
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
774 @item te
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
775 The extents of each matched token surrounded by @code{(@dots{})} in
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
776 @var{pat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
777
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
778 @item m
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
779 A cell array of the text of each match
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
780
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
781 @item t
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
782 A cell array of the text of each token matched
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
783
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
784 @item nm
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
785 A structure containing the text of each matched named token, with the name
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
786 being used as the fieldname. A named token is denoted by
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
787 @code{(?<name>@dots{})}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
788
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
789 @item sp
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
790 A cell array of the text not returned by match, i.e., what remains if you
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
791 split the string based on @var{pat}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
792 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
793
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
794 Particular output arguments, or the order of the output arguments, can be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
795 selected by additional @var{opt} arguments. These are strings and the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
796 correspondence between the output arguments and the optional argument
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
797 are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
798
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
799 @multitable @columnfractions 0.2 0.3 0.3 0.2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
800 @item @tab @qcode{'start'} @tab @var{s} @tab
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
801 @item @tab @qcode{'end'} @tab @var{e} @tab
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
802 @item @tab @qcode{'tokenExtents'} @tab @var{te} @tab
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
803 @item @tab @qcode{'match'} @tab @var{m} @tab
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
804 @item @tab @qcode{'tokens'} @tab @var{t} @tab
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
805 @item @tab @qcode{'names'} @tab @var{nm} @tab
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
806 @item @tab @qcode{'split'} @tab @var{sp} @tab
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
807 @end multitable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
808
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
809 Additional arguments are summarized below.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
810
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
811 @table @samp
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
812 @item once
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
813 Return only the first occurrence of the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
814
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
815 @item matchcase
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
816 Make the matching case sensitive. (default)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
817
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
818 Alternatively, use (?-i) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
819
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
820 @item ignorecase
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
821 Ignore case when matching the pattern to the string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
822
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
823 Alternatively, use (?i) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
824
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
825 @item stringanchors
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
826 Match the anchor characters at the beginning and end of the string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
827 (default)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
828
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
829 Alternatively, use (?-m) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
830
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
831 @item lineanchors
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
832 Match the anchor characters at the beginning and end of the line.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
833
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
834 Alternatively, use (?m) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
835
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
836 @item dotall
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
837 The pattern @code{.} matches all characters including the newline character.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
838 (default)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
839
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
840 Alternatively, use (?s) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
841
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
842 @item dotexceptnewline
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
843 The pattern @code{.} matches all characters except the newline character.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
844
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
845 Alternatively, use (?-s) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
846
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
847 @item literalspacing
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
848 All characters in the pattern, including whitespace, are significant and are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
849 used in pattern matching. (default)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
850
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
851 Alternatively, use (?-x) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
852
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
853 @item freespacing
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
854 The pattern may include arbitrary whitespace and also comments beginning
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
855 with the character @samp{#}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
856
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
857 Alternatively, use (?x) in the pattern.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
858
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
859 @item noemptymatch
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
860 Zero-length matches are not returned. (default)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
861
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
862 @item emptymatch
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
863 Return zero-length matches.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
864
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
865 @code{regexp ('a', 'b*', 'emptymatch')} returns @code{[1 2]} because there
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
866 are zero or more @qcode{'b'} characters at positions 1 and end-of-string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
867
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
868 @end table
24986
0b9e7fcaab91 doc: grammarcheck docstrings in C++ files ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24751
diff changeset
869
23816
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
870 Stack Limitation Note: Pattern searches are done with a recursive function
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
871 which can overflow the program stack when there are a high number of matches.
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
872 For example,
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
873
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
874 @example
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
875 @code{regexp (repmat ('a', 1, 1e5), '(a)+')}
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
876 @end example
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
877
24986
0b9e7fcaab91 doc: grammarcheck docstrings in C++ files ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24751
diff changeset
878 @noindent
23816
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
879 may lead to a segfault. As an alternative, consider constructing pattern
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
880 searches that reduce the number of matches (e.g., by creatively using set
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
881 complement), and then further processing the return variables (now reduced in
d396866fa7d8 Add documentation about PCRE library regexp stack overflow (bug #51589).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23769
diff changeset
882 size) with successive @code{regexp} searches.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
883 @seealso{regexpi, strfind, regexprep}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
884 @end deftypefn */)
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
885 {
20821
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
886 if (args.length () < 2)
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
887 print_usage ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
888
20821
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
889 octave_value_list retval;
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
890
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
891 if (args(0).iscell () || args(1).iscell ())
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
892 retval = (octcellregexp (args, (nargout > 0 ? nargout : 1), "regexp"));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
893 else
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
894 retval = octregexp (args, nargout, "regexp");
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
895
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
896 return retval;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
897 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
898
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
899 /*
8140
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
900 ## PCRE_ERROR_MATCHLIMIT test
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
901 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
902 %! s = sprintf ('\t4\n0000\t-0.00\t-0.0000\t4\t-0.00\t-0.0000\t4\n0000\t-0.00\t-0.0000\t0\t-0.00\t-');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
903 %! ws = warning ("query");
8140
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
904 %! unwind_protect
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
905 %! warning ("off");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
906 %! regexp (s, '(\s*-*\d+[.]*\d*\s*)+\n');
8140
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
907 %! unwind_protect_cleanup
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
908 %! warning (ws);
8140
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
909 %! end_unwind_protect
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
910
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
911 ## segfault test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
912 %!assert (regexp ("abcde", "."), [1,2,3,4,5])
31114
5cf18ef0377c regexp: Check pattern length before accessing it (bug #62704).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
913 %!assert <*62704> (regexpi('(', '\(?'), 1)
13759
c4b6ea833fa5 Fix infinite loop with null patterns in regexp (Bug #34101, Bug #33258)
Rik <octave@nomad.inbox5.com>
parents: 13311
diff changeset
914 ## Infinite loop test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
915 %!assert (isempty (regexp ("abcde", "")))
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
916
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
917 ## Check that anchoring of pattern works correctly
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
918 %!assert (regexp ('abcabc', '^abc'), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
919 %!assert (regexp ('abcabc', 'abc$'), 4)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
920 %!assert (regexp ('abcabc', '^abc$'), zeros (1,0))
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
921
31483
864d29fb932b Add test for regexp match on UTF-8 string (patch #10295).
Rafael Laboissiere <rafael@laboissiere.net>
parents: 31422
diff changeset
922 ## UTF-8 test with character vector "âé🙂ïõù"
864d29fb932b Add test for regexp match on UTF-8 string (patch #10295).
Rafael Laboissiere <rafael@laboissiere.net>
parents: 31422
diff changeset
923 %!assert (regexp (char ([195, 162, 195, 169, 240, 159, 153, 130, 195, 175, ...
864d29fb932b Add test for regexp match on UTF-8 string (patch #10295).
Rafael Laboissiere <rafael@laboissiere.net>
parents: 31422
diff changeset
924 %! 195, 181, 195, 185]), "."), [1, 3, 5, 9, 11, 13])
864d29fb932b Add test for regexp match on UTF-8 string (patch #10295).
Rafael Laboissiere <rafael@laboissiere.net>
parents: 31422
diff changeset
925
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
926 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
927 %! [s, e, te, m, t] = regexp (' No Match ', 'f(.*)uck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
928 %! assert (s, zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
929 %! assert (e, zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
930 %! assert (te, cell (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
931 %! assert (m, cell (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
932 %! assert (t, cell (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
933
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
934 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
935 %! [s, e, te, m, t] = regexp (' FiRetrUck ', 'f(.*)uck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
936 %! assert (s, zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
937 %! assert (e, zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
938 %! assert (te, cell (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
939 %! assert (m, cell (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
940 %! assert (t, cell (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
941
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
942 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
943 %! [s, e, te, m, t] = regexp (' firetruck ', 'f(.*)uck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
944 %! assert (s, 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
945 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
946 %! assert (te{1}, [3, 7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
947 %! assert (m{1}, 'firetruck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
948 %! assert (t{1}{1}, 'iretr');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
949
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
950 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
951 %! [s, e, te, m, t] = regexp ('short test string', '\w*r\w*');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
952 %! assert (s, [1, 12]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
953 %! assert (e, [5, 17]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
954 %! assert (size (te), [1, 2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
955 %! assert (isempty (te{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
956 %! assert (isempty (te{2}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
957 %! assert (m{1}, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
958 %! assert (m{2}, 'string');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
959 %! assert (size (t), [1, 2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
960 %! assert (isempty (t{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
961 %! assert (isempty (t{2}));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
962
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
963 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
964 %! [s, e, te, m, t] = regexp ('short test string', '\w*r\w*', 'once');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
965 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
966 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
967 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
968 %! assert (m, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
969 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
970
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
971 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
972 %! [m, te, e, s, t] = regexp ('short test string', '\w*r\w*', 'once', 'match', 'tokenExtents', 'end', 'start', 'tokens');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
973 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
974 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
975 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
976 %! assert (m, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
977 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
978
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
979 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
980 %! [s, e, te, m, t, nm] = regexp ('short test string', '(?<word1>\w*t)\s*(?<word2>\w*t)');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
981 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
982 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
983 %! assert (size (te), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
984 %! assert (te{1}, [1,5; 7,10]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
985 %! assert (m{1}, 'short test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
986 %! assert (size (t), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
987 %! assert (t{1}{1}, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
988 %! assert (t{1}{2}, 'test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
989 %! assert (size (nm), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
990 %! assert (! isempty (fieldnames (nm)));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
991 %! assert (sort (fieldnames (nm)), {'word1';'word2'});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
992 %! assert (nm.word1, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
993 %! assert (nm.word2, 'test');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
994
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
995 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
996 %! [nm, m, te, e, s, t] = regexp ('short test string', '(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
997 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
998 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
999 %! assert (size (te), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1000 %! assert (te{1}, [1,5; 7,10]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1001 %! assert (m{1}, 'short test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1002 %! assert (size (t), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1003 %! assert (t{1}{1}, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1004 %! assert (t{1}{2}, 'test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1005 %! assert (size (nm), [1, 1]);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
1006 %! assert (! isempty (fieldnames (nm)));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1007 %! assert (sort (fieldnames (nm)), {'word1';'word2'});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1008 %! assert (nm.word1, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1009 %! assert (nm.word2, 'test');
5619
e9112ff172b1 [project @ 2006-02-13 20:05:36 by dbateman]
dbateman
parents: 5582
diff changeset
1010
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1011 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1012 %! [t, nm] = regexp ("John Davis\nRogers, James", '(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)', 'tokens', 'names');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1013 %! assert (size (t), [1, 2]);
23019
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1014 %! assert (t{1}{1}, "John");
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1015 %! assert (t{1}{2}, "Davis");
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1016 %! assert (t{2}{1}, "Rogers");
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1017 %! assert (t{2}{2}, "James");
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1018 %! assert (size (nm), [1, 2]);
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1019 %! assert (nm(1).first, "John");
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1020 %! assert (nm(1).last, "Davis");
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1021 %! assert (nm(2).first, "James");
cb09392b5b1c Return struct array for 'names' option of regexp (bug #49659).
Rik <rik@octave.org>
parents: 22862
diff changeset
1022 %! assert (nm(2).last, "Rogers");
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1023
24741
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1024 ## Tests for nulls in strings properly matching
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1025 %!test
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1026 %! str = "A\0B\0\0C";
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1027 %! ptn = '(\0+)'; # also test null in single-quote pattern
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1028 %! M = regexp (str, ptn, "match");
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1029 %! assert (size (M), [1, 2]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1030 %! assert (double (M{1}), [0]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1031 %! assert (double (M{2}), [0, 0]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1032
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1033 %!test
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1034 %! str = "A\0B\0\0C";
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1035 %! ptn = "(\0+)"; # also test null in double-quote pattern
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1036 %! T = regexp (str, ptn, "tokens");
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1037 %! assert (size (T), [1, 2]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1038 %! assert (double (T{1}{1}), [0]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1039 %! assert (double (T{2}{1}), [0, 0]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1040
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1041 %!test
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1042 %! str = "A\0B\0\0C";
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1043 %! ptn = '(?<namedtoken>\0+)';
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1044 %! NT = regexp (str, ptn, "names");
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1045 %! assert (size (NT), [1, 2]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1046 %! assert (double (NT(1).namedtoken), [0]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1047 %! assert (double (NT(2).namedtoken), [0, 0]);
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1048
14452
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1049 ## Tests for named tokens
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1050 %!test
17336
b81b9d079515 Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents: 17281
diff changeset
1051 %! ## Parenthesis in named token (ie (int)) causes a problem
24741
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1052 %! assert (regexp ('qwe int asd', ['(?<typestr>(int))'], 'names'),
00dfa167c1fe Fix handling of NULL character in regular expressions for Matlab compatibility.
Rik <rik@octave.org>
parents: 24607
diff changeset
1053 %! struct ('typestr', 'int'));
10518
fcafe0e9bd58 Handle repeated matches in matches returned by pcre
David Bateman <dbateman@free.fr>
parents: 10504
diff changeset
1054
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1055 %!test <*35683>
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22407
diff changeset
1056 %! ## Mix of named and unnamed tokens can cause segfault
14452
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1057 %! str = "abcde";
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1058 %! ptn = '(?<T1>a)(\w+)(?<T2>d\w+)';
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1059 %! tokens = regexp (str, ptn, "names");
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1060 %! assert (isstruct (tokens) && numel (tokens) == 1);
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1061 %! assert (tokens.T1, "a");
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1062 %! assert (tokens.T2, "de");
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1063
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1064 ## Test options to regexp
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1065 %!assert (regexp ("abc\nabc", '.'), [1:7])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1066 %!assert (regexp ("abc\nabc", '.', 'dotall'), [1:7])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1067 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1068 %! assert (regexp ("abc\nabc", '(?s).'), [1:7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1069 %! assert (regexp ("abc\nabc", '.', 'dotexceptnewline'), [1,2,3,5,6,7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1070 %! assert (regexp ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1071
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1072 %!assert (regexp ("caseCaSe", 'case'), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1073 %!assert (regexp ("caseCaSe", 'case', "matchcase"), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1074 %!assert (regexp ("caseCaSe", 'case', "ignorecase"), [1,5])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1075 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1076 %! assert (regexp ("caseCaSe", '(?-i)case'), 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1077 %! assert (regexp ("caseCaSe", '(?i)case'), [1, 5]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1078
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1079 %!assert (regexp ("abc\nabc", 'c$'), 7)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1080 %!assert (regexp ("abc\nabc", 'c$', "stringanchors"), 7)
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1081 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1082 %! assert (regexp ("abc\nabc", '(?-m)c$'), 7);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1083 %! assert (regexp ("abc\nabc", 'c$',"lineanchors"), [3, 7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1084 %! assert (regexp ("abc\nabc", '(?m)c$'), [3,7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1085
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1086 %!assert (regexp ("this word", 's w'), 4)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1087 %!assert (regexp ("this word", 's w', 'literalspacing'), 4)
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1088 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1089 %! assert (regexp ("this word", '(?-x)s w', 'literalspacing'), 4);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1090 %! assert (regexp ("this word", 's w', 'freespacing'), zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1091 %! assert (regexp ("this word", '(?x)s w'), zeros (1,0));
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1092
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1093 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1094 %! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '[VOCT]*', 'noemptymatch');
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1095 %! assert (s, [1 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1096 %! assert (e, [3 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1097 %! assert (te, { zeros(0,2), zeros(0,2) });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1098 %! assert (m, { "OCT", "V" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1099 %! assert (t, { cell(1,0), cell(1,0) });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1100 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1101 %! assert (sp, { "", "A", "E" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1102
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1103 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1104 %! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '([VOCT]*)', 'noemptymatch');
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1105 %! assert (s, [1 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1106 %! assert (e, [3 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1107 %! assert (te, { [1 3], [5 5] });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1108 %! assert (m, { "OCT", "V" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1109 %! assert (t, { {"OCT"}, {"V"} });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1110 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1111 %! assert (sp, { "", "A", "E" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1112
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1113 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1114 %! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '[VOCT]*', 'emptymatch');
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1115 %! assert (s, [1 4 5 6 7]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1116 %! assert (e, [3 3 5 5 6]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1117 %! assert (te, repmat ({zeros(0,2)}, [1, 5]));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1118 %! assert (m, { "OCT", "", "V", "", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1119 %! assert (t, repmat({cell(1,0)}, [1, 5]));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1120 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1121 %! assert (sp, { "", "", "A", "", "E", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1122
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1123 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1124 %! [s, e, te, m, t, nm, sp] = regexp ('OCTAVE', '([VOCT]*)', 'emptymatch');
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1125 %! assert (s, [1 4 5 6 7]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1126 %! assert (e, [3 3 5 5 6]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1127 %! assert (te, { [1 3], [4 3], [5 5], [6 5], [7 6] });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1128 %! assert (m, { "OCT", "", "V", "", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1129 %! assert (t, { {"OCT"}, {""}, {"V"}, {""}, {""} });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1130 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1131 %! assert (sp, { "", "", "A", "", "E", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1132
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1133 %!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1134 %! {6;[1,5,9];zeros(1,0)})
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1135 %!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1136 %! {6;[3,7];[1,9]})
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1137 %!assert (regexp ('Strings', {'t','s'}), {2, 7})
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1138
8093
dcc31f473596 Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
1139 ## Test case for lookaround operators
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1140 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1141 %! assert (regexp ('Iraq', 'q(?!u)'), 4);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1142 %! assert (regexp ('quit', 'q(?!u)'), zeros (1, 0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1143 %! assert (regexp ('quit', 'q(?=u)' , 'match'), {'q'});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1144 %! assert (regexp ("quit", 'q(?=u+)', 'match'), {'q'});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1145 %! assert (regexp ("qit", 'q(?=u+)', 'match'), cell (1, 0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1146 %! assert (regexp ("qit", 'q(?=u*)', 'match'), {'q'});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1147 %! assert (regexp ('thingamabob', '(?<=a)b'), 9);
8093
dcc31f473596 Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
1148
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1149 ## Tests for split option.
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1150 %!shared str
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1151 %! str = "foo bar foo";
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1152 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1153 %! [a, b] = regexp (str, "f..", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1154 %! assert (a, {"foo", "foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1155 %! assert (b, {"", " bar ", ""});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1156 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1157 %! [a, b] = regexp (str, "f..", "match", "split", "once");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1158 %! assert (a, "foo");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1159 %! assert (b, {"", " bar foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1160 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1161 %! [a, b] = regexp (str, "fx.", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1162 %! assert (a, cell (1, 0));
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1163 %! assert (b, {"foo bar foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1164 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1165 %! [a, b] = regexp (str, "fx.", "match", "split", "once");
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1166 %! assert (a, "");;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1167 %! assert (b, "foo bar foo");
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1168
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1169 %!shared str
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1170 %! str = "foo bar";
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1171 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1172 %! [a, b] = regexp (str, "f..", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1173 %! assert (a, {"foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1174 %! assert (b, {"", " bar"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1175 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1176 %! [a, b] = regexp (str, "b..", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1177 %! assert (a, {"bar"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1178 %! assert (b, {"foo ", ""});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1179 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1180 %! [a, b] = regexp (str, "x", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1181 %! assert (a, cell (1, 0));
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1182 %! assert (b, {"foo bar"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1183 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1184 %! [a, b] = regexp (str, "[o]+", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1185 %! assert (a, {"oo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1186 %! assert (b, {"f", " bar"});
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
1187
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1188 ## Test escape sequences are expanded even in single-quoted strings
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1189 %!assert (regexp ("\n", '\n'), 1)
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1190 %!assert (regexp ("\n", "\n"), 1)
20290
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
1191
29345
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1192 ## Test escape sequences are silently converted
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1193 %!test <*45407>
20290
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
1194 %! assert (regexprep ('s', 's', 'x\.y'), 'x.y');
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
1195 %! assert (regexprep ('s', '(s)', 'x\$1y'), 'x$1y');
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
1196 %! assert (regexprep ('s', '(s)', 'x\\$1y'), 'x\sy');
b6a59cc96bfa Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents: 20232
diff changeset
1197
29345
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1198 ## Test start-of-word / end-of-word patterns for Matlab compatibility
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1199 %!test <*59992>
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1200 %! assert (regexp ('foo!+bar', '\<\w'), [1, 6]);
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1201 %! assert (regexp ('foo!+bar', '.\>'), [3, 4, 8]);
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1202 %! assert (regexp ('foo!+bar\nbar!+foo', '.\>'), [3, 4, 8, 13, 14, 18]);
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1203 %! assert (regexp ('foo!+bar\nbar!+foo', '\<\w'), [1, 6, 10, 16]);
8f0d0d4690c0 Change regexp start-of-word/end-of-word behavior for Matlab compatiblity (bug #59992).
Rik <rik@octave.org>
parents: 29117
diff changeset
1204
31116
7d3bda173b63 regexp: Be more thorough in detecting named patterns.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31115
diff changeset
1205 ## Test "incomplete" named patterns
7d3bda173b63 regexp: Be more thorough in detecting named patterns.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31115
diff changeset
1206 %!assert <*62705> (regexpi ('<', '\(?<'), 1)
7d3bda173b63 regexp: Be more thorough in detecting named patterns.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31115
diff changeset
1207 %!assert <*62705> (regexpi ('<n>', '\(?<n\>'), 1)
7d3bda173b63 regexp: Be more thorough in detecting named patterns.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31115
diff changeset
1208 %!assert <*62705> (regexpi ('<n>', '\(?<n\>\)?'), 1)
7d3bda173b63 regexp: Be more thorough in detecting named patterns.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31115
diff changeset
1209 %!assert <62705> (regexpi ('<n>a', '\(?<n\>a\)?'), 1)
7d3bda173b63 regexp: Be more thorough in detecting named patterns.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31115
diff changeset
1210
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1211 ## Test input validation
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1212 %!error regexp ('string', 'tri', 'BadArg')
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1213 %!error regexp ('string')
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1214
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1215 */
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1216
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
1217 DEFUN (regexpi, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1218 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1219 @deftypefn {} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1220 @deftypefnx {} {[@dots{}] =} regexpi (@var{str}, @var{pat}, "@var{opt1}", @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1221
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1222 Case insensitive regular expression string matching.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1223
27537
7dc31256c5e4 Document that regexp* functions need UTF-8 encoded input (bug #35910).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27278
diff changeset
1224 Search for @var{pat} in UTF-8 encoded @var{str} and return the positions and
7dc31256c5e4 Document that regexp* functions need UTF-8 encoded input (bug #35910).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27278
diff changeset
1225 substrings of any matches, or empty values if there are none.
28961
d9d028b479ac doc: Use @code{} within alternate text for @xref,@pxref macros in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1226 @xref{XREFregexp,,@code{regexp}}, for details on the syntax of the search
d9d028b479ac doc: Use @code{} within alternate text for @xref,@pxref macros in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1227 pattern.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1228 @seealso{regexp}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1229 @end deftypefn */)
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1230 {
20821
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
1231 if (args.length () < 2)
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
1232 print_usage ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1233
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
1234 if (args(0).iscell () || args(1).iscell ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1235 return octcellregexp (args, (nargout > 0 ? nargout : 1), "regexpi", true);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1236 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1237 return octregexp (args, nargout, "regexpi", true);
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1238 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1239
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1240 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1241 ## segfault test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1242 %!assert (regexpi ("abcde", "."), [1,2,3,4,5])
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1243
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1244 ## Check that anchoring of pattern works correctly
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1245 %!assert (regexpi ('abcabc', '^ABC'), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1246 %!assert (regexpi ('abcabc', 'ABC$'), 4)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1247 %!assert (regexpi ('abcabc', '^ABC$'), zeros (1,0))
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1248
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1249 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1250 %! [s, e, te, m, t] = regexpi (' No Match ', 'f(.*)uck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1251 %! assert (s, zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1252 %! assert (e, zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1253 %! assert (te, cell (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1254 %! assert (m, cell (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1255 %! assert (t, cell (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1256
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1257 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1258 %! [s, e, te, m, t] = regexpi (' FiRetrUck ', 'f(.*)uck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1259 %! assert (s, 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1260 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1261 %! assert (te{1}, [3, 7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1262 %! assert (m{1}, 'FiRetrUck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1263 %! assert (t{1}{1}, 'iRetr');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1264
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1265 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1266 %! [s, e, te, m, t] = regexpi (' firetruck ', 'f(.*)uck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1267 %! assert (s, 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1268 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1269 %! assert (te{1}, [3, 7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1270 %! assert (m{1}, 'firetruck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1271 %! assert (t{1}{1}, 'iretr');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1272
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1273 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1274 %! [s, e, te, m, t] = regexpi ('ShoRt Test String', '\w*r\w*');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1275 %! assert (s, [1, 12]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1276 %! assert (e, [5, 17]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1277 %! assert (size (te), [1, 2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1278 %! assert (isempty (te{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1279 %! assert (isempty (te{2}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1280 %! assert (m{1}, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1281 %! assert (m{2}, 'String');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1282 %! assert (size (t), [1, 2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1283 %! assert (isempty (t{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1284 %! assert (isempty (t{2}));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1285
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1286 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1287 %! [s, e, te, m, t] = regexpi ('ShoRt Test String', '\w*r\w*', 'once');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1288 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1289 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1290 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1291 %! assert (m, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1292 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1293
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1294 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1295 %! [m, te, e, s, t] = regexpi ('ShoRt Test String', '\w*r\w*', 'once', 'match', 'tokenExtents', 'end', 'start', 'tokens');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1296 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1297 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1298 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1299 %! assert (m, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1300 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1301
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1302 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1303 %! [s, e, te, m, t, nm] = regexpi ('ShoRt Test String', '(?<word1>\w*t)\s*(?<word2>\w*t)');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1304 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1305 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1306 %! assert (size (te), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1307 %! assert (te{1}, [1,5; 7,10]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1308 %! assert (m{1}, 'ShoRt Test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1309 %! assert (size (t), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1310 %! assert (t{1}{1}, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1311 %! assert (t{1}{2}, 'Test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1312 %! assert (size (nm), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1313 %! assert (! isempty (fieldnames (nm)));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1314 %! assert (sort (fieldnames (nm)), {'word1';'word2'});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1315 %! assert (nm.word1, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1316 %! assert (nm.word2, 'Test');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1317
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1318 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1319 %! [nm, m, te, e, s, t] = regexpi ('ShoRt Test String', '(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1320 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1321 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1322 %! assert (size (te), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1323 %! assert (te{1}, [1,5; 7,10]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1324 %! assert (m{1}, 'ShoRt Test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1325 %! assert (size (t), [1, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1326 %! assert (t{1}{1}, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1327 %! assert (t{1}{2}, 'Test');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1328 %! assert (size (nm), [1, 1]);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20940
diff changeset
1329 %! assert (! isempty (fieldnames (nm)));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1330 %! assert (sort (fieldnames (nm)), {'word1';'word2'});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1331 %! assert (nm.word1, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1332 %! assert (nm.word2, 'Test');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1333
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1334 %!assert (regexpi ("abc\nabc", '.'), [1:7])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1335 %!assert (regexpi ("abc\nabc", '.', 'dotall'), [1:7])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1336 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1337 %! assert (regexpi ("abc\nabc", '(?s).'), [1:7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1338 %! assert (regexpi ("abc\nabc", '.', 'dotexceptnewline'), [1,2,3,5,6,7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1339 %! assert (regexpi ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1340
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1341 %!assert (regexpi ("caseCaSe", 'case'), [1, 5])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1342 %!assert (regexpi ("caseCaSe", 'case', "matchcase"), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1343 %!assert (regexpi ("caseCaSe", 'case', "ignorecase"), [1, 5])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1344 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1345 %! assert (regexpi ("caseCaSe", '(?-i)case'), 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1346 %! assert (regexpi ("caseCaSe", '(?i)case'), [1, 5]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1347
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1348 %!assert (regexpi ("abc\nabc", 'C$'), 7)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1349 %!assert (regexpi ("abc\nabc", 'C$', "stringanchors"), 7)
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1350 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1351 %! assert (regexpi ("abc\nabc", '(?-m)C$'), 7);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1352 %! assert (regexpi ("abc\nabc", 'C$', "lineanchors"), [3, 7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1353 %! assert (regexpi ("abc\nabc", '(?m)C$'), [3, 7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1354
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1355 %!assert (regexpi ("this word", 'S w'), 4)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1356 %!assert (regexpi ("this word", 'S w', 'literalspacing'), 4)
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1357 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1358 %! assert (regexpi ("this word", '(?-x)S w', 'literalspacing'), 4);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1359 %! assert (regexpi ("this word", 'S w', 'freespacing'), zeros (1,0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1360 %! assert (regexpi ("this word", '(?x)S w'), zeros (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1361
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1362 %!error regexpi ('string', 'tri', 'BadArg')
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1363 %!error regexpi ('string')
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1364
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1365 %!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1366 %! {6;[1,5,9];zeros(1, 0)})
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1367 %!assert (regexpi ({'asdfg-dfd', '-dfd-dfd-', 'qasfdfdaq'}, '-'),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1368 %! {6, [1,5,9], zeros(1,0)})
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1369 %!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1370 %! {6;[3,7];[1,9]})
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1371 %!assert (regexpi ('Strings', {'t', 's'}), {2, [1, 7]})
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
1372
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1373 %!assert (regexpi ("\n", '\n'), 1)
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1374 %!assert (regexpi ("\n", "\n"), 1)
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1375 */
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1376
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1377 static octave_value
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1378 octregexprep (const octave_value_list& args, const std::string& who)
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1379 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1380 int nargin = args.length ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1381
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1382 // Make sure we have string, pattern, replacement
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1383 const std::string buffer = args(0).string_value ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1384
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
1385 std::string pattern = args(1).string_value ();
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1386
22722
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
1387 // Rewrite pattern for PCRE
e6fac42c8d56 Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
Rik <rik@octave.org>
parents: 22599
diff changeset
1388 pattern = do_regexp_ptn_string_escapes (pattern, args(1).is_sq_string ());
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1389
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
1390 std::string replacement = args(2).string_value ();
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1391
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
1392 // Matlab compatibility.
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
1393 if (args(2).is_sq_string ())
15541
9db32cabeacf Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents: 15195
diff changeset
1394 replacement = do_regexp_rep_string_escapes (replacement);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1395
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1396 // Pack options excluding 'tokenize' and various output
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1397 // reordering strings into regexp arg list
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1398 octave_value_list regexpargs (nargin-3, octave_value ());
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1399
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1400 int len = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1401 for (int i = 3; i < nargin; i++)
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1402 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1403 const std::string opt = args(i).string_value ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1404 if (opt != "tokenize" && opt != "start" && opt != "end"
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1405 && opt != "tokenextents" && opt != "match" && opt != "tokens"
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1406 && opt != "names" && opt != "split" && opt != "warnings")
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1407 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1408 regexpargs(len++) = args(i);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1409 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1410 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1411 regexpargs.resize (len);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1412
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1413 regexp::opts options;
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1414 bool extra_args = false;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1415 parse_options (options, regexpargs, who, 0, extra_args);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1416
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1417 return regexp::replace (pattern, buffer, replacement, options, who);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1418 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1419
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
1420 DEFUN (regexprep, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1421 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1422 @deftypefn {} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1423 @deftypefnx {} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}, "@var{opt1}", @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1424 Replace occurrences of pattern @var{pat} in @var{string} with @var{repstr}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1425
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1426 The pattern is a regular expression as documented for @code{regexp}.
28961
d9d028b479ac doc: Use @code{} within alternate text for @xref,@pxref macros in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1427 @xref{XREFregexp,,@code{regexp}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1428
27537
7dc31256c5e4 Document that regexp* functions need UTF-8 encoded input (bug #35910).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27278
diff changeset
1429 All strings must be UTF-8 encoded.
7dc31256c5e4 Document that regexp* functions need UTF-8 encoded input (bug #35910).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27278
diff changeset
1430
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1431 The replacement string may contain @code{$i}, which substitutes for the ith
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1432 set of parentheses in the match string. For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1433
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1434 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1435 regexprep ("Bill Dunn", '(\w+) (\w+)', '$2, $1')
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1436 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1437
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1438 @noindent
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 22197
diff changeset
1439 returns @qcode{"Dunn, Bill"}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1440
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1441 Options in addition to those of @code{regexp} are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1442
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1443 @table @samp
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1444
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1445 @item once
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1446 Replace only the first occurrence of @var{pat} in the result.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1447
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1448 @item warnings
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1449 This option is present for compatibility but is ignored.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1450
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1451 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1452
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1453 Implementation Note: For compatibility with @sc{matlab}, escape sequences
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 28961
diff changeset
1454 in @var{pat} (e.g., @qcode{"@backslashchar{}n"} => newline) are expanded
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1455 even when @var{pat} has been defined with single quotes. To disable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1456 expansion use a second backslash before the escape sequence (e.g.,
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 28961
diff changeset
1457 "@backslashchar{}@backslashchar{}n") or use the @code{regexptranslate}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1458 function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1459 @seealso{regexp, regexpi, strrep}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1460 @end deftypefn */)
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1461 {
20821
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
1462 if (args.length () < 3)
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
1463 print_usage ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1464
20821
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
1465 octave_value_list retval;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1466
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
1467 if (args(0).iscell () || args(1).iscell () || args(2).iscell ())
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1468 {
20821
b169da150702 Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents: 20819
diff changeset
1469 Cell str, pat, rep;
6495
fd09c7e8c4c9 [project @ 2007-04-05 16:18:20 by dbateman]
dbateman
parents: 6361
diff changeset
1470 dim_vector dv0;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1471 dim_vector dv1 (1, 1);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1472
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
1473 if (args(0).iscell ())
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1474 str = args(0).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1475 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1476 str = Cell (args(0));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1477
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
1478 if (args(1).iscell ())
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1479 pat = args(1).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1480 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1481 pat = Cell (args(1));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1482
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
1483 if (args(2).iscell ())
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1484 rep = args(2).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1485 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1486 rep = Cell (args(2));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1487
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1488 dv0 = str.dims ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1489 if (pat.numel () != 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1490 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1491 dv1 = pat.dims ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1492 if (rep.numel () != 1 && dv1 != rep.dims ())
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1493 error ("regexprep: inconsistent cell array dimensions");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1494 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1495 else if (rep.numel () != 1)
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1496 dv1 = rep.dims ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1497
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1498 Cell ret (dv0);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1499 octave_value_list new_args = args;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1500
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1501 for (octave_idx_type i = 0; i < dv0.numel (); i++)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1502 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1503 new_args(0) = str(i);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1504 if (pat.numel () == 1)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1505 new_args(1) = pat(0);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1506 if (rep.numel () == 1)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1507 new_args(2) = rep(0);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1508
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1509 for (octave_idx_type j = 0; j < dv1.numel (); j++)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1510 {
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1511 if (pat.numel () != 1)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1512 new_args(1) = pat(j);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1513 if (rep.numel () != 1)
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1514 new_args(2) = rep(j);
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1515 new_args(0) = octregexprep (new_args, "regexprep");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1516 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1517
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1518 ret(i) = new_args(0);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1519 }
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20290
diff changeset
1520
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23573
diff changeset
1521 retval = (args(0).iscell () ? ovl (ret) : ovl (ret(0)));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1522 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1523 else
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1524 retval = octregexprep (args, "regexprep");
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1525
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1526 return retval;
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1527 }
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1528
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1529 /*
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1530 %!test # Replace with empty
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1531 %! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1532 %! t = regexprep (xml, '<[!?][^>]*>', '');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1533 %! assert (t, ' <tag v="hello">some stuff</tag>');
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1534
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1535 %!test # Replace with non-empty
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1536 %! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1537 %! t = regexprep (xml, '<[!?][^>]*>', '?');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1538 %! assert (t, '? <tag v="hello">some stuff?</tag>');
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1539
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1540 %!test # Check that 'tokenize' is ignored
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1541 %! xml = '<!-- This is some XML --> <tag v="hello">some stuff<!-- sample tag--></tag>';
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1542 %! t = regexprep (xml, '<[!?][^>]*>', '', 'tokenize');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1543 %! assert (t, ' <tag v="hello">some stuff</tag>');
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1544
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
1545 ## Test capture replacement
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1546 %!test
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7237
diff changeset
1547 %! data = "Bob Smith\nDavid Hollerith\nSam Jenkins";
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7237
diff changeset
1548 %! result = "Smith, Bob\nHollerith, David\nJenkins, Sam";
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1549 %! t = regexprep (data, '(?m)^(\w+)\s+(\w+)$', '$2, $1');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1550 %! assert (t, result);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1551
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
1552 ## Return the original if no match
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1553 %!assert (regexprep ('hello', 'world', 'earth'), 'hello')
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1554
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1555 ## Test emptymatch option
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1556 %!assert (regexprep ('World', '^', 'Hello '), 'World')
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1557 %!assert (regexprep ('World', '^', 'Hello ', 'emptymatch'), 'Hello World')
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1558
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1559 ## Test a general replacement
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1560 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_"), "a_b_c_d_e_f_g")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1561
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1562 ## Make sure replacements work at the beginning and end of string
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1563 %!assert (regexprep ("a[b]c{d}e-f=g", "a", "_"), "_[b]c{d}e-f=g")
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1564 %!assert (regexprep ("a[b]c{d}e-f=g", "g", "_"), "a[b]c{d}e-f=_")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1565
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1566 ## Test options "once" and "ignorecase"
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1567 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_", "once"),
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1568 %! "a_b]c{d}e-f=g")
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1569 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "ignorecase"),
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1570 %! "a_b_c_d_e_f_g")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1571
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1572 ## Option combinations
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1573 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "once", "ignorecase"),
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1574 %! "a_b]c{d}e-f=g")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1575
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1576 ## End conditions on replacement
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1577 %!assert (regexprep ("abc", "(b)", ".$1"), "a.bc")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1578 %!assert (regexprep ("abc", "(b)", "$1"), "abc")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1579 %!assert (regexprep ("abc", "(b)", "$1."), "ab.c")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1580 %!assert (regexprep ("abc", "(b)", "$1.."), "ab..c")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1581
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1582 ## Test cell array arguments
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1583 %!assert (regexprep ("abc", {"b","a"}, "?"), "??c")
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1584 %!assert (regexprep ({"abc","cba"}, "b", "?"), {"a?c","c?a"})
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1585 %!assert (regexprep ({"abc","cba"}, {"b","a"}, {"?","!"}), {"!?c","c?!"})
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1586
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1587 ## Nasty lookbehind expression
21575
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
1588 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
1589 %! warning ("off", "Octave:regexp-lookbehind-limit", "local");
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1590 %! assert (regexprep ('x^(-1)+y(-1)+z(-1)=0', '(?<=[a-z]+)\(\-[1-9]*\)',
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1591 %! '_minus1'),'x^(-1)+y_minus1+z_minus1=0');
14543
e47d929fde8f process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents: 14536
diff changeset
1592
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1593 ## Verify escape sequences in pattern
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1594 %!assert (regexprep ("\n", '\n', "X"), "X")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1595 %!assert (regexprep ("\n", "\n", "X"), "X")
24606
4a4a8b2a5bf2 Test for incorrect regexprep on ARM platforms (bug #52810).
Colin Macdonald <cbm@m.fsf.org>
parents: 23816
diff changeset
1596
24751
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1597 ## Verify NULLs in pattern and replacement string
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1598 %!assert (regexprep ("A\0A", "\0", ","), "A,A")
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1599 %!assert (regexprep ("A\0A", '\0', ","), "A,A")
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1600 %!assert (regexprep ("A,A", "A", "B\0B"), "B\0B,B\0B")
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1601 %!assert (regexprep ("A,A", "A", 'B\0B'), "B\0B,B\0B")
6e670c58c6f0 Expand octal sequences in regexprep replacement string for Matlab compatibility.
Rik <rik@octave.org>
parents: 24741
diff changeset
1602
24606
4a4a8b2a5bf2 Test for incorrect regexprep on ARM platforms (bug #52810).
Colin Macdonald <cbm@m.fsf.org>
parents: 23816
diff changeset
1603 ## Empty matches were broken on ARM architecture
4a4a8b2a5bf2 Test for incorrect regexprep on ARM platforms (bug #52810).
Colin Macdonald <cbm@m.fsf.org>
parents: 23816
diff changeset
1604 %!test <*52810>
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1605 %! assert (strcmp (regexprep ("\nabc", "^(\t*)(abc)$", "$1$2", "lineanchors"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
1606 %! "\nabc"));
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1607 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1608
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31483
diff changeset
1609 OCTAVE_END_NAMESPACE(octave)