Mercurial > octave
annotate libinterp/corefcn/regexp.cc @ 22197:e43d83253e28
refill multi-line macro definitions
Use the Emacs C++ mode style for line continuation markers in
multi-line macro definitions.
* make_int.cc, __dsearchn__.cc, __magick_read__.cc, besselj.cc,
bitfcns.cc, bsxfun.cc, cellfun.cc, data.cc, defun-dld.h, defun-int.h,
defun.h, det.cc, error.h, find.cc, gcd.cc, graphics.cc, interpreter.h,
jit-ir.h, jit-typeinfo.h, lookup.cc, ls-mat5.cc, max.cc, mexproto.h,
mxarray.in.h, oct-stream.cc, ordschur.cc, pr-output.cc, profiler.h,
psi.cc, regexp.cc, sparse-xdiv.cc, sparse-xpow.cc, tril.cc, txt-eng.h,
utils.cc, variables.cc, variables.h, xdiv.cc, xpow.cc, __glpk__.cc,
ov-base.cc, ov-base.h, ov-cell.cc, ov-ch-mat.cc, ov-classdef.cc,
ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-float.cc, ov-float.h,
ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc,
ov-int-traits.h, ov-lazy-idx.h, ov-perm.cc, ov-re-mat.cc,
ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc,
ov-type-conv.h, ov.cc, ov.h, op-class.cc, op-int-conv.cc, op-int.h,
op-str-str.cc, ops.h, lex.ll, Array.cc, CMatrix.cc, CSparse.cc,
MArray.cc, MArray.h, MDiagArray2.cc, MDiagArray2.h, MSparse.h,
Sparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc, fMatrix.cc,
idx-vector.cc, f77-fcn.h, quit.h, bsxfun-decl.h, bsxfun-defs.cc,
lo-specfun.cc, oct-convn.cc, oct-convn.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, Sparse-op-decls.h, Sparse-op-defs.h, mx-inlines.cc,
mx-op-decl.h, mx-op-defs.h, mach-info.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, oct-time.cc, data-conv.cc, kpse.cc, lo-ieee.h,
lo-macros.h, oct-cmplx.h, oct-glob.cc, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.h, oct-sparse.h, url-transfer.cc,
oct-conf-post.in.h, shared-fcns.h: Refill macro definitions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 01 Aug 2016 12:40:18 -0400 |
parents | 112b20240c87 |
children | 9fc91bb2aec3 |
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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21575
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
25 # include "config.h" |
5582 | 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" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
42 #include "errwarn.h" |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
43 #include "oct-map.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
44 #include "ovl.h" |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
45 #include "utils.h" |
5785 | 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; |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
105 warning ("malformed octal escape sequence '\\o' -- converting to '\\0'"); |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
106 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
107 retval[i] = tmpi; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
108 j = k - 1; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
109 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
110 } |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
111 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
112 default: // pass escape sequence through |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
113 retval[i] = '\\'; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
114 retval[++i] = s[j]; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
115 break; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
116 } |
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 else |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
119 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
120 retval[i] = s[j]; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
121 } |
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 i++; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
124 j++; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
125 } |
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 retval.resize (i); |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
128 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
129 return retval; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
130 } |
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 static std::string |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
133 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
|
134 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
135 std::string retval; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
136 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
137 size_t i = 0; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
138 size_t j = 0; |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
139 size_t len = s.length (); |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
140 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
141 retval.resize (len); |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
142 |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
143 while (j < len) |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
144 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
145 if (s[j] == '\\' && j+1 < len) |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
146 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
147 switch (s[++j]) |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
148 { |
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
149 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
|
150 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
|
151 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
152 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
153 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
|
154 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
|
155 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
156 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
157 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
|
158 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
|
159 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
160 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
161 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
|
162 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
|
163 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
164 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
165 case '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
|
166 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
|
167 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
168 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
169 case '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
|
170 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
|
171 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
172 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
173 case '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
|
174 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
|
175 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
176 |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
177 case 'o': // octal input |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
178 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
179 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
|
180 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
181 bool brace = false; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
182 if (! bad_esc_seq && s[++j] == '{') |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
183 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
184 brace = true; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
185 j++; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
186 } |
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 int tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
189 size_t k; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
190 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
|
191 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
192 int digit = s[k] - '0'; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
193 if (digit < 0 || digit > 7) |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
194 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
195 tmpi <<= 3; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
196 tmpi += digit; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
197 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
198 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
|
199 { |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
200 warning ("malformed octal escape sequence '\\o' -- converting to '\\0'"); |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
201 tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
202 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
203 retval[i] = tmpi; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
204 j = k - 1; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
205 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
206 } |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
207 |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
208 case 'x': // hex input |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
209 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
210 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
|
211 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
212 bool brace = false; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
213 if (! bad_esc_seq && s[++j] == '{') |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
214 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
215 brace = true; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
216 j++; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
217 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
218 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
219 int tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
220 size_t k; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
221 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
|
222 { |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
223 if (! isxdigit (s[k])) |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
224 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
225 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
226 tmpi <<= 4; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
227 int digit = s[k]; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
228 if (digit >= 'a') |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
229 tmpi += digit - 'a' + 10; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
230 else 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 |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
233 tmpi += digit - '0'; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
234 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
235 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
|
236 { |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
237 warning ("malformed hex escape sequence '\\x' -- converting to '\\0'"); |
20211
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
238 tmpi = 0; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
239 } |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
240 retval[i] = tmpi; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
241 j = k - 1; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
242 break; |
f2bc7d23295d
Add special hex/octal escape sequence processing for regexp.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
243 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
244 |
20290
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
245 // Both dollar sign (for capture buffer) and backslash are |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
246 // passed through with their escape backslash. The processing |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
247 // for these must occur during the actual replacement operation |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
248 // in lo-regexp.cc. |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
249 case '$': // pass dollar sign through with escape |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
250 retval[i] = '\\'; retval[++i] = '$'; |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
251 break; |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
252 |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
253 case '\\': // pass backslash through with escape |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
254 retval[i] = '\\'; retval[++i] = '\\'; |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
255 break; |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
256 |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
257 default: // convert escaped character to unescaped char |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
258 retval[i] = s[j]; |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
259 break; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
260 } |
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 else |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
263 { |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
264 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
|
265 } |
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 i++; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
268 j++; |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
269 } |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
270 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
271 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
|
272 |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
273 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
|
274 } |
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
275 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
276 static void |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
277 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
|
278 const std::string& who, int skip, bool& extra_args) |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
279 { |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
280 extra_args = false; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
281 |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
282 for (int i = skip; i < args.length (); i++) |
5582 | 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 std::string str; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
285 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20581
diff
changeset
|
286 str = args(i).xstring_value ("%s: optional arguments must be strings", who.c_str ()); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
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 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
336 std::string pattern = args(1).string_value (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
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 // 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
|
339 if (args(1).is_sq_string ()) |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
340 pattern = do_regexp_ptn_string_escapes (pattern); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
341 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
342 regexp::opts options; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
343 options.case_insensitive (case_insensitive); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
344 bool extra_options = false; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
345 parse_options (options, args, who, 2, extra_options); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
346 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
347 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
|
348 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
349 string_vector named_pats = rx_lst.named_patterns (); |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
350 |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
351 size_t sz = rx_lst.size (); |
5785 | 352 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
353 // Converted the linked list in the correct form for the return values |
12464
dfeea9cae79e
require PCRE to build Octave
John W. Eaton <jwe@octave.org>
parents:
12462
diff
changeset
|
354 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
355 octave_idx_type i = 0; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
356 octave_scalar_map nmap; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
357 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
358 retval.resize (7); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
359 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
360 if (sz == 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
361 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
362 string_vector named_tokens = rx_lst.begin ()->named_tokens (); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
363 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
364 for (int j = 0; j < named_pats.numel (); j++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
365 nmap.assign (named_pats(j), named_tokens(j)); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
366 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
367 retval(5) = nmap; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
368 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
369 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
370 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
371 for (int j = 0; j < named_pats.numel (); j++) |
7893
eb9ccb44ea41
make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
372 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
373 Cell tmp (dim_vector (1, sz)); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
374 |
7893
eb9ccb44ea41
make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
375 i = 0; |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
376 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
|
377 p != rx_lst.end (); p++) |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
378 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
379 string_vector named_tokens = p->named_tokens (); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
380 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
381 tmp(i++) = named_tokens(j); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
382 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
383 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
384 nmap.assign (named_pats(j), octave_value (tmp)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
385 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
386 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
387 retval(5) = nmap; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
388 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
389 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
390 if (options.once ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
391 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
392 regexp::match_data::const_iterator p = rx_lst.begin (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
393 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
394 retval(4) = sz ? p->tokens () : Cell (); |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
395 retval(3) = sz ? p->match_string () : ""; |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
396 retval(2) = sz ? p->token_extents () : Matrix (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
397 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
398 if (sz) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
399 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
400 double start = p->start (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
401 double end = p->end (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
402 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
403 Cell split (dim_vector (1, 2)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
404 split(0) = buffer.substr (0, start-1); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
405 split(1) = buffer.substr (end); |
5785 | 406 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
407 retval(6) = split; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
408 retval(1) = end; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
409 retval(0) = start; |
7893
eb9ccb44ea41
make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
410 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
411 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
412 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
413 retval(6) = buffer; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
414 retval(1) = Matrix (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
415 retval(0) = Matrix (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
416 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
417 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
418 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
419 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
420 Cell tokens (dim_vector (1, sz)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
421 Cell match_string (dim_vector (1, sz)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
422 Cell token_extents (dim_vector (1, sz)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
423 NDArray end (dim_vector (1, sz)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
424 NDArray start (dim_vector (1, sz)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
425 Cell split (dim_vector (1, sz+1)); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
426 size_t sp_start = 0; |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
427 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
428 i = 0; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
429 for (regexp::match_data::const_iterator p = rx_lst.begin (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
430 p != rx_lst.end (); p++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
431 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
432 double s = p->start (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
433 double e = p->end (); |
5582 | 434 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
435 string_vector tmp = p->tokens (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
436 tokens(i) = Cell (dim_vector (1, tmp.numel ()), tmp); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
437 match_string(i) = p->match_string (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
438 token_extents(i) = p->token_extents (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
439 end(i) = e; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
440 start(i) = s; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
441 split(i) = buffer.substr (sp_start, s-sp_start-1); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
442 sp_start = e; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
443 i++; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
444 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
445 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
446 split(i) = buffer.substr (sp_start); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
447 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
448 retval(6) = split; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
449 retval(4) = tokens; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
450 retval(3) = match_string; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
451 retval(2) = token_extents; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
452 retval(1) = end; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
453 retval(0) = start; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
454 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
455 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
456 // Alter the order of the output arguments |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
457 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
458 if (extra_options) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
459 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
460 int n = 0; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
461 octave_value_list new_retval; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
462 new_retval.resize (nargout); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
463 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
464 OCTAVE_LOCAL_BUFFER (int, arg_used, 6); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
465 for (int j = 0; j < 6; j++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
466 arg_used[j] = false; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
467 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
468 for (int j = 2; j < nargin; j++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
469 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
470 int k = 0; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
471 std::string str = args(j).string_value (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
472 std::transform (str.begin (), str.end (), str.begin (), tolower); |
5582 | 473 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
474 if (str.find ("once", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
475 || str.find ("stringanchors", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
476 || str.find ("lineanchors", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
477 || str.find ("matchcase", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
478 || str.find ("ignorecase", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
479 || str.find ("dotall", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
480 || str.find ("dotexceptnewline", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
481 || str.find ("literalspacing", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
482 || str.find ("freespacing", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
483 || str.find ("noemptymatch", 0) == 0 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
484 || str.find ("emptymatch", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
485 continue; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
486 else if (str.find ("start", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
487 k = 0; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
488 else if (str.find ("end", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
489 k = 1; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
490 else if (str.find ("tokenextents", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
491 k = 2; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
492 else if (str.find ("match", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
493 k = 3; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
494 else if (str.find ("tokens", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
495 k = 4; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
496 else if (str.find ("names", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
497 k = 5; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
498 else if (str.find ("split", 0) == 0) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
499 k = 6; |
5582 | 500 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
501 new_retval(n++) = retval(k); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
502 arg_used[k] = true; |
5582 | 503 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
504 if (n == nargout) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
505 break; |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
506 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
507 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
508 // Fill in the rest of the arguments |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
509 if (n < nargout) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
510 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
511 for (int j = 0; j < 6; j++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
512 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
513 if (! arg_used[j]) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
514 new_retval(n++) = retval(j); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
515 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
516 } |
5582 | 517 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
518 retval = new_retval; |
5582 | 519 } |
520 | |
521 return retval; | |
522 } | |
523 | |
6361 | 524 static octave_value_list |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
525 octcellregexp (const octave_value_list &args, int nargout, |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
526 const std::string &who, bool case_insensitive = false) |
6361 | 527 { |
528 octave_value_list retval; | |
529 | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
530 if (args(0).is_cell ()) |
6361 | 531 { |
532 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout); | |
533 octave_value_list new_args = args; | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
534 Cell cellstr = args(0).cell_value (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
535 if (args(1).is_cell ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
536 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
537 Cell cellpat = args(1).cell_value (); |
6361 | 538 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
539 if (cellpat.numel () == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
540 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
541 for (int j = 0; j < nargout; j++) |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
542 newretval[j].resize (cellstr.dims ()); |
6361 | 543 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
544 new_args(1) = cellpat(0); |
6361 | 545 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
546 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
|
547 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
548 new_args(0) = cellstr(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
549 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
|
550 case_insensitive); |
6361 | 551 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
552 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
553 newretval[j](i) = tmp(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
554 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
555 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
556 else if (cellstr.numel () == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
557 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
558 for (int j = 0; j < nargout; j++) |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
559 newretval[j].resize (cellpat.dims ()); |
6361 | 560 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
561 new_args(0) = cellstr(0); |
6361 | 562 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
563 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
|
564 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
565 new_args(1) = cellpat(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
566 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
|
567 case_insensitive); |
6361 | 568 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
569 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
570 newretval[j](i) = tmp(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
571 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
572 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
573 else if (cellstr.numel () == cellpat.numel ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
574 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
575 if (cellstr.dims () != cellpat.dims ()) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
576 error ("%s: inconsistent cell array dimensions", who.c_str ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
577 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
578 for (int j = 0; j < nargout; j++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
579 newretval[j].resize (cellstr.dims ()); |
6361 | 580 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
581 for (octave_idx_type i = 0; i < cellstr.numel (); i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
582 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
583 new_args(0) = cellstr(i); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
584 new_args(1) = cellpat(i); |
6361 | 585 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
586 octave_value_list tmp = octregexp (new_args, nargout, who, |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
587 case_insensitive); |
6361 | 588 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
589 for (int j = 0; j < nargout; j++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
590 newretval[j](i) = tmp(j); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
591 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
592 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
593 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
594 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
|
595 } |
6361 | 596 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
597 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
598 for (int j = 0; j < nargout; j++) |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
599 newretval[j].resize (cellstr.dims ()); |
6361 | 600 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
601 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
|
602 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
603 new_args(0) = cellstr(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
604 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
|
605 case_insensitive); |
6361 | 606 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
607 for (int j = 0; j < nargout; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
608 newretval[j](i) = tmp(j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
609 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
610 } |
6361 | 611 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
612 for (int j = 0; j < nargout; j++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
613 retval(j) = octave_value (newretval[j]); |
6361 | 614 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
615 else if (args(1).is_cell ()) |
6361 | 616 { |
617 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout); | |
618 octave_value_list new_args = args; | |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
619 Cell cellpat = args(1).cell_value (); |
6361 | 620 |
621 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
|
622 newretval[j].resize (cellpat.dims ()); |
6361 | 623 |
624 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
|
625 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
626 new_args(1) = cellpat(i); |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
627 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
|
628 case_insensitive); |
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 } |
6361 | 633 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
634 for (int j = 0; j < nargout; j++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
635 retval(j) = octave_value (newretval[j]); |
6361 | 636 } |
637 else | |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
638 retval = octregexp (args, nargout, who, case_insensitive); |
6361 | 639 |
640 return retval; | |
641 | |
642 } | |
643 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
644 DEFUN (regexp, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
645 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
646 @deftypefn {} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexp (@var{str}, @var{pat}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
647 @deftypefnx {} {[@dots{}] =} regexp (@var{str}, @var{pat}, "@var{opt1}", @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
648 Regular expression string matching. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
649 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
650 Search for @var{pat} in @var{str} and return the positions and substrings of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
651 any matches, or empty values if there are none. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
652 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
653 The matched pattern @var{pat} can include any of the standard regex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
654 operators, including: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
655 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
656 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
657 @item . |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
658 Match any character |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
659 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
660 @item * + ? @{@} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
661 Repetition operators, representing |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
662 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
663 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
664 @item * |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
665 Match zero or more times |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
666 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
667 @item + |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
668 Match one or more times |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
669 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
670 @item ? |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
671 Match zero or one times |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
672 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
673 @item @{@var{n}@} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
674 Match exactly @var{n} times |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
675 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
676 @item @{@var{n},@} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
677 Match @var{n} or more times |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
678 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
679 @item @{@var{m},@var{n}@} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
680 Match between @var{m} and @var{n} times |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
681 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
682 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
683 @item [@dots{}] [^@dots{}] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
684 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
685 List operators. The pattern will match any character listed between "[" |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
686 and "]". If the first character is "^" then the pattern is inverted and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
687 any character except those listed between brackets will match. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
688 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
689 Escape sequences defined below can also be used inside list operators. For |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
690 example, a template for a floating point number might be @code{[-+.\d]+}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
691 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
692 @item () (?:) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
693 Grouping operator. The first form, parentheses only, also creates a token. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
694 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
695 @item | |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
696 Alternation operator. Match one of a choice of regular expressions. The |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
697 alternatives must be delimited by the grouping operator @code{()} above. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
698 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
699 @item ^ $ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
700 Anchoring operators. Requires pattern to occur at the start (@code{^}) or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
701 end (@code{$}) of the string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
702 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
703 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
704 In addition, the following escaped characters have special meaning. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
705 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
706 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
707 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
708 @item \d |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
709 Match any digit |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
710 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
711 @item \D |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
712 Match any non-digit |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
713 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
714 @item \s |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
715 Match any whitespace character |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
716 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
717 @item \S |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
718 Match any non-whitespace character |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
719 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
720 @item \w |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
721 Match any word character |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
722 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
723 @item \W |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
724 Match any non-word character |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
725 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
726 @item \< |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
727 Match the beginning of a word |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
728 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
729 @item \> |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
730 Match the end of a word |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
731 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
732 @item \B |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
733 Match within a word |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
734 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
735 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
736 Implementation Note: For compatibility with @sc{matlab}, escape sequences |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
737 in @var{pat} (e.g., @qcode{"@xbackslashchar{}n"} => newline) are expanded |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
738 even when @var{pat} has been defined with single quotes. To disable |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
739 expansion use a second backslash before the escape sequence (e.g., |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
740 "@xbackslashchar{}@xbackslashchar{}n") or use the @code{regexptranslate} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
741 function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
742 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
743 The outputs of @code{regexp} default to the order given below |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
744 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
745 @table @var |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
746 @item s |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
747 The start indices of each matching substring |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
748 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
749 @item e |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
750 The end indices of each matching substring |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
751 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
752 @item te |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
753 The extents of each matched token surrounded by @code{(@dots{})} in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
754 @var{pat} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
755 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
756 @item m |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
757 A cell array of the text of each match |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
758 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
759 @item t |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
760 A cell array of the text of each token matched |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
761 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
762 @item nm |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
763 A structure containing the text of each matched named token, with the name |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
764 being used as the fieldname. A named token is denoted by |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
765 @code{(?<name>@dots{})}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
766 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
767 @item sp |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
768 A cell array of the text not returned by match, i.e., what remains if you |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
769 split the string based on @var{pat}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
770 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
771 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
772 Particular output arguments, or the order of the output arguments, can be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
773 selected by additional @var{opt} arguments. These are strings and the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
774 correspondence between the output arguments and the optional argument |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
775 are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
776 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
777 @multitable @columnfractions 0.2 0.3 0.3 0.2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
778 @item @tab @qcode{'start'} @tab @var{s} @tab |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
779 @item @tab @qcode{'end'} @tab @var{e} @tab |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
780 @item @tab @qcode{'tokenExtents'} @tab @var{te} @tab |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
781 @item @tab @qcode{'match'} @tab @var{m} @tab |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
782 @item @tab @qcode{'tokens'} @tab @var{t} @tab |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
783 @item @tab @qcode{'names'} @tab @var{nm} @tab |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
784 @item @tab @qcode{'split'} @tab @var{sp} @tab |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
785 @end multitable |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
786 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
787 Additional arguments are summarized below. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
788 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
789 @table @samp |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
790 @item once |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
791 Return only the first occurrence of the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
792 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
793 @item matchcase |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
794 Make the matching case sensitive. (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
795 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
796 Alternatively, use (?-i) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
797 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
798 @item ignorecase |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
799 Ignore case when matching the pattern to the string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
800 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
801 Alternatively, use (?i) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
802 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
803 @item stringanchors |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
804 Match the anchor characters at the beginning and end of the string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
805 (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
806 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
807 Alternatively, use (?-m) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
808 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
809 @item lineanchors |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
810 Match the anchor characters at the beginning and end of the line. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
811 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
812 Alternatively, use (?m) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
813 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
814 @item dotall |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
815 The pattern @code{.} matches all characters including the newline character. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
816 (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
817 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
818 Alternatively, use (?s) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
819 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
820 @item dotexceptnewline |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
821 The pattern @code{.} matches all characters except the newline character. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
822 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
823 Alternatively, use (?-s) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
824 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
825 @item literalspacing |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
826 All characters in the pattern, including whitespace, are significant and are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
827 used in pattern matching. (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
828 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
829 Alternatively, use (?-x) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
830 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
831 @item freespacing |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
832 The pattern may include arbitrary whitespace and also comments beginning |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
833 with the character @samp{#}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
834 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
835 Alternatively, use (?x) in the pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
836 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
837 @item noemptymatch |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
838 Zero-length matches are not returned. (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
839 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
840 @item emptymatch |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
841 Return zero-length matches. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
842 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
843 @code{regexp ('a', 'b*', 'emptymatch')} returns @code{[1 2]} because there |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
844 are zero or more @qcode{'b'} characters at positions 1 and end-of-string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
845 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
846 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
847 @seealso{regexpi, strfind, regexprep} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
848 @end deftypefn */) |
5582 | 849 { |
20821
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
850 if (args.length () < 2) |
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
851 print_usage (); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
852 |
20821
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
853 octave_value_list retval; |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
854 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
855 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
|
856 retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexp"); |
6361 | 857 else |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
858 retval = octregexp (args, nargout, "regexp"); |
6361 | 859 |
860 return retval; | |
5582 | 861 } |
862 | |
863 /* | |
8140
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
864 ## PCRE_ERROR_MATCHLIMIT test |
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
865 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
866 %! 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
|
867 %! ws = warning ("query"); |
8140
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
868 %! unwind_protect |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
869 %! warning ("off"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
870 %! 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
|
871 %! unwind_protect_cleanup |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
872 %! warning (ws); |
8140
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
873 %! end_unwind_protect |
cdd05e46f6c9
Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
8093
diff
changeset
|
874 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
875 ## segfault test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
876 %!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
|
877 ## Infinite loop test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
878 %!assert (isempty (regexp ("abcde", ""))) |
5582 | 879 |
880 ## 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
|
881 %!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
|
882 %!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
|
883 %!assert (regexp ('abcabc', '^abc$'), zeros (1,0)) |
5582 | 884 |
885 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
886 %! [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
|
887 %! 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
|
888 %! 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
|
889 %! 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
|
890 %! 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
|
891 %! assert (t, cell (1,0)); |
5582 | 892 |
893 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
894 %! [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
|
895 %! 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
|
896 %! 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
|
897 %! 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
|
898 %! 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
|
899 %! assert (t, cell (1,0)); |
5582 | 900 |
901 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
902 %! [s, 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
|
903 %! assert (s, 2); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
904 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
905 %! 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
|
906 %! assert (m{1}, 'firetruck'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
907 %! assert (t{1}{1}, 'iretr'); |
5582 | 908 |
909 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
910 %! [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
|
911 %! assert (s, [1, 12]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
912 %! assert (e, [5, 17]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
913 %! 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
|
914 %! assert (isempty (te{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
915 %! assert (isempty (te{2})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
916 %! assert (m{1}, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
917 %! assert (m{2}, 'string'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
918 %! 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
|
919 %! assert (isempty (t{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
920 %! assert (isempty (t{2})); |
5582 | 921 |
922 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
923 %! [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
|
924 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
925 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
926 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
927 %! assert (m, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
928 %! assert (isempty (t)); |
5582 | 929 |
930 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
931 %! [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
|
932 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
933 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
934 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
935 %! assert (m, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
936 %! assert (isempty (t)); |
5582 | 937 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
938 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
939 %! [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
|
940 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
941 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
942 %! 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
|
943 %! 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
|
944 %! 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
|
945 %! 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
|
946 %! 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
|
947 %! 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
|
948 %! 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
|
949 %! assert (! isempty (fieldnames (nm))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
950 %! 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
|
951 %! assert (nm.word1, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
952 %! assert (nm.word2, 'test'); |
5582 | 953 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
954 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
955 %! [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
|
956 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
957 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
958 %! 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
|
959 %! 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
|
960 %! 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
|
961 %! 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
|
962 %! 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
|
963 %! 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
|
964 %! assert (size (nm), [1, 1]); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
965 %! assert (! isempty (fieldnames (nm))); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
966 %! 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
|
967 %! assert (nm.word1, 'short'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
968 %! assert (nm.word2, 'test'); |
5619 | 969 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
970 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
971 %! [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
|
972 %! 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
|
973 %! 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
|
974 %! 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
|
975 %! 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
|
976 %! 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
|
977 %! 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
|
978 %! 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
|
979 %! 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
|
980 %! 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
|
981 %! assert (nm.last{2}, 'Rogers'); |
5582 | 982 |
14452
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
983 ## Tests for named tokens |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
984 %!test |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
985 %! ## 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
|
986 %! 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
|
987 |
14452
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
988 %!test |
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
989 %! ## 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
|
990 %! str = "abcde"; |
721be41ea988
Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
991 %! 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
|
992 %! 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
|
993 %! 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
|
994 %! 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
|
995 %! 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
|
996 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
997 %!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
|
998 %!assert (regexp ("abc\nabc", '.', 'dotall'), [1:7]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
999 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1000 %! 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
|
1001 %! 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
|
1002 %! assert (regexp ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]); |
5779 | 1003 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1004 %!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
|
1005 %!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
|
1006 %!assert (regexp ("caseCaSe", 'case', "ignorecase"), [1,5]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1007 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1008 %! 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
|
1009 %! assert (regexp ("caseCaSe", '(?i)case'), [1, 5]); |
5779 | 1010 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1011 %!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
|
1012 %!assert (regexp ("abc\nabc", 'c$', "stringanchors"), 7) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1013 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1014 %! 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
|
1015 %! 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
|
1016 %! assert (regexp ("abc\nabc", '(?m)c$'), [3,7]); |
5779 | 1017 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1018 %!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
|
1019 %!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
|
1020 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1021 %! 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
|
1022 %! 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
|
1023 %! assert (regexp ("this word", '(?x)s w'), zeros (1,0)); |
5779 | 1024 |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1025 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1026 %! [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
|
1027 %! assert (s, [1 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1028 %! assert (e, [3 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1029 %! 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
|
1030 %! assert (m, { "OCT", "V" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1031 %! 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
|
1032 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1033 %! assert (sp, { "", "A", "E" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1034 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1035 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1036 %! [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
|
1037 %! assert (s, [1 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1038 %! assert (e, [3 5]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1039 %! assert (te, { [1 3], [5 5] }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1040 %! assert (m, { "OCT", "V" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1041 %! assert (t, { {"OCT"}, {"V"} }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1042 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1043 %! assert (sp, { "", "A", "E" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1044 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1045 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1046 %! [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
|
1047 %! assert (s, [1 4 5 6 7]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1048 %! assert (e, [3 3 5 5 6]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1049 %! 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
|
1050 %! assert (m, { "OCT", "", "V", "", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1051 %! 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
|
1052 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1053 %! assert (sp, { "", "", "A", "", "E", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1054 |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1055 %!test |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1056 %! [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
|
1057 %! assert (s, [1 4 5 6 7]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1058 %! assert (e, [3 3 5 5 6]); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1059 %! 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
|
1060 %! assert (m, { "OCT", "", "V", "", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1061 %! assert (t, { {"OCT"}, {""}, {"V"}, {""}, {""} }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1062 %! assert (isempty (fieldnames (nm))); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1063 %! assert (sp, { "", "", "A", "", "E", "" }); |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1064 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1065 %!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
|
1066 %!error regexp ('string') |
5582 | 1067 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1068 %!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
|
1069 %!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
|
1070 %!assert (regexp ('Strings', {'t','s'}), {2, 7}) |
6361 | 1071 |
8093
dcc31f473596
Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1072 ## Test case for lookaround operators |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1073 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1074 %! 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
|
1075 %! 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
|
1076 %! 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
|
1077 %! 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
|
1078 %! 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
|
1079 %! 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
|
1080 %! 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
|
1081 |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1082 ## Tests for split option. |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1083 %!shared str |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1084 %! str = "foo bar foo"; |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1085 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1086 %! [a, b] = regexp (str, "f..", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1087 %! assert (a, {"foo", "foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1088 %! assert (b, {"", " bar ", ""}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1089 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1090 %! [a, b] = regexp (str, "f..", "match", "split", "once"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1091 %! assert (a, "foo"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1092 %! assert (b, {"", " bar foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1093 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1094 %! [a, b] = regexp (str, "fx.", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1095 %! assert (a, cell (1, 0)); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1096 %! assert (b, {"foo bar foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1097 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1098 %! [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
|
1099 %! assert (a, "");; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1100 %! assert (b, "foo bar foo"); |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1101 |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1102 %!shared str |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1103 %! str = "foo bar"; |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1104 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1105 %! [a, b] = regexp (str, "f..", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1106 %! assert (a, {"foo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1107 %! assert (b, {"", " bar"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1108 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1109 %! [a, b] = regexp (str, "b..", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1110 %! assert (a, {"bar"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1111 %! assert (b, {"foo ", ""}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1112 %!test |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1113 %! [a, b] = regexp (str, "x", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1114 %! assert (a, cell (1, 0)); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1115 %! assert (b, {"foo bar"}); |
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, "[o]+", "match", "split"); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1118 %! assert (a, {"oo"}); |
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1119 %! 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
|
1120 |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1121 %!assert (regexp ("\n", '\n'), 1) |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1122 %!assert (regexp ("\n", "\n"), 1) |
20290
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1123 |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1124 %!test # Bug #45407, escape sequences are silently converted |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1125 %! assert (regexprep ('s', 's', 'x\.y'), 'x.y'); |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1126 %! assert (regexprep ('s', '(s)', 'x\$1y'), 'x$1y'); |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1127 %! assert (regexprep ('s', '(s)', 'x\\$1y'), 'x\sy'); |
b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1128 |
5582 | 1129 */ |
1130 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1131 DEFUN (regexpi, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1132 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1133 @deftypefn {} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1134 @deftypefnx {} {[@dots{}] =} regexpi (@var{str}, @var{pat}, "@var{opt1}", @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1135 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1136 Case insensitive regular expression string matching. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1137 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1138 Search for @var{pat} in @var{str} and return the positions and substrings of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1139 any matches, or empty values if there are none. @xref{XREFregexp,,regexp}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1140 for details on the syntax of the search pattern. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1141 @seealso{regexp} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1142 @end deftypefn */) |
5582 | 1143 { |
20821
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
1144 if (args.length () < 2) |
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
1145 print_usage (); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1146 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1147 if (args(0).is_cell () || args(1).is_cell ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1148 return octcellregexp (args, (nargout > 0 ? nargout : 1), "regexpi", true); |
6361 | 1149 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1150 return octregexp (args, nargout, "regexpi", true); |
5582 | 1151 } |
1152 | |
1153 /* | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1154 ## segfault test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1155 %!assert (regexpi ("abcde", "."), [1,2,3,4,5]) |
5582 | 1156 |
1157 ## 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
|
1158 %!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
|
1159 %!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
|
1160 %!assert (regexpi ('abcabc', '^ABC$'), zeros (1,0)) |
5582 | 1161 |
1162 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1163 %! [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
|
1164 %! 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
|
1165 %! 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
|
1166 %! 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
|
1167 %! 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
|
1168 %! assert (t, cell (1,0)); |
5582 | 1169 |
1170 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1171 %! [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
|
1172 %! assert (s, 2); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1173 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1174 %! 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
|
1175 %! assert (m{1}, 'FiRetrUck'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1176 %! assert (t{1}{1}, 'iRetr'); |
5582 | 1177 |
1178 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1179 %! [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
|
1180 %! assert (s, 2); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1181 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1182 %! 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
|
1183 %! assert (m{1}, 'firetruck'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1184 %! assert (t{1}{1}, 'iretr'); |
5582 | 1185 |
1186 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1187 %! [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
|
1188 %! assert (s, [1, 12]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1189 %! assert (e, [5, 17]); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1190 %! 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
|
1191 %! assert (isempty (te{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1192 %! assert (isempty (te{2})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1193 %! assert (m{1}, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1194 %! assert (m{2}, 'String'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1195 %! 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
|
1196 %! assert (isempty (t{1})); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1197 %! assert (isempty (t{2})); |
5582 | 1198 |
1199 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1200 %! [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
|
1201 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1202 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1203 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1204 %! assert (m, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1205 %! assert (isempty (t)); |
5582 | 1206 |
1207 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1208 %! [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
|
1209 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1210 %! assert (e, 5); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1211 %! assert (isempty (te)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1212 %! assert (m, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1213 %! assert (isempty (t)); |
5582 | 1214 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1215 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1216 %! [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
|
1217 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1218 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1219 %! 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
|
1220 %! 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
|
1221 %! 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
|
1222 %! 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
|
1223 %! 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
|
1224 %! 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
|
1225 %! 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
|
1226 %! assert (! isempty (fieldnames (nm))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1227 %! 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
|
1228 %! assert (nm.word1, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1229 %! assert (nm.word2, 'Test'); |
5582 | 1230 |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1231 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1232 %! [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
|
1233 %! assert (s, 1); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1234 %! assert (e, 10); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1235 %! 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
|
1236 %! 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
|
1237 %! 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
|
1238 %! 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
|
1239 %! 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
|
1240 %! 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
|
1241 %! assert (size (nm), [1, 1]); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1242 %! assert (! isempty (fieldnames (nm))); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1243 %! 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
|
1244 %! assert (nm.word1, 'ShoRt'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1245 %! assert (nm.word2, 'Test'); |
5582 | 1246 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1247 %!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
|
1248 %!assert (regexpi ("abc\nabc", '.', 'dotall'), [1:7]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1249 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1250 %! 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
|
1251 %! 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
|
1252 %! assert (regexpi ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]); |
5779 | 1253 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1254 %!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
|
1255 %!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
|
1256 %!assert (regexpi ("caseCaSe", 'case', "ignorecase"), [1, 5]) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1257 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1258 %! 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
|
1259 %! assert (regexpi ("caseCaSe", '(?i)case'), [1, 5]); |
5779 | 1260 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1261 %!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
|
1262 %!assert (regexpi ("abc\nabc", 'C$', "stringanchors"), 7) |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1263 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1264 %! 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
|
1265 %! 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
|
1266 %! assert (regexpi ("abc\nabc", '(?m)C$'), [3, 7]); |
5779 | 1267 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1268 %!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
|
1269 %!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
|
1270 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1271 %! 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
|
1272 %! 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
|
1273 %! assert (regexpi ("this word", '(?x)S w'), zeros (1,0)); |
5582 | 1274 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1275 %!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
|
1276 %!error regexpi ('string') |
6361 | 1277 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1278 %!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
|
1279 %!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
|
1280 %!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
|
1281 %!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
|
1282 |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1283 %!assert (regexpi ("\n", '\n'), 1) |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1284 %!assert (regexpi ("\n", "\n"), 1) |
5582 | 1285 */ |
1286 | |
6361 | 1287 static octave_value |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1288 octregexprep (const octave_value_list &args, const std::string &who) |
5785 | 1289 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1290 int nargin = args.length (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1291 |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1292 // Make sure we have string, pattern, replacement |
5785 | 1293 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
|
1294 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1295 std::string pattern = args(1).string_value (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1296 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1297 // 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
|
1298 if (args(1).is_sq_string ()) |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
1299 pattern = do_regexp_ptn_string_escapes (pattern); |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1300 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1301 std::string replacement = args(2).string_value (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1302 |
14543
e47d929fde8f
process backslash string escapes in regexp pattern and regexprep replacement (bug #35911)
John W. Eaton <jwe@octave.org>
parents:
14536
diff
changeset
|
1303 // 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
|
1304 if (args(2).is_sq_string ()) |
15541
9db32cabeacf
Fix backslash handling in regexp pattern (Bug #37092)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
1305 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
|
1306 |
5785 | 1307 // Pack options excluding 'tokenize' and various output |
1308 // reordering strings into regexp arg list | |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1309 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
|
1310 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1311 int len = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1312 for (int i = 3; i < nargin; i++) |
5785 | 1313 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1314 const std::string opt = args(i).string_value (); |
5785 | 1315 if (opt != "tokenize" && opt != "start" && opt != "end" |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1316 && opt != "tokenextents" && opt != "match" && opt != "tokens" |
13310
583940a28bfd
handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents:
13227
diff
changeset
|
1317 && opt != "names" && opt != "split" && opt != "warnings") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1318 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1319 regexpargs(len++) = args(i); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1320 } |
5785 | 1321 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1322 regexpargs.resize (len); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1323 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1324 regexp::opts options; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1325 bool extra_args = false; |
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1326 parse_options (options, regexpargs, who, 0, extra_args); |
5785 | 1327 |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1328 return regexp_replace (pattern, buffer, replacement, options, who); |
6361 | 1329 } |
1330 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1331 DEFUN (regexprep, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1332 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1333 @deftypefn {} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1334 @deftypefnx {} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}, "@var{opt1}", @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1335 Replace occurrences of pattern @var{pat} in @var{string} with @var{repstr}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1336 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1337 The pattern is a regular expression as documented for @code{regexp}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1338 @xref{XREFregexp,,regexp}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1339 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1340 The replacement string may contain @code{$i}, which substitutes for the ith |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1341 set of parentheses in the match string. For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1342 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1343 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1344 regexprep ("Bill Dunn", '(\w+) (\w+)', '$2, $1') |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1345 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1346 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1347 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1348 returns "Dunn, Bill" |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1349 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1350 Options in addition to those of @code{regexp} are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1351 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1352 @table @samp |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1353 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1354 @item once |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1355 Replace only the first occurrence of @var{pat} in the result. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1356 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1357 @item warnings |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1358 This option is present for compatibility but is ignored. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1359 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1360 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1361 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1362 Implementation Note: For compatibility with @sc{matlab}, escape sequences |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1363 in @var{pat} (e.g., @qcode{"@xbackslashchar{}n"} => newline) are expanded |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1364 even when @var{pat} has been defined with single quotes. To disable |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1365 expansion use a second backslash before the escape sequence (e.g., |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1366 "@xbackslashchar{}@xbackslashchar{}n") or use the @code{regexptranslate} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1367 function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1368 @seealso{regexp, regexpi, strrep} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1369 @end deftypefn */) |
6361 | 1370 { |
20821
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
1371 if (args.length () < 3) |
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
1372 print_usage (); |
6361 | 1373 |
20821
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
1374 octave_value_list retval; |
6361 | 1375 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1376 if (args(0).is_cell () || args(1).is_cell () || args(2).is_cell ()) |
6361 | 1377 { |
20821
b169da150702
Eliminate unnecessary uses of nargin.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
1378 Cell str, pat, rep; |
6495 | 1379 dim_vector dv0; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1380 dim_vector dv1 (1, 1); |
6361 | 1381 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1382 if (args(0).is_cell ()) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1383 str = args(0).cell_value (); |
6361 | 1384 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1385 str = Cell (args(0)); |
6361 | 1386 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1387 if (args(1).is_cell ()) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1388 pat = args(1).cell_value (); |
6361 | 1389 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1390 pat = Cell (args(1)); |
6361 | 1391 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1392 if (args(2).is_cell ()) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1393 rep = args(2).cell_value (); |
6361 | 1394 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1395 rep = Cell (args(2)); |
6361 | 1396 |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1397 dv0 = str.dims (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1398 if (pat.numel () != 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1399 { |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1400 dv1 = pat.dims (); |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1401 if (rep.numel () != 1 && dv1 != rep.dims ()) |
14024
fc9f204faea0
refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
1402 error ("regexprep: inconsistent cell array dimensions"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1403 } |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1404 else if (rep.numel () != 1) |
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1405 dv1 = rep.dims (); |
6361 | 1406 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1407 Cell ret (dv0); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1408 octave_value_list new_args = args; |
13227
9559417aa965
maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
1409 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1410 for (octave_idx_type i = 0; i < dv0.numel (); i++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1411 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1412 new_args(0) = str(i); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1413 if (pat.numel () == 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1414 new_args(1) = pat(0); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1415 if (rep.numel () == 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1416 new_args(2) = rep(0); |
6361 | 1417 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1418 for (octave_idx_type j = 0; j < dv1.numel (); j++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1419 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1420 if (pat.numel () != 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1421 new_args(1) = pat(j); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1422 if (rep.numel () != 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1423 new_args(2) = rep(j); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1424 new_args(0) = octregexprep (new_args, "regexprep"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1425 } |
6361 | 1426 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1427 ret(i) = new_args(0); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
1428 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20290
diff
changeset
|
1429 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1430 retval = args(0).is_cell () ? ovl (ret) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1431 : ovl (ret(0)); |
6361 | 1432 } |
1433 else | |
1434 retval = octregexprep (args, "regexprep"); | |
1435 | |
5785 | 1436 return retval; |
1437 } | |
1438 | |
1439 /* | |
1440 %!test # Replace with empty | |
1441 %! 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
|
1442 %! t = regexprep (xml, '<[!?][^>]*>', ''); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1443 %! assert (t, ' <tag v="hello">some stuff</tag>'); |
5785 | 1444 |
1445 %!test # Replace with non-empty | |
1446 %! 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
|
1447 %! t = regexprep (xml, '<[!?][^>]*>', '?'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1448 %! assert (t, '? <tag v="hello">some stuff?</tag>'); |
5785 | 1449 |
1450 %!test # Check that 'tokenize' is ignored | |
1451 %! 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
|
1452 %! t = regexprep (xml, '<[!?][^>]*>', '', 'tokenize'); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1453 %! assert (t, ' <tag v="hello">some stuff</tag>'); |
5785 | 1454 |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
1455 ## Test capture replacement |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
12433
diff
changeset
|
1456 %!test |
7242 | 1457 %! data = "Bob Smith\nDavid Hollerith\nSam Jenkins"; |
1458 %! 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
|
1459 %! 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
|
1460 %! assert (t, result); |
5785 | 1461 |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
11025
diff
changeset
|
1462 ## 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
|
1463 %!assert (regexprep ('hello', 'world', 'earth'), 'hello') |
5785 | 1464 |
14536
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1465 ## Test emptymatch |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1466 %!assert (regexprep ('World', '^', 'Hello '), 'World') |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1467 %!assert (regexprep ('World', '^', 'Hello ', 'emptymatch'), 'Hello World') |
6d5c951ec520
Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
1468 |
5785 | 1469 ## 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
|
1470 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_"), "a_b_c_d_e_f_g") |
5785 | 1471 |
1472 ## 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
|
1473 %!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
|
1474 %!assert (regexprep ("a[b]c{d}e-f=g", "g", "_"), "a[b]c{d}e-f=_") |
5785 | 1475 |
1476 ## Options | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1477 %!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
|
1478 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "ignorecase"), "a_b_c_d_e_f_g") |
5785 | 1479 |
1480 ## Option combinations | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14496
diff
changeset
|
1481 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "once", "ignorecase"), "a_b]c{d}e-f=g") |
5785 | 1482 |
1483 ## End conditions on replacement | |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1484 %!assert (regexprep ("abc", "(b)", ".$1"), "a.bc") |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1485 %!assert (regexprep ("abc", "(b)", "$1"), "abc") |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1486 %!assert (regexprep ("abc", "(b)", "$1."), "ab.c") |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1487 %!assert (regexprep ("abc", "(b)", "$1.."), "ab..c") |
5785 | 1488 |
6361 | 1489 ## 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
|
1490 %!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
|
1491 %!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
|
1492 %!assert (regexprep ({"abc","cba"}, {"b","a"}, {"?","!"}), {"!?c","c?!"}) |
6361 | 1493 |
8093
dcc31f473596
Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1494 # Nasty lookbehind expression |
21575
bc9aa534bc29
maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1495 %!test |
bc9aa534bc29
maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1496 %! warning ("off", "Octave:regexp-lookbehind-limit", "local"); |
bc9aa534bc29
maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1497 %! 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
|
1498 |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1499 %!assert (regexprep ("\n", '\n', "X"), "X") |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1500 %!assert (regexprep ("\n", "\n", "X"), "X") |
5785 | 1501 */ |