Mercurial > jwe > octave
annotate libinterp/corefcn/regexp.cc @ 20232:a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
* liboctave/array/Array.h (Array::length): deprecate for ::numel.
* liboctave/array/Sparse.h (Sparse::length): deprecate for ::numel.
* libgui/graphics/QtHandlesUtils.cc, libgui/src/octave-qt-link.cc,
libinterp/corefcn/Cell.cc, libinterp/corefcn/__contourc__.cc,
libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc,
libinterp/corefcn/cellfun.cc, libinterp/corefcn/daspk.cc,
libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc,
libinterp/corefcn/data.cc, libinterp/corefcn/filter.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gl-render.cc,
libinterp/corefcn/gl-render.h, libinterp/corefcn/graphics.cc,
libinterp/corefcn/graphics.in.h, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/ls-oct-ascii.h, libinterp/corefcn/lsode.cc,
libinterp/corefcn/matrix_type.cc, libinterp/corefcn/oct-hist.cc,
libinterp/corefcn/oct-map.cc, libinterp/corefcn/oct-map.h,
libinterp/corefcn/oct-obj.h, libinterp/corefcn/oct-stream.cc,
libinterp/corefcn/oct-stream.h, libinterp/corefcn/pr-output.cc,
libinterp/corefcn/quadcc.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/strfns.cc,
libinterp/corefcn/sub2ind.cc, libinterp/corefcn/symtab.h,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/tsearch.cc,
libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc,
libinterp/corefcn/variables.cc, libinterp/corefcn/xdiv.cc,
libinterp/corefcn/xpow.cc, libinterp/dldfcn/__glpk__.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__magick_read__.cc,
libinterp/dldfcn/audiodevinfo.cc, libinterp/dldfcn/ccolamd.cc,
libinterp/dldfcn/colamd.cc, libinterp/octave-value/ov-cell.cc,
libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-class.h,
libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc,
libinterp/octave-value/ov-perm.cc, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov.cc,
libinterp/operators/op-int.h, libinterp/parse-tree/pt-pr-code.cc,
liboctave/array/Array-util.cc, liboctave/array/Array.cc,
liboctave/array/CColVector.cc, liboctave/array/CDiagMatrix.cc,
liboctave/array/CMatrix.cc, liboctave/array/CRowVector.cc,
liboctave/array/DiagArray2.cc, liboctave/array/DiagArray2.h,
liboctave/array/MArray.cc, liboctave/array/PermMatrix.cc,
liboctave/array/PermMatrix.h, liboctave/array/Sparse.cc,
liboctave/array/boolMatrix.cc, liboctave/array/chMatrix.cc,
liboctave/array/chNDArray.cc, liboctave/array/dColVector.cc,
liboctave/array/dDiagMatrix.cc, liboctave/array/dMatrix.cc,
liboctave/array/dRowVector.cc, liboctave/array/fCColVector.cc,
liboctave/array/fCDiagMatrix.cc, liboctave/array/fCMatrix.cc,
liboctave/array/fCRowVector.cc, liboctave/array/fColVector.cc,
liboctave/array/fDiagMatrix.cc, liboctave/array/fMatrix.cc,
liboctave/array/fRowVector.cc, liboctave/array/idx-vector.cc,
liboctave/array/intNDArray.cc, liboctave/numeric/CmplxCHOL.cc,
liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxQR.cc,
liboctave/numeric/DASPK.cc, liboctave/numeric/DASRT.cc,
liboctave/numeric/DASSL.cc, liboctave/numeric/LSODE.cc,
liboctave/numeric/ODES.cc, liboctave/numeric/ODES.h,
liboctave/numeric/base-dae.h, liboctave/numeric/base-lu.cc,
liboctave/numeric/dbleCHOL.cc, liboctave/numeric/dbleLU.cc,
liboctave/numeric/dbleQR.cc, liboctave/numeric/eigs-base.cc,
liboctave/numeric/fCmplxCHOL.cc, liboctave/numeric/fCmplxLU.cc,
liboctave/numeric/fCmplxQR.cc, liboctave/numeric/floatCHOL.cc,
liboctave/numeric/floatLU.cc, liboctave/numeric/floatQR.cc,
liboctave/numeric/lo-specfun.cc, liboctave/numeric/oct-rand.cc,
liboctave/numeric/oct-spparms.cc, liboctave/numeric/sparse-base-chol.cc,
liboctave/operators/mx-inlines.cc, liboctave/system/file-ops.cc,
liboctave/util/glob-match.h, liboctave/util/kpse.cc,
liboctave/util/lo-regexp.cc, liboctave/util/oct-glob.cc,
liboctave/util/pathsearch.cc, liboctave/util/str-vec.cc,
liboctave/util/str-vec.h, liboctave/util/url-transfer.cc: replace all usage
of Array::length() and Sparse::length() with ::numel().
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Sat, 30 May 2015 03:14:07 +0100 |
parents | f2bc7d23295d |
children | b6a59cc96bfa |
rev | line source |
---|---|
5582 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19403
diff
changeset
|
3 Copyright (C) 2005-2015 David Bateman |
11523 | 4 Copyright (C) 2002-2005 Paul Kienzle |
7016 | 5 |
6 This file is part of Octave. | |
5582 | 7 |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5582 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5582 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
28 #include <list> |
5765 | 29 #include <sstream> |
30 | |
5582 | 31 #include <pcre.h> |
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" |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
42 #include "gripes.h" |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
43 #include "oct-map.h" |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
44 #include "oct-obj.h" |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
45 #include "utils.h" |
5785 | 46 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
47 // 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
|
48 // 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
|
49 // 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
|
50 // 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
|
51 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
52 static std::string |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
53 do_regexp_ptn_string_escapes (const std::string& s) |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
54 { |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
55 std::string retval; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
56 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
57 size_t i = 0; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
58 size_t j = 0; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
59 size_t len = s.length (); |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
60 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
61 retval.resize (len); |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
62 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
63 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
|
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 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
|
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 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
|
68 { |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
69 case 'b': // backspace |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
70 retval[i] = '\b'; |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
71 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
72 |
16918
ab46b5c77669
Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents:
16816
diff
changeset
|
73 // Translate \< and \> to PCRE word boundary |
ab46b5c77669
Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents:
16816
diff
changeset
|
74 case '<': // begin word boundary |
ab46b5c77669
Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents:
16816
diff
changeset
|
75 case '>': // end word boundary |
ab46b5c77669
Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents:
16816
diff
changeset
|
76 retval[i] = '\\'; |
ab46b5c77669
Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents:
16816
diff
changeset
|
77 retval[++i] = 'b'; |
ab46b5c77669
Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents:
16816
diff
changeset
|
78 break; |
ab46b5c77669
Fix word boundary handling in regexp pattern (bug #38778)
Mike Miller <mtmiller@ieee.org>
parents:
16816
diff
changeset
|
79 |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
80 case 'o': // octal input |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
81 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
82 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
|
83 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
84 bool brace = false; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
85 if (! bad_esc_seq && s[++j] == '{') |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
86 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
87 brace = true; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
88 j++; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
89 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
90 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
91 int tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
92 size_t k; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
93 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
|
94 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
95 int digit = s[k] - '0'; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
96 if (digit < 0 || digit > 7) |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
97 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
98 tmpi <<= 3; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
99 tmpi += digit; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
100 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
101 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
|
102 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
103 bad_esc_seq = true; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
104 tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
105 warning ("malformed octal escape sequence '\\o' --\ |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
106 converting to '\\0'"); |
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 retval[i] = tmpi; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
109 j = k - 1; |
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 } |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
112 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
113 default: // pass escape sequence through |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
114 retval[i] = '\\'; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
115 retval[++i] = s[j]; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
116 break; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
117 } |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
118 } |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
119 else |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
120 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
121 retval[i] = s[j]; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
122 } |
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 i++; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
125 j++; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
126 } |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
127 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
128 retval.resize (i); |
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 return retval; |
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 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
133 static std::string |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
134 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
|
135 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
136 std::string retval; |
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 size_t i = 0; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
139 size_t j = 0; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
140 size_t len = s.length (); |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
141 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
142 retval.resize (len); |
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 while (j < len) |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
145 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
146 if (s[j] == '\\' && j+1 < len) |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
147 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
148 switch (s[++j]) |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
149 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
150 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
|
151 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
|
152 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
153 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
154 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
|
155 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
|
156 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
157 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
158 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
|
159 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
|
160 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
161 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
162 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
|
163 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
|
164 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
165 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
166 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
|
167 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
|
168 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
169 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
170 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
|
171 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
|
172 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
173 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
174 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
|
175 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
|
176 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
177 |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
178 case 'o': // octal input |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
179 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
180 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
|
181 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
182 bool brace = false; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
183 if (! bad_esc_seq && s[++j] == '{') |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
184 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
185 brace = true; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
186 j++; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
187 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
188 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
189 int tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
190 size_t k; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
191 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
|
192 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
193 int digit = s[k] - '0'; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
194 if (digit < 0 || digit > 7) |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
195 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
196 tmpi <<= 3; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
197 tmpi += digit; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
198 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
199 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
|
200 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
201 warning ("malformed octal escape sequence '\\o' --\ |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
202 converting to '\\0'"); |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
203 tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
204 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
205 retval[i] = tmpi; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
206 j = k - 1; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
207 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
208 } |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
209 |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
210 case 'x': // hex input |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
211 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
212 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
|
213 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
214 bool brace = false; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
215 if (! bad_esc_seq && s[++j] == '{') |
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 brace = true; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
218 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 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
221 int tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
222 size_t k; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
223 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
|
224 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
225 if (! isxdigit (s[k])) |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
226 break; |
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 tmpi <<= 4; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
229 int digit = s[k]; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
230 if (digit >= 'a') |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
231 tmpi += digit - 'a' + 10; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
232 else if (digit >= 'A') |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
233 tmpi += digit - 'A' + 10; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
234 else |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
235 tmpi += digit - '0'; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
236 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
237 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
|
238 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
239 warning ("malformed hex escape sequence '\\x' --\ |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
240 converting to '\\0'"); |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
241 tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
242 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
243 retval[i] = tmpi; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
244 j = k - 1; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
245 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
246 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
247 |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
248 default: // pass escape sequence through |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
249 retval[i] = '\\'; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
250 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
|
251 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
252 } |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
253 } |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
254 else |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
255 { |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
256 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
|
257 } |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
258 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
259 i++; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
260 j++; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
261 } |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
262 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
263 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
|
264 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
265 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
|
266 } |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
267 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
268 static void |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
269 parse_options (regexp::opts& options, const octave_value_list& args, |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
270 const std::string& who, int skip, bool& extra_args) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
271 { |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
272 int nargin = args.length (); |
5582 | 273 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
274 extra_args = false; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
275 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
276 for (int i = skip; i < nargin; i++) |
5582 | 277 { |
19403
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
278 std::string str; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
279 |
19403
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
280 if (args(i).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
281 str = args(i).string_value (); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
282 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
283 { |
19403
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
284 error ("%s: optional arguments must be strings", who.c_str ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
285 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
286 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
287 |
5582 | 288 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
|
289 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
290 if (str.find ("once", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
291 options.once (true); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
292 else if (str.find ("matchcase", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
293 options.case_insensitive (false); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
294 else if (str.find ("ignorecase", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
295 options.case_insensitive (true); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
296 else if (str.find ("dotall", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
297 options.dotexceptnewline (false); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
298 else if (str.find ("stringanchors", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
299 options.lineanchors (false); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
300 else if (str.find ("literalspacing", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
301 options.freespacing (false); |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
302 else if (str.find ("noemptymatch", 0) == 0) |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
303 options.emptymatch (false); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
304 else if (str.find ("dotexceptnewline", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
305 options.dotexceptnewline (true); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
306 else if (str.find ("lineanchors", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
307 options.lineanchors (true); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
308 else if (str.find ("freespacing", 0) == 0) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
309 options.freespacing (true); |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
310 else if (str.find ("emptymatch", 0) == 0) |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
311 options.emptymatch (true); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
312 else if (str.find ("start", 0) == 0 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
313 || str.find ("end", 0) == 0 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
314 || str.find ("tokenextents", 0) == 0 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
315 || str.find ("match", 0) == 0 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
316 || str.find ("tokens", 0) == 0 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
317 || str.find ("names", 0) == 0 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
318 || str.find ("split", 0) == 0) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
319 extra_args = true; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
320 else |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
321 error ("%s: unrecognized option", who.c_str ()); |
5582 | 322 } |
5785 | 323 } |
5582 | 324 |
5785 | 325 static octave_value_list |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
326 octregexp (const octave_value_list &args, int nargout, |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
327 const std::string &who, bool case_insensitive = false) |
5785 | 328 { |
329 octave_value_list retval; | |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
330 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
331 int nargin = args.length (); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
332 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
333 // Make sure we have string, pattern |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
334 const std::string buffer = args(0).string_value (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
335 if (error_state) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
336 return retval; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
337 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
338 std::string pattern = args(1).string_value (); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
339 if (error_state) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
340 return 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
|
341 // 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
|
342 if (args(1).is_sq_string ()) |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
343 pattern = do_regexp_ptn_string_escapes (pattern); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
344 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
345 regexp::opts options; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
346 options.case_insensitive (case_insensitive); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
347 bool extra_options = false; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
348 parse_options (options, args, who, 2, extra_options); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
349 if (error_state) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
350 return retval; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
351 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
352 regexp::match_data rx_lst = regexp_match (pattern, buffer, options, who); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
353 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
354 string_vector named_pats = rx_lst.named_patterns (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
355 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
356 size_t sz = rx_lst.size (); |
5785 | 357 |
358 if (! error_state) | |
359 { | |
360 // Converted the linked list in the correct form for the return values | |
361 | |
362 octave_idx_type i = 0; | |
11045
cc3aad9dd3ef
dispatch.cc, fltk_backend.cc, regexp.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11032
diff
changeset
|
363 octave_scalar_map nmap; |
12464
dfeea9cae79e
require PCRE to build Octave
John W. Eaton <jwe@octave.org>
parents:
12462
diff
changeset
|
364 |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
365 retval.resize (7); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
366 |
5785 | 367 if (sz == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
368 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14543
diff
changeset
|
369 string_vector named_tokens = rx_lst.begin ()->named_tokens (); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
370 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20211
diff
changeset
|
371 for (int j = 0; j < named_pats.numel (); j++) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
372 nmap.assign (named_pats(j), named_tokens(j)); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
373 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
374 retval(5) = nmap; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
375 } |
5785 | 376 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
377 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20211
diff
changeset
|
378 for (int j = 0; j < named_pats.numel (); j++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
379 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
380 Cell tmp (dim_vector (1, sz)); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
381 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
382 i = 0; |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
383 for (regexp::match_data::const_iterator p = rx_lst.begin (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
384 p != rx_lst.end (); p++) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
385 { |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
386 string_vector named_tokens = p->named_tokens (); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
387 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
388 tmp(i++) = named_tokens(j); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
389 } |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
390 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
391 nmap.assign (named_pats(j), octave_value (tmp)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
392 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
393 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
394 retval(5) = nmap; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
395 } |
5785 | 396 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
397 if (options.once ()) |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
398 { |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
399 regexp::match_data::const_iterator p = rx_lst.begin (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
400 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
401 retval(4) = sz ? p->tokens () : Cell (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
402 retval(3) = sz ? p->match_string () : std::string (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
403 retval(2) = sz ? p->token_extents () : Matrix (); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
404 |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
405 if (sz) |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
406 { |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
407 double start = p->start (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
408 double end = p->end (); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
409 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
410 Cell split (dim_vector (1, 2)); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
411 split(0) = buffer.substr (0, start-1); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
412 split(1) = buffer.substr (end); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
413 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
414 retval(6) = split; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
415 retval(1) = end; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
416 retval(0) = start; |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
417 } |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
418 else |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
419 { |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
420 retval(6) = buffer; |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
421 retval(1) = Matrix (); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
422 retval(0) = Matrix (); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
423 } |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
424 } |
7893
eb9ccb44ea41
make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
425 else |
eb9ccb44ea41
make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
426 { |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
427 Cell tokens (dim_vector (1, sz)); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
428 Cell match_string (dim_vector (1, sz)); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
429 Cell token_extents (dim_vector (1, sz)); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
430 NDArray end (dim_vector (1, sz)); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
431 NDArray start (dim_vector (1, sz)); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
432 Cell split (dim_vector (1, sz+1)); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
433 size_t sp_start = 0; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
434 |
7893
eb9ccb44ea41
make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
435 i = 0; |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
436 for (regexp::match_data::const_iterator p = rx_lst.begin (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
437 p != rx_lst.end (); p++) |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
438 { |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
439 double s = p->start (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
440 double e = p->end (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
441 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
442 string_vector tmp = p->tokens (); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20211
diff
changeset
|
443 tokens(i) = Cell (dim_vector (1, tmp.numel ()), tmp); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
444 match_string(i) = p->match_string (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
445 token_extents(i) = p->token_extents (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
446 end(i) = e; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
447 start(i) = s; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
448 split(i) = buffer.substr (sp_start, s-sp_start-1); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
449 sp_start = e; |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
450 i++; |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
451 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
452 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
453 split(i) = buffer.substr (sp_start); |
5785 | 454 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
455 retval(6) = split; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
456 retval(4) = tokens; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
457 retval(3) = match_string; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
458 retval(2) = token_extents; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
459 retval(1) = end; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
460 retval(0) = start; |
7893
eb9ccb44ea41
make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
461 } |
5582 | 462 |
463 // Alter the order of the output arguments | |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
464 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
465 if (extra_options) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
466 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
467 int n = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
468 octave_value_list new_retval; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
469 new_retval.resize (nargout); |
5582 | 470 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
471 OCTAVE_LOCAL_BUFFER (int, arg_used, 6); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
472 for (int j = 0; j < 6; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
473 arg_used[j] = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
474 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
475 for (int j = 2; j < nargin; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
476 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
477 int k = 0; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
478 std::string str = args(j).string_value (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
479 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
|
480 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
481 if (str.find ("once", 0) == 0 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
482 || str.find ("stringanchors", 0) == 0 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
483 || str.find ("lineanchors", 0) == 0 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
484 || str.find ("matchcase", 0) == 0 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
485 || str.find ("ignorecase", 0) == 0 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
486 || str.find ("dotall", 0) == 0 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
487 || str.find ("dotexceptnewline", 0) == 0 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
488 || str.find ("literalspacing", 0) == 0 |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
489 || str.find ("freespacing", 0) == 0 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
490 || str.find ("noemptymatch", 0) == 0 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
491 || str.find ("emptymatch", 0) == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
492 continue; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
493 else if (str.find ("start", 0) == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
494 k = 0; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
495 else if (str.find ("end", 0) == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
496 k = 1; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
497 else if (str.find ("tokenextents", 0) == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
498 k = 2; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
499 else if (str.find ("match", 0) == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
500 k = 3; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
501 else if (str.find ("tokens", 0) == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
502 k = 4; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
503 else if (str.find ("names", 0) == 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
504 k = 5; |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
505 else if (str.find ("split", 0) == 0) |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
506 k = 6; |
5582 | 507 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
508 new_retval(n++) = retval(k); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
509 arg_used[k] = true; |
5582 | 510 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
511 if (n == nargout) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
512 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
513 } |
5582 | 514 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
515 // Fill in the rest of the arguments |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
516 if (n < nargout) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
517 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
518 for (int j = 0; j < 6; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
519 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
520 if (! arg_used[j]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
521 new_retval(n++) = retval(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
522 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
523 } |
5582 | 524 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
525 retval = new_retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
526 } |
5582 | 527 } |
528 | |
529 return retval; | |
530 } | |
531 | |
6361 | 532 static octave_value_list |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
533 octcellregexp (const octave_value_list &args, int nargout, |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
534 const std::string &who, bool case_insensitive = false) |
6361 | 535 { |
536 octave_value_list retval; | |
537 | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
538 if (args(0).is_cell ()) |
6361 | 539 { |
540 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout); | |
541 octave_value_list new_args = args; | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
542 Cell cellstr = args(0).cell_value (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
543 if (args(1).is_cell ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
544 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
545 Cell cellpat = args(1).cell_value (); |
6361 | 546 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
547 if (cellpat.numel () == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
548 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
549 for (int j = 0; j < nargout; j++) |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
550 newretval[j].resize (cellstr.dims ()); |
6361 | 551 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
552 new_args(1) = cellpat(0); |
6361 | 553 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
554 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
|
555 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
556 new_args(0) = cellstr(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
557 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
|
558 case_insensitive); |
6361 | 559 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
560 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
561 break; |
6361 | 562 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
563 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
564 newretval[j](i) = tmp(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
565 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
566 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
567 else if (cellstr.numel () == 1) |
10154
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 for (int j = 0; j < nargout; j++) |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
570 newretval[j].resize (cellpat.dims ()); |
6361 | 571 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
572 new_args(0) = cellstr(0); |
6361 | 573 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
574 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
|
575 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
576 new_args(1) = cellpat(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
577 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
|
578 case_insensitive); |
6361 | 579 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
580 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
581 break; |
6361 | 582 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
583 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
584 newretval[j](i) = tmp(j); |
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 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
587 else if (cellstr.numel () == cellpat.numel ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
588 { |
6361 | 589 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
590 if (cellstr.dims () != cellpat.dims ()) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
591 error ("%s: inconsistent cell array dimensions", who.c_str ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
592 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
593 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
594 for (int j = 0; j < nargout; j++) |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
595 newretval[j].resize (cellstr.dims ()); |
6361 | 596 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
597 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
|
598 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
599 new_args(0) = cellstr(i); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
600 new_args(1) = cellpat(i); |
6361 | 601 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
602 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
|
603 case_insensitive); |
6361 | 604 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
605 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
606 break; |
6361 | 607 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
608 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
609 newretval[j](i) = tmp(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
610 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
611 } |
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 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
614 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
|
615 } |
6361 | 616 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
617 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
618 for (int j = 0; j < nargout; j++) |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
619 newretval[j].resize (cellstr.dims ()); |
6361 | 620 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
621 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
|
622 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
623 new_args(0) = cellstr(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
624 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
|
625 case_insensitive); |
6361 | 626 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
627 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
628 break; |
6361 | 629 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
630 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
631 newretval[j](i) = tmp(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
632 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
633 } |
6361 | 634 |
635 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
636 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
637 retval(j) = octave_value (newretval[j]); |
6361 | 638 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
639 else if (args(1).is_cell ()) |
6361 | 640 { |
641 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout); | |
642 octave_value_list new_args = args; | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
643 Cell cellpat = args(1).cell_value (); |
6361 | 644 |
645 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
|
646 newretval[j].resize (cellpat.dims ()); |
6361 | 647 |
648 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
|
649 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
650 new_args(1) = cellpat(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
651 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
|
652 case_insensitive); |
6361 | 653 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
654 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
655 break; |
6361 | 656 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
657 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
658 newretval[j](i) = tmp(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
659 } |
6361 | 660 |
661 if (!error_state) | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
662 { |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
663 for (int j = 0; j < nargout; j++) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
664 retval(j) = octave_value (newretval[j]); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
665 } |
6361 | 666 } |
667 else | |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
668 retval = octregexp (args, nargout, who, case_insensitive); |
6361 | 669 |
670 return retval; | |
671 | |
672 } | |
673 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
674 DEFUN (regexp, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
675 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
676 @deftypefn {Built-in Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexp (@var{str}, @var{pat})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
677 @deftypefnx {Built-in Function} {[@dots{}] =} regexp (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
678 Regular expression string matching.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
679 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
680 Search for @var{pat} in @var{str} and return the positions and substrings of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
681 any matches, or empty values if there are none.\n\ |
5582 | 682 \n\ |
683 The matched pattern @var{pat} can include any of the standard regex\n\ | |
684 operators, including:\n\ | |
685 \n\ | |
686 @table @code\n\ | |
687 @item .\n\ | |
688 Match any character\n\ | |
10840 | 689 \n\ |
5582 | 690 @item * + ? @{@}\n\ |
691 Repetition operators, representing\n\ | |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
692 \n\ |
5582 | 693 @table @code\n\ |
694 @item *\n\ | |
695 Match zero or more times\n\ | |
10840 | 696 \n\ |
5582 | 697 @item +\n\ |
698 Match one or more times\n\ | |
10840 | 699 \n\ |
5582 | 700 @item ?\n\ |
701 Match zero or one times\n\ | |
10840 | 702 \n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
703 @item @{@var{n}@}\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
704 Match exactly @var{n} times\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
705 \n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
706 @item @{@var{n},@}\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
707 Match @var{n} or more times\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
708 \n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
709 @item @{@var{m},@var{n}@}\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
710 Match between @var{m} and @var{n} times\n\ |
5582 | 711 @end table\n\ |
10840 | 712 \n\ |
5582 | 713 @item [@dots{}] [^@dots{}]\n\ |
10840 | 714 \n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
715 List operators. The pattern will match any character listed between \"[\"\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
716 and \"]\". If the first character is \"^\" then the pattern is inverted and\n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
717 any character except those listed between brackets will match.\n\ |
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
718 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
719 Escape sequences defined below can also be used inside list operators. For\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
720 example, a template for a floating point number might be @code{[-+.\\d]+}.\n\ |
10840 | 721 \n\ |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
722 @item () (?:)\n\ |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
723 Grouping operator. The first form, parentheses only, also creates a token.\n\ |
10840 | 724 \n\ |
5582 | 725 @item |\n\ |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
726 Alternation operator. Match one of a choice of regular expressions. The\n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
727 alternatives must be delimited by the grouping operator @code{()} above.\n\ |
10840 | 728 \n\ |
5582 | 729 @item ^ $\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
730 Anchoring operators. Requires pattern to occur at the start (@code{^}) or\n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
731 end (@code{$}) of the string.\n\ |
5582 | 732 @end table\n\ |
733 \n\ | |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15039
diff
changeset
|
734 In addition, the following escaped characters have special meaning.\n\ |
5582 | 735 \n\ |
736 @table @code\n\ | |
16919
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
737 \n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
738 @item \\d\n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
739 Match any digit\n\ |
10840 | 740 \n\ |
16919
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
741 @item \\D\n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
742 Match any non-digit\n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
743 \n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
744 @item \\s\n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
745 Match any whitespace character\n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
746 \n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
747 @item \\S\n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
748 Match any non-whitespace character\n\ |
10840 | 749 \n\ |
5582 | 750 @item \\w\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
751 Match any word character\n\ |
10840 | 752 \n\ |
5582 | 753 @item \\W\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
754 Match any non-word character\n\ |
10840 | 755 \n\ |
5582 | 756 @item \\<\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
757 Match the beginning of a word\n\ |
10840 | 758 \n\ |
5582 | 759 @item \\>\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
760 Match the end of a word\n\ |
10840 | 761 \n\ |
16919
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
762 @item \\B\n\ |
908b4956cbfd
doc: remove '\b' from list of special regexp sequences (bug #38778).
Rik <rik@octave.org>
parents:
16918
diff
changeset
|
763 Match within a word\n\ |
5582 | 764 @end table\n\ |
765 \n\ | |
20041
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
766 Implementation Note: For compatibility with @sc{matlab}, escape sequences\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
767 in @var{pat} (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are expanded\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
768 even when @var{pat} has been defined with single quotes. To disable\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
769 expansion use a second backslash before the escape sequence (e.g.,\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
770 \"@xbackslashchar{}@xbackslashchar{}n\") or use the @code{regexptranslate}\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
771 function.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15039
diff
changeset
|
772 \n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
773 The outputs of @code{regexp} default to the order given below\n\ |
5582 | 774 \n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
775 @table @var\n\ |
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
776 @item s\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
777 The start indices of each matching substring\n\ |
5582 | 778 \n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
779 @item e\n\ |
5582 | 780 The end indices of each matching substring\n\ |
781 \n\ | |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
782 @item te\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
783 The extents of each matched token surrounded by @code{(@dots{})} in\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
784 @var{pat}\n\ |
5582 | 785 \n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
786 @item m\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
787 A cell array of the text of each match\n\ |
5582 | 788 \n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
789 @item t\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
790 A cell array of the text of each token matched\n\ |
5582 | 791 \n\ |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
792 @item nm\n\ |
5582 | 793 A structure containing the text of each matched named token, with the name\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
794 being used as the fieldname. A named token is denoted by\n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
795 @code{(?<name>@dots{})}.\n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13759
diff
changeset
|
796 \n\ |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
797 @item sp\n\ |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
798 A cell array of the text not returned by match, i.e., what remains if you\n\ |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
799 split the string based on @var{pat}.\n\ |
5582 | 800 @end table\n\ |
801 \n\ | |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
802 Particular output arguments, or the order of the output arguments, can be\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
803 selected by additional @var{opt} arguments. These are strings and the\n\ |
5582 | 804 correspondence between the output arguments and the optional argument\n\ |
805 are\n\ | |
806 \n\ | |
807 @multitable @columnfractions 0.2 0.3 0.3 0.2\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
808 @item @tab @qcode{'start'} @tab @var{s} @tab\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
809 @item @tab @qcode{'end'} @tab @var{e} @tab\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
810 @item @tab @qcode{'tokenExtents'} @tab @var{te} @tab\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
811 @item @tab @qcode{'match'} @tab @var{m} @tab\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
812 @item @tab @qcode{'tokens'} @tab @var{t} @tab\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
813 @item @tab @qcode{'names'} @tab @var{nm} @tab\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
814 @item @tab @qcode{'split'} @tab @var{sp} @tab\n\ |
5582 | 815 @end multitable\n\ |
816 \n\ | |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
817 Additional arguments are summarized below.\n\ |
5779 | 818 \n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
819 @table @samp\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
820 @item once\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
821 Return only the first occurrence of the pattern.\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
822 \n\ |
5779 | 823 @item matchcase\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
824 Make the matching case sensitive. (default)\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
825 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
826 Alternatively, use (?-i) in the pattern.\n\ |
10840 | 827 \n\ |
5779 | 828 @item ignorecase\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
829 Ignore case when matching the pattern to the string.\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
830 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
831 Alternatively, use (?i) in the pattern.\n\ |
10840 | 832 \n\ |
5779 | 833 @item stringanchors\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12464
diff
changeset
|
834 Match the anchor characters at the beginning and end of the string.\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
835 (default)\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
836 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
837 Alternatively, use (?-m) in the pattern.\n\ |
10840 | 838 \n\ |
5779 | 839 @item lineanchors\n\ |
840 Match the anchor characters at the beginning and end of the line.\n\ | |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
841 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
842 Alternatively, use (?m) in the pattern.\n\ |
10840 | 843 \n\ |
5779 | 844 @item dotall\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
845 The pattern @code{.} matches all characters including the newline character.\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
846 (default)\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
847 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
848 Alternatively, use (?s) in the pattern.\n\ |
10840 | 849 \n\ |
5779 | 850 @item dotexceptnewline\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
851 The pattern @code{.} matches all characters except the newline character.\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
852 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
853 Alternatively, use (?-s) in the pattern.\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
854 \n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
855 @item literalspacing\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
856 All characters in the pattern, including whitespace, are significant and are\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
857 used in pattern matching. (default)\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
858 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
859 Alternatively, use (?-x) in the pattern.\n\ |
10840 | 860 \n\ |
5779 | 861 @item freespacing\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
862 The pattern may include arbitrary whitespace and also comments beginning with\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
863 the character @samp{#}.\n\ |
10840 | 864 \n\ |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
865 Alternatively, use (?x) in the pattern.\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
866 \n\ |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
867 @item noemptymatch\n\ |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
868 Zero-length matches are not returned. (default)\n\ |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
869 \n\ |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
870 @item emptymatch\n\ |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
871 Return zero-length matches.\n\ |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
872 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
873 @code{regexp ('a', 'b*', 'emptymatch')} returns @code{[1 2]} because there\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
874 are zero or more @qcode{'b'} characters at positions 1 and end-of-string.\n\ |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
875 \n\ |
5779 | 876 @end table\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
877 @seealso{regexpi, strfind, regexprep}\n\ |
5582 | 878 @end deftypefn") |
879 { | |
6361 | 880 octave_value_list retval; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
881 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
882 int nargin = args.length (); |
6361 | 883 |
884 if (nargin < 2) | |
885 print_usage (); | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
886 else if (args(0).is_cell () || args(1).is_cell ()) |
14454
2232931f2494
Return regexp output when input is a cellstr and there is no return variable assignment.
Rik <octave@nomad.inbox5.com>
parents:
14453
diff
changeset
|
887 retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexp"); |
6361 | 888 else |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
889 retval = octregexp (args, nargout, "regexp"); |
6361 | 890 |
891 return retval; | |
5582 | 892 } |
893 | |
894 /* | |
8140
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
895 ## PCRE_ERROR_MATCHLIMIT test |
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
896 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
897 %! 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
|
898 %! ws = warning ("query"); |
8140
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
899 %! unwind_protect |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
900 %! warning ("off"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
901 %! 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
|
902 %! unwind_protect_cleanup |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
903 %! warning (ws); |
8140
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
904 %! end_unwind_protect |
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
905 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
906 ## segfault test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
907 %!assert (regexp ("abcde", "."), [1,2,3,4,5]) |
13759
c4b6ea833fa5
Fix infinite loop with null patterns in regexp (Bug #34101, Bug #33258)
Rik <octave@nomad.inbox5.com>
parents:
13311
diff
changeset
|
908 ## Infinite loop test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
909 %!assert (isempty (regexp ("abcde", ""))) |
5582 | 910 |
911 ## 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
|
912 %!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
|
913 %!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
|
914 %!assert (regexp ('abcabc', '^abc$'), zeros (1,0)) |
5582 | 915 |
916 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
917 %! [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
|
918 %! 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
|
919 %! 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
|
920 %! 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
|
921 %! 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
|
922 %! assert (t, cell (1,0)); |
5582 | 923 |
924 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
925 %! [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
|
926 %! 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
|
927 %! 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
|
928 %! 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
|
929 %! 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
|
930 %! assert (t, cell (1,0)); |
5582 | 931 |
932 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
933 %! [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
|
934 %! assert (s, 2); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
935 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
936 %! 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
|
937 %! assert (m{1}, 'firetruck'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
938 %! assert (t{1}{1}, 'iretr'); |
5582 | 939 |
940 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
941 %! [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
|
942 %! assert (s, [1, 12]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
943 %! assert (e, [5, 17]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
944 %! 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
|
945 %! assert (isempty (te{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
946 %! assert (isempty (te{2})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
947 %! assert (m{1}, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
948 %! assert (m{2}, 'string'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
949 %! 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
|
950 %! assert (isempty (t{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
951 %! assert (isempty (t{2})); |
5582 | 952 |
953 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
954 %! [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
|
955 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
956 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
957 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
958 %! assert (m, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
959 %! assert (isempty (t)); |
5582 | 960 |
961 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
962 %! [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
|
963 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
964 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
965 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
966 %! assert (m, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
967 %! assert (isempty (t)); |
5582 | 968 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
969 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
970 %! [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
|
971 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
972 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
973 %! 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
|
974 %! 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
|
975 %! 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
|
976 %! 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
|
977 %! 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
|
978 %! 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
|
979 %! 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
|
980 %! assert (! isempty (fieldnames (nm))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
981 %! 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
|
982 %! assert (nm.word1, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
983 %! assert (nm.word2, 'test'); |
5582 | 984 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
985 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
986 %! [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
|
987 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
988 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
989 %! 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
|
990 %! 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
|
991 %! 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
|
992 %! 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
|
993 %! 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
|
994 %! 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
|
995 %! 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
|
996 %! assert (!isempty (fieldnames (nm))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
997 %! 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
|
998 %! assert (nm.word1, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
999 %! assert (nm.word2, 'test'); |
5619 | 1000 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1001 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1002 %! [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
|
1003 %! 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
|
1004 %! assert (t{1}{1}, 'John'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1005 %! assert (t{1}{2}, 'Davis'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1006 %! assert (t{2}{1}, 'Rogers'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1007 %! assert (t{2}{2}, 'James'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1008 %! 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
|
1009 %! assert (nm.first{1}, 'John'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1010 %! assert (nm.first{2}, 'James'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1011 %! assert (nm.last{1}, 'Davis'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1012 %! assert (nm.last{2}, 'Rogers'); |
5582 | 1013 |
14452
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1014 ## Tests for named tokens |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1015 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
1016 %! ## Parenthesis in named token (ie (int)) causes a problem |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1017 %! assert (regexp ('qwe int asd', ['(?<typestr>(int))'], 'names'), struct ('typestr', 'int')); |
10518
fcafe0e9bd58
Handle repeated matches in matches returned by pcre
David Bateman <dbateman@free.fr>
parents:
10504
diff
changeset
|
1018 |
14452
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1019 %!test |
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1020 %! ## Mix of named and unnamed tokens can cause segfault (bug #35683) |
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1021 %! str = "abcde"; |
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1022 %! 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
|
1023 %! 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
|
1024 %! 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
|
1025 %! 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
|
1026 %! 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
|
1027 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1028 %!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
|
1029 %!assert (regexp ("abc\nabc", '.', 'dotall'), [1:7]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1030 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1031 %! 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
|
1032 %! 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
|
1033 %! assert (regexp ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]); |
5779 | 1034 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1035 %!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
|
1036 %!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
|
1037 %!assert (regexp ("caseCaSe", 'case', "ignorecase"), [1,5]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1038 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1039 %! 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
|
1040 %! assert (regexp ("caseCaSe", '(?i)case'), [1, 5]); |
5779 | 1041 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1042 %!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
|
1043 %!assert (regexp ("abc\nabc", 'c$', "stringanchors"), 7) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1044 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1045 %! 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
|
1046 %! 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
|
1047 %! assert (regexp ("abc\nabc", '(?m)c$'), [3,7]); |
5779 | 1048 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1049 %!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
|
1050 %!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
|
1051 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1052 %! 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
|
1053 %! 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
|
1054 %! assert (regexp ("this word", '(?x)s w'), zeros (1,0)); |
5779 | 1055 |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1056 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1057 %! [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
|
1058 %! assert (s, [1 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1059 %! assert (e, [3 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1060 %! 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
|
1061 %! assert (m, { "OCT", "V" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1062 %! 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
|
1063 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1064 %! assert (sp, { "", "A", "E" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1065 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1066 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1067 %! [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
|
1068 %! assert (s, [1 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1069 %! assert (e, [3 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1070 %! assert (te, { [1 3], [5 5] }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1071 %! assert (m, { "OCT", "V" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1072 %! assert (t, { {"OCT"}, {"V"} }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1073 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1074 %! assert (sp, { "", "A", "E" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1075 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1076 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1077 %! [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
|
1078 %! assert (s, [1 4 5 6 7]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1079 %! assert (e, [3 3 5 5 6]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1080 %! 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
|
1081 %! assert (m, { "OCT", "", "V", "", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1082 %! 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
|
1083 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1084 %! assert (sp, { "", "", "A", "", "E", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1085 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1086 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1087 %! [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
|
1088 %! assert (s, [1 4 5 6 7]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1089 %! assert (e, [3 3 5 5 6]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1090 %! 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
|
1091 %! assert (m, { "OCT", "", "V", "", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1092 %! assert (t, { {"OCT"}, {""}, {"V"}, {""}, {""} }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1093 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1094 %! assert (sp, { "", "", "A", "", "E", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1095 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1096 %!error regexp ('string', 'tri', 'BadArg') |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1097 %!error regexp ('string') |
5582 | 1098 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1099 %!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'), {6;[1,5,9];zeros(1,0)}) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1100 %!assert (regexp ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}), {6;[3,7];[1,9]}) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1101 %!assert (regexp ('Strings', {'t','s'}), {2, 7}) |
6361 | 1102 |
8093
dcc31f473596
Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1103 ## Test case for lookaround operators |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1104 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1105 %! 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
|
1106 %! 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
|
1107 %! 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
|
1108 %! 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
|
1109 %! 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
|
1110 %! 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
|
1111 %! 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
|
1112 |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1113 ## Tests for split option. |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1114 %!shared str |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1115 %! str = "foo bar foo"; |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1116 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1117 %! [a, b] = regexp (str, "f..", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1118 %! assert (a, {"foo", "foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1119 %! assert (b, {"", " bar ", ""}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1120 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1121 %! [a, b] = regexp (str, "f..", "match", "split", "once"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1122 %! assert (a, "foo"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1123 %! assert (b, {"", " bar foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1124 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1125 %! [a, b] = regexp (str, "fx.", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1126 %! assert (a, cell (1, 0)); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1127 %! assert (b, {"foo bar foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1128 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1129 %! [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
|
1130 %! assert (a, "");; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1131 %! assert (b, "foo bar foo"); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1132 |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1133 %!shared str |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1134 %! str = "foo bar"; |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1135 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1136 %! [a, b] = regexp (str, "f..", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1137 %! assert (a, {"foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1138 %! assert (b, {"", " bar"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1139 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1140 %! [a, b] = regexp (str, "b..", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1141 %! assert (a, {"bar"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1142 %! assert (b, {"foo ", ""}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1143 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1144 %! [a, b] = regexp (str, "x", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1145 %! assert (a, cell (1, 0)); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1146 %! assert (b, {"foo bar"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1147 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1148 %! [a, b] = regexp (str, "[o]+", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1149 %! assert (a, {"oo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1150 %! 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
|
1151 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1152 %!assert (regexp ("\n", '\n'), 1); |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1153 %!assert (regexp ("\n", "\n"), 1); |
5582 | 1154 */ |
1155 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1156 DEFUN (regexpi, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1157 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1158 @deftypefn {Built-in Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1159 @deftypefnx {Built-in Function} {[@dots{}] =} regexpi (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\ |
5582 | 1160 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1161 Case insensitive regular expression string matching.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1162 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1163 Search for @var{pat} in @var{str} and return the positions and substrings of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1164 any matches, or empty values if there are none. @xref{XREFregexp,,regexp},\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1165 for details on the syntax of the search pattern.\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
1166 @seealso{regexp}\n\ |
5582 | 1167 @end deftypefn") |
1168 { | |
6361 | 1169 octave_value_list retval; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1170 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1171 int nargin = args.length (); |
6361 | 1172 |
1173 if (nargin < 2) | |
1174 print_usage (); | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1175 else if (args(0).is_cell () || args(1).is_cell ()) |
14454
2232931f2494
Return regexp output when input is a cellstr and there is no return variable assignment.
Rik <octave@nomad.inbox5.com>
parents:
14453
diff
changeset
|
1176 retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexpi", true); |
6361 | 1177 else |
1178 retval = octregexp (args, nargout, "regexpi", true); | |
1179 | |
1180 return retval; | |
5582 | 1181 } |
1182 | |
1183 /* | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1184 ## segfault test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1185 %!assert (regexpi ("abcde", "."), [1,2,3,4,5]) |
5582 | 1186 |
1187 ## 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
|
1188 %!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
|
1189 %!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
|
1190 %!assert (regexpi ('abcabc', '^ABC$'), zeros (1,0)) |
5582 | 1191 |
1192 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1193 %! [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
|
1194 %! 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
|
1195 %! 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
|
1196 %! 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
|
1197 %! 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
|
1198 %! assert (t, cell (1,0)); |
5582 | 1199 |
1200 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1201 %! [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
|
1202 %! assert (s, 2); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1203 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1204 %! 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
|
1205 %! assert (m{1}, 'FiRetrUck'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1206 %! assert (t{1}{1}, 'iRetr'); |
5582 | 1207 |
1208 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1209 %! [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
|
1210 %! assert (s, 2); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1211 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1212 %! 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
|
1213 %! assert (m{1}, 'firetruck'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1214 %! assert (t{1}{1}, 'iretr'); |
5582 | 1215 |
1216 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1217 %! [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
|
1218 %! assert (s, [1, 12]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1219 %! assert (e, [5, 17]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1220 %! 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
|
1221 %! assert (isempty (te{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1222 %! assert (isempty (te{2})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1223 %! assert (m{1}, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1224 %! assert (m{2}, 'String'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1225 %! 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
|
1226 %! assert (isempty (t{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1227 %! assert (isempty (t{2})); |
5582 | 1228 |
1229 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1230 %! [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
|
1231 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1232 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1233 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1234 %! assert (m, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1235 %! assert (isempty (t)); |
5582 | 1236 |
1237 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1238 %! [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
|
1239 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1240 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1241 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1242 %! assert (m, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1243 %! assert (isempty (t)); |
5582 | 1244 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1245 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1246 %! [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
|
1247 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1248 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1249 %! 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
|
1250 %! 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
|
1251 %! 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
|
1252 %! 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
|
1253 %! 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
|
1254 %! 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
|
1255 %! 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
|
1256 %! assert (! isempty (fieldnames (nm))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1257 %! 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
|
1258 %! assert (nm.word1, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1259 %! assert (nm.word2, 'Test'); |
5582 | 1260 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1261 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1262 %! [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
|
1263 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1264 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1265 %! 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
|
1266 %! 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
|
1267 %! 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
|
1268 %! 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
|
1269 %! 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
|
1270 %! 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
|
1271 %! 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
|
1272 %! assert (!isempty (fieldnames (nm))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1273 %! 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
|
1274 %! assert (nm.word1, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1275 %! assert (nm.word2, 'Test'); |
5582 | 1276 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1277 %!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
|
1278 %!assert (regexpi ("abc\nabc", '.', 'dotall'), [1:7]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1279 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1280 %! 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
|
1281 %! 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
|
1282 %! assert (regexpi ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]); |
5779 | 1283 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1284 %!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
|
1285 %!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
|
1286 %!assert (regexpi ("caseCaSe", 'case', "ignorecase"), [1, 5]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1287 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1288 %! 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
|
1289 %! assert (regexpi ("caseCaSe", '(?i)case'), [1, 5]); |
5779 | 1290 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1291 %!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
|
1292 %!assert (regexpi ("abc\nabc", 'C$', "stringanchors"), 7) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1293 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1294 %! 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
|
1295 %! 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
|
1296 %! assert (regexpi ("abc\nabc", '(?m)C$'), [3, 7]); |
5779 | 1297 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1298 %!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
|
1299 %!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
|
1300 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1301 %! 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
|
1302 %! 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
|
1303 %! assert (regexpi ("this word", '(?x)S w'), zeros (1,0)); |
5582 | 1304 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1305 %!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
|
1306 %!error regexpi ('string') |
6361 | 1307 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1308 %!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, '-'), {6;[1,5,9];zeros(1, 0)}) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1309 %!assert (regexpi ({'asdfg-dfd', '-dfd-dfd-', 'qasfdfdaq'}, '-'), {6, [1,5,9], zeros(1,0)}) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1310 %!assert (regexpi ({'asdfg-dfd';'-dfd-dfd-';'qasfdfdaq'}, {'-';'f';'q'}), {6;[3,7];[1,9]}) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1311 %!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
|
1312 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1313 %!assert (regexpi ("\n", '\n'), 1); |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1314 %!assert (regexpi ("\n", "\n"), 1); |
5582 | 1315 */ |
1316 | |
6361 | 1317 static octave_value |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1318 octregexprep (const octave_value_list &args, const std::string &who) |
5785 | 1319 { |
6361 | 1320 octave_value retval; |
5785 | 1321 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1322 int nargin = args.length (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1323 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1324 // Make sure we have string, pattern, replacement |
5785 | 1325 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
|
1326 if (error_state) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1327 return retval; |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1328 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1329 std::string pattern = args(1).string_value (); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1330 if (error_state) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1331 return 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
|
1332 // 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
|
1333 if (args(1).is_sq_string ()) |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
1334 pattern = do_regexp_ptn_string_escapes (pattern); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1335 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1336 std::string replacement = args(2).string_value (); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1337 if (error_state) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1338 return 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
|
1339 // 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
|
1340 if (args(2).is_sq_string ()) |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
1341 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
|
1342 |
5785 | 1343 // Pack options excluding 'tokenize' and various output |
1344 // reordering strings into regexp arg list | |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1345 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
|
1346 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1347 int len = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1348 for (int i = 3; i < nargin; i++) |
5785 | 1349 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1350 const std::string opt = args(i).string_value (); |
5785 | 1351 if (opt != "tokenize" && opt != "start" && opt != "end" |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1352 && opt != "tokenextents" && opt != "match" && opt != "tokens" |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1353 && opt != "names" && opt != "split" && opt != "warnings") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1354 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1355 regexpargs(len++) = args(i); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1356 } |
5785 | 1357 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1358 regexpargs.resize (len); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1359 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1360 regexp::opts options; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1361 bool extra_args = false; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1362 parse_options (options, regexpargs, who, 0, extra_args); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1363 if (error_state) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1364 return retval; |
5785 | 1365 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1366 return regexp_replace (pattern, buffer, replacement, options, who); |
6361 | 1367 } |
1368 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1369 DEFUN (regexprep, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1370 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1371 @deftypefn {Built-in Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1372 @deftypefnx {Built-in Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}, \"@var{opt1}\", @dots{})\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
1373 Replace occurrences of pattern @var{pat} in @var{string} with @var{repstr}.\n\ |
6361 | 1374 \n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
1375 The pattern is a regular expression as documented for @code{regexp}.\n\ |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16940
diff
changeset
|
1376 @xref{XREFregexp,,regexp}.\n\ |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
1377 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1378 The replacement string may contain @code{$i}, which substitutes for the ith\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1379 set of parentheses in the match string. For example,\n\ |
10840 | 1380 \n\ |
6361 | 1381 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1382 regexprep (\"Bill Dunn\", '(\\w+) (\\w+)', '$2, $1')\n\ |
6361 | 1383 @end example\n\ |
10840 | 1384 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
1385 @noindent\n\ |
6361 | 1386 returns \"Dunn, Bill\"\n\ |
1387 \n\ | |
11025
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
1388 Options in addition to those of @code{regexp} are\n\ |
df2152514429
Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents:
11018
diff
changeset
|
1389 \n\ |
6361 | 1390 @table @samp\n\ |
1391 \n\ | |
1392 @item once\n\ | |
7001 | 1393 Replace only the first occurrence of @var{pat} in the result.\n\ |
6361 | 1394 \n\ |
1395 @item warnings\n\ | |
1396 This option is present for compatibility but is ignored.\n\ | |
1397 \n\ | |
1398 @end table\n\ | |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15039
diff
changeset
|
1399 \n\ |
20041
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1400 Implementation Note: For compatibility with @sc{matlab}, escape sequences\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1401 in @var{pat} (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are expanded\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1402 even when @var{pat} has been defined with single quotes. To disable\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1403 expansion use a second backslash before the escape sequence (e.g.,\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1404 \"@xbackslashchar{}@xbackslashchar{}n\") or use the @code{regexptranslate}\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20041
diff
changeset
|
1405 function.\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
1406 @seealso{regexp, regexpi, strrep}\n\ |
6361 | 1407 @end deftypefn") |
1408 { | |
1409 octave_value_list retval; | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1410 int nargin = args.length (); |
6361 | 1411 |
1412 if (nargin < 3) | |
1413 { | |
1414 print_usage (); | |
1415 return retval; | |
1416 } | |
1417 | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1418 if (args(0).is_cell () || args(1).is_cell () || args(2).is_cell ()) |
6361 | 1419 { |
1420 Cell str; | |
1421 Cell pat; | |
1422 Cell rep; | |
6495 | 1423 dim_vector dv0; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1424 dim_vector dv1 (1, 1); |
6361 | 1425 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1426 if (args(0).is_cell ()) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1427 str = args(0).cell_value (); |
6361 | 1428 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1429 str = Cell (args(0)); |
6361 | 1430 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1431 if (args(1).is_cell ()) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1432 pat = args(1).cell_value (); |
6361 | 1433 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1434 pat = Cell (args(1)); |
6361 | 1435 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1436 if (args(2).is_cell ()) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1437 rep = args(2).cell_value (); |
6361 | 1438 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1439 rep = Cell (args(2)); |
6361 | 1440 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1441 dv0 = str.dims (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1442 if (pat.numel () != 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1443 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1444 dv1 = pat.dims (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1445 if (rep.numel () != 1 && dv1 != rep.dims ()) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1446 error ("regexprep: inconsistent cell array dimensions"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1447 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1448 else if (rep.numel () != 1) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1449 dv1 = rep.dims (); |
6361 | 1450 |
1451 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1452 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1453 Cell ret (dv0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1454 octave_value_list new_args = args; |
6361 | 1455 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1456 for (octave_idx_type i = 0; i < dv0.numel (); i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1457 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1458 new_args(0) = str(i); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14543
diff
changeset
|
1459 if (pat.numel () == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1460 new_args(1) = pat(0); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14543
diff
changeset
|
1461 if (rep.numel () == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1462 new_args(2) = rep(0); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1463 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1464 for (octave_idx_type j = 0; j < dv1.numel (); j++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1465 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1466 if (pat.numel () != 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1467 new_args(1) = pat(j); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1468 if (rep.numel () != 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1469 new_args(2) = rep(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1470 new_args(0) = octregexprep (new_args, "regexprep"); |
6361 | 1471 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1472 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1473 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1474 } |
6361 | 1475 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1476 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1477 break; |
6495 | 1478 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1479 ret(i) = new_args(0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1480 } |
6361 | 1481 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1482 if (!error_state) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1483 retval = args(0).is_cell () ? octave_value (ret) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1484 : octave_value (ret(0)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1485 } |
6361 | 1486 } |
1487 else | |
1488 retval = octregexprep (args, "regexprep"); | |
1489 | |
5785 | 1490 return retval; |
1491 } | |
1492 | |
1493 /* | |
1494 %!test # Replace with empty | |
1495 %! 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
|
1496 %! t = regexprep (xml, '<[!?][^>]*>', ''); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1497 %! assert (t, ' <tag v="hello">some stuff</tag>'); |
5785 | 1498 |
1499 %!test # Replace with non-empty | |
1500 %! 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
|
1501 %! t = regexprep (xml, '<[!?][^>]*>', '?'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1502 %! assert (t, '? <tag v="hello">some stuff?</tag>'); |
5785 | 1503 |
1504 %!test # Check that 'tokenize' is ignored | |
1505 %! 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
|
1506 %! t = regexprep (xml, '<[!?][^>]*>', '', 'tokenize'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1507 %! assert (t, ' <tag v="hello">some stuff</tag>'); |
5785 | 1508 |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
1509 ## Test capture replacement |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1510 %!test |
7242 | 1511 %! data = "Bob Smith\nDavid Hollerith\nSam Jenkins"; |
1512 %! 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
|
1513 %! 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
|
1514 %! assert (t, result); |
5785 | 1515 |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
1516 ## 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
|
1517 %!assert (regexprep ('hello', 'world', 'earth'), 'hello') |
5785 | 1518 |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1519 ## Test emptymatch |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1520 %!assert (regexprep ('World', '^', 'Hello '), 'World') |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1521 %!assert (regexprep ('World', '^', 'Hello ', 'emptymatch'), 'Hello World') |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1522 |
5785 | 1523 ## 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
|
1524 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_"), "a_b_c_d_e_f_g") |
5785 | 1525 |
1526 ## Make sure it works at the beginning and end | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1527 %!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
|
1528 %!assert (regexprep ("a[b]c{d}e-f=g", "g", "_"), "a[b]c{d}e-f=_") |
5785 | 1529 |
1530 ## Options | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1531 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_", "once"), "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
|
1532 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "ignorecase"), "a_b_c_d_e_f_g") |
5785 | 1533 |
1534 ## Option combinations | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1535 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "once", "ignorecase"), "a_b]c{d}e-f=g") |
5785 | 1536 |
1537 ## End conditions on replacement | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1538 %!assert (regexprep ("abc", "(b)", ".$1"), "a.bc"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1539 %!assert (regexprep ("abc", "(b)", "$1"), "abc"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1540 %!assert (regexprep ("abc", "(b)", "$1."), "ab.c"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1541 %!assert (regexprep ("abc", "(b)", "$1.."), "ab..c"); |
5785 | 1542 |
6361 | 1543 ## 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
|
1544 %!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
|
1545 %!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
|
1546 %!assert (regexprep ({"abc","cba"}, {"b","a"}, {"?","!"}), {"!?c","c?!"}) |
6361 | 1547 |
8093
dcc31f473596
Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1548 # Nasty lookbehind expression |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1549 %!assert (regexprep ('x^(-1)+y(-1)+z(-1)=0', '(?<=[a-z]+)\(\-[1-9]*\)', '_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
|
1550 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1551 %!assert (regexprep ("\n", '\n', "X"), "X"); |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1552 %!assert (regexprep ("\n", "\n", "X"), "X"); |
5785 | 1553 */ |