annotate src/DLD-FUNCTIONS/regexp.cc @ 14536:6d5c951ec520

Add 'emptymatch', 'noemptymatch' options to regular expressions. * NEWS: Announce new options. * liboctave/regexp.cc (regexp::match): Add processing option for zero length matches. * liboctave/regexp.h (class opts): Add emptymatch option to constructors, setter/getter routines, private variable. * DLD-FUNCTIONS/regexp.cc (parse_options): Add emptymatch to options parsing routine. * DLD-FUNCTIONS/regexp.cc (octregexp): Ignore emptymatch when determing output ordering of arguments. * DLD-FUNCTIONS/regexp.cc (Fregexp): Add new options to docstring. Add %!tests for new behavior. * DLD-FUNCTIONS/regexp.cc (Fregexprep): Add %!tests for new behavior.
author Rik <octave@nomad.inbox5.com>
date Sat, 07 Apr 2012 09:43:53 -0700
parents 60e5cf354d80
children e47d929fde8f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1 /*
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14024
diff changeset
3 Copyright (C) 2005-2012 David Bateman
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11045
diff changeset
4 Copyright (C) 2002-2005 Paul Kienzle
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
5
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
6 This file is part of Octave.
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
7
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
11 option) any later version.
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
12
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
16 for more details.
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
17
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
20 <http://www.gnu.org/licenses/>.
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
21
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
22 */
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
23
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
26 #endif
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
27
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
28 #include <list>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
29 #include <sstream>
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
30
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
31 #include <pcre.h>
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
32
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
33 #include "base-list.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
34 #include "oct-locbuf.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
35 #include "quit.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
36 #include "regexp.h"
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
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
39 #include "defun-dld.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
40 #include "Cell.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
41 #include "error.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
42 #include "gripes.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
43 #include "oct-map.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
44 #include "oct-obj.h"
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
45 #include "utils.h"
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
46
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
47 static void
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
48 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
49 const std::string& who, int skip, bool& extra_args)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
50 {
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
51 int nargin = args.length ();
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
52
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
53 extra_args = false;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
54
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
55 for (int i = skip; i < nargin; i++)
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
56 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
57 std::string str = args(i).string_value ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
58
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
59 if (error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
60 {
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
61 error ("%s: optional arguments must be character strings",
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
62 who.c_str ());
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
63 break;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
64 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
65
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
66 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
67
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
68 if (str.find ("once", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
69 options.once (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
70 else if (str.find ("matchcase", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
71 options.case_insensitive (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
72 else if (str.find ("ignorecase", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
73 options.case_insensitive (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
74 else if (str.find ("dotall", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
75 options.dotexceptnewline (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
76 else if (str.find ("stringanchors", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
77 options.lineanchors (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
78 else if (str.find ("literalspacing", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
79 options.freespacing (false);
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
80 else if (str.find ("noemptymatch", 0) == 0)
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
81 options.emptymatch (false);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
82 else if (str.find ("dotexceptnewline", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
83 options.dotexceptnewline (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
84 else if (str.find ("lineanchors", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
85 options.lineanchors (true);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
86 else if (str.find ("freespacing", 0) == 0)
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
87 options.freespacing (true);
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
88 else if (str.find ("emptymatch", 0) == 0)
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
89 options.emptymatch (true);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
90 else if (str.find ("start", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
91 || str.find ("end", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
92 || str.find ("tokenextents", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
93 || str.find ("match", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
94 || str.find ("tokens", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
95 || str.find ("names", 0) == 0
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
96 || str.find ("split", 0) == 0)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
97 extra_args = true;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
98 else
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
99 error ("%s: unrecognized option", who.c_str ());
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
100 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
101 }
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
102
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
103 static octave_value_list
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
104 octregexp (const octave_value_list &args, int nargout,
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
105 const std::string &who, bool case_insensitive = false)
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
106 {
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
107 octave_value_list retval;
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
108
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
109 int nargin = args.length ();
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
110
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
111 // Make sure we have string, pattern
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
112 const std::string buffer = args(0).string_value ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
113 if (error_state)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
114 return retval;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
115
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
116 const std::string pattern = args(1).string_value ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
117 if (error_state)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
118 return retval;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
119
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
120 regexp::opts options;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
121 options.case_insensitive (case_insensitive);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
122 bool extra_options = false;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
123 parse_options (options, args, who, 2, extra_options);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
124 if (error_state)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
125 return retval;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
126
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
127 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
128
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
129 string_vector named_pats = rx_lst.named_patterns ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
130
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
131 size_t sz = rx_lst.size ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
132
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
133 if (! error_state)
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
134 {
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
135 // Converted the linked list in the correct form for the return values
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
136
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
137 octave_idx_type i = 0;
11045
cc3aad9dd3ef dispatch.cc, fltk_backend.cc, regexp.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
138 octave_scalar_map nmap;
12464
dfeea9cae79e require PCRE to build Octave
John W. Eaton <jwe@octave.org>
parents: 12462
diff changeset
139
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
140 retval.resize (7);
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
141
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
142 if (sz == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
143 {
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
144 string_vector named_tokens = rx_lst.begin()->named_tokens ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
145
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
146 for (int j = 0; j < named_pats.length (); j++)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
147 nmap.assign (named_pats(j), named_tokens(j));
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
148
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
149 retval(5) = nmap;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
150 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
151 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
152 {
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
153 for (int j = 0; j < named_pats.length (); j++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
154 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
155 Cell tmp (dim_vector (1, sz));
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
156
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
157 i = 0;
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
158 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
159 p != rx_lst.end (); p++)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
160 {
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
161 string_vector named_tokens = p->named_tokens ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
162
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
163 tmp(i++) = named_tokens(j);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
164 }
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
165
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
166 nmap.assign (named_pats(j), octave_value (tmp));
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
167 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
168
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
169 retval(5) = nmap;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
170 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
171
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
172 if (options.once ())
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
173 {
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
174 regexp::match_data::const_iterator p = rx_lst.begin ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
175
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
176 retval(4) = sz ? p->tokens () : Cell ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
177 retval(3) = sz ? p->match_string () : std::string ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
178 retval(2) = sz ? p->token_extents () : Matrix ();
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
179
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
180 if (sz)
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
181 {
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
182 double start = p->start ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
183 double end = p->end ();
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
184
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
185 Cell split (dim_vector (1, 2));
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
186 split(0) = buffer.substr (0, start-1);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
187 split(1) = buffer.substr (end);
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
188
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
189 retval(6) = split;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
190 retval(1) = end;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
191 retval(0) = start;
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
192 }
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
193 else
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
194 {
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
195 retval(6) = buffer;
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
196 retval(1) = Matrix ();
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
197 retval(0) = Matrix ();
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
198 }
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
199 }
7893
eb9ccb44ea41 make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7520
diff changeset
200 else
eb9ccb44ea41 make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7520
diff changeset
201 {
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
202 Cell tokens (dim_vector (1, sz));
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
203 Cell match_string (dim_vector (1, sz));
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
204 Cell token_extents (dim_vector (1, sz));
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
205 NDArray end (dim_vector (1, sz));
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
206 NDArray start (dim_vector (1, sz));
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
207 Cell split (dim_vector (1, sz+1));
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
208 size_t sp_start = 0;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
209
7893
eb9ccb44ea41 make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7520
diff changeset
210 i = 0;
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
211 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
212 p != rx_lst.end (); p++)
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
213 {
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
214 double s = p->start ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
215 double e = p->end ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
216
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
217 string_vector tmp = p->tokens ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
218 tokens(i) = Cell (dim_vector (1, tmp.length ()), tmp);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
219 match_string(i) = p->match_string ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
220 token_extents(i) = p->token_extents ();
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
221 end(i) = e;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
222 start(i) = s;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
223 split(i) = buffer.substr (sp_start, s-sp_start-1);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
224 sp_start = e;
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
225 i++;
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
226 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
227
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
228 split(i) = buffer.substr (sp_start);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
229
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
230 retval(6) = split;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
231 retval(4) = tokens;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
232 retval(3) = match_string;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
233 retval(2) = token_extents;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
234 retval(1) = end;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
235 retval(0) = start;
7893
eb9ccb44ea41 make regexp(...,'once') matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 7520
diff changeset
236 }
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
237
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
238 // Alter the order of the output arguments
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
239
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
240 if (extra_options)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
241 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
242 int n = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
243 octave_value_list new_retval;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
244 new_retval.resize (nargout);
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
245
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
246 OCTAVE_LOCAL_BUFFER (int, arg_used, 6);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
247 for (int j = 0; j < 6; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
248 arg_used[j] = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
249
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
250 for (int j = 2; j < nargin; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
251 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
252 int k = 0;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
253 std::string str = args(j).string_value ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
254 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
255
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
256 if (str.find ("once", 0) == 0
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
257 || str.find ("stringanchors", 0) == 0
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
258 || str.find ("lineanchors", 0) == 0
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
259 || str.find ("matchcase", 0) == 0
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
260 || str.find ("ignorecase", 0) == 0
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
261 || str.find ("dotall", 0) == 0
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
262 || str.find ("dotexceptnewline", 0) == 0
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
263 || str.find ("literalspacing", 0) == 0
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
264 || str.find ("freespacing", 0) == 0
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
265 || str.find ("noemptymatch", 0) == 0
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
266 || str.find ("emptymatch", 0) == 0)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
267 continue;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
268 else if (str.find ("start", 0) == 0)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
269 k = 0;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
270 else if (str.find ("end", 0) == 0)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
271 k = 1;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
272 else if (str.find ("tokenextents", 0) == 0)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
273 k = 2;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
274 else if (str.find ("match", 0) == 0)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
275 k = 3;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
276 else if (str.find ("tokens", 0) == 0)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
277 k = 4;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
278 else if (str.find ("names", 0) == 0)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
279 k = 5;
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
280 else if (str.find ("split", 0) == 0)
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
281 k = 6;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
282
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
283 new_retval(n++) = retval(k);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
284 arg_used[k] = true;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
285
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
286 if (n == nargout)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
287 break;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
288 }
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
289
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
290 // Fill in the rest of the arguments
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
291 if (n < nargout)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
292 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
293 for (int j = 0; j < 6; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
294 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
295 if (! arg_used[j])
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
296 new_retval(n++) = retval(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
297 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
298 }
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
299
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
300 retval = new_retval;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
301 }
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
302 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
303
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
304 return retval;
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
305 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
306
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
307 static octave_value_list
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
308 octcellregexp (const octave_value_list &args, int nargout,
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
309 const std::string &who, bool case_insensitive = false)
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
310 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
311 octave_value_list retval;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
312
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
313 if (args(0).is_cell ())
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
314 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
315 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
316 octave_value_list new_args = args;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
317 Cell cellstr = args(0).cell_value ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
318 if (args(1).is_cell ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
319 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
320 Cell cellpat = args(1).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
321
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
322 if (cellpat.numel () == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
323 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
324 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
325 newretval[j].resize (cellstr.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
326
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
327 new_args(1) = cellpat(0);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
328
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
329 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
330 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
331 new_args(0) = cellstr(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
332 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
333 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
334
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
335 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
336 break;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
337
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
338 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
339 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
340 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
341 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
342 else if (cellstr.numel () == 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
343 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
344 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
345 newretval[j].resize (cellpat.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
346
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
347 new_args(0) = cellstr(0);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
348
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
349 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
350 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
351 new_args(1) = cellpat(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
352 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
353 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
354
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
355 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
356 break;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
357
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
358 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
359 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
360 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
361 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
362 else if (cellstr.numel () == cellpat.numel ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
363 {
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
364
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
365 if (cellstr.dims () != cellpat.dims ())
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
366 error ("%s: inconsistent cell array dimensions", who.c_str ());
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
367 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
368 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
369 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
370 newretval[j].resize (cellstr.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
371
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
372 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
373 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
374 new_args(0) = cellstr(i);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
375 new_args(1) = cellpat(i);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
376
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
377 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
378 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
379
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
380 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
381 break;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
382
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
383 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
384 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
385 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
386 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
387 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
388 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
389 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
390 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
391 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
392 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
393 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
394 newretval[j].resize (cellstr.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
395
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
396 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
397 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
398 new_args(0) = cellstr(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
399 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
400 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
401
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
402 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
403 break;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
404
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
405 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
406 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
407 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
408 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
409
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
410 if (!error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
411 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
412 retval(j) = octave_value (newretval[j]);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
413 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
414 else if (args(1).is_cell ())
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
415 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
416 OCTAVE_LOCAL_BUFFER (Cell, newretval, nargout);
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
417 octave_value_list new_args = args;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
418 Cell cellpat = args(1).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
419
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
420 for (int j = 0; j < nargout; j++)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
421 newretval[j].resize(cellpat.dims ());
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
422
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
423 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
424 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
425 new_args(1) = cellpat(i);
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
426 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
427 case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
428
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
429 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
430 break;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
431
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
432 for (int j = 0; j < nargout; j++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
433 newretval[j](i) = tmp(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
434 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
435
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
436 if (!error_state)
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
437 {
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
438 for (int j = 0; j < nargout; j++)
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
439 retval(j) = octave_value (newretval[j]);
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
440 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
441 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
442 else
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
443 retval = octregexp (args, nargout, who, case_insensitive);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
444
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
445 return retval;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
446
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
447 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
448
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
449 DEFUN_DLD (regexp, args, nargout,
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
450 "-*- texinfo -*-\n\
14496
bd592d5482c0 doc: Add SP to list of outputs in docstring for regexp, regexpi.
Rik <octave@nomad.inbox5.com>
parents: 14454
diff changeset
451 @deftypefn {Loadable Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexp (@var{str}, @var{pat})\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
452 @deftypefnx {Loadable Function} {[@dots{}] =} regexp (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
453 Regular expression string matching. Search for @var{pat} in @var{str} and\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
454 return the positions and substrings of any matches, or empty values if there\n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
455 are none.\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
456 \n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
457 The matched pattern @var{pat} can include any of the standard regex\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
458 operators, including:\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
459 \n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
460 @table @code\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
461 @item .\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
462 Match any character\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
463 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
464 @item * + ? @{@}\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
465 Repetition operators, representing\n\
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
466 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
467 @table @code\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
468 @item *\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
469 Match zero or more times\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
470 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
471 @item +\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
472 Match one or more times\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
473 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
474 @item ?\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
475 Match zero or one times\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
476 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
477 @item @{@var{n}@}\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
478 Match exactly @var{n} times\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
479 \n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
480 @item @{@var{n},@}\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
481 Match @var{n} or more times\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
482 \n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
483 @item @{@var{m},@var{n}@}\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
484 Match between @var{m} and @var{n} times\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
485 @end table\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
486 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
487 @item [@dots{}] [^@dots{}]\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
488 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
489 List operators. The pattern will match any character listed between \"[\"\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
490 and \"]\". If the first character is \"^\" then the pattern is inverted and\n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
491 any character except those listed between brackets will match.\n\
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
492 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
493 Escape sequences defined below can also be used inside list\n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
494 operators. For example, a template for a floating point number might be\n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
495 @code{[-+.\\d]+}.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
496 \n\
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
497 @item () (?:)\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
498 Grouping operator. The first form, parentheses only, also creates a token.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
499 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
500 @item |\n\
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
501 Alternation operator. Match one of a choice of regular expressions. The\n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
502 alternatives must be delimited by the grouping operator @code{()} above.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
503 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
504 @item ^ $\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
505 Anchoring operators. Requires pattern to occur at the start (@code{^}) or\n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
506 end (@code{$}) of the string.\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
507 @end table\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
508 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
509 In addition, the following escaped characters have special meaning. Note,\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
510 it is recommended to quote @var{pat} in single quotes, rather than double\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
511 quotes, to avoid the escape sequences being interpreted by Octave before\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
512 being passed to @code{regexp}.\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
513 \n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
514 @table @code\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
515 @item \\b\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
516 Match a word boundary\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
517 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
518 @item \\B\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
519 Match within a word\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
520 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
521 @item \\w\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
522 Match any word character\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
523 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
524 @item \\W\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
525 Match any non-word character\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
526 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
527 @item \\<\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
528 Match the beginning of a word\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
529 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
530 @item \\>\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
531 Match the end of a word\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
532 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
533 @item \\s\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
534 Match any whitespace character\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
535 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
536 @item \\S\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
537 Match any non-whitespace character\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
538 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
539 @item \\d\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
540 Match any digit\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
541 \n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
542 @item \\D\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
543 Match any non-digit\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
544 @end table\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
545 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
546 The outputs of @code{regexp} default to the order given below\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
547 \n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
548 @table @var\n\
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
549 @item s\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
550 The start indices of each matching substring\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
551 \n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
552 @item e\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
553 The end indices of each matching substring\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
554 \n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
555 @item te\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
556 The extents of each matched token surrounded by @code{(@dots{})} in\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
557 @var{pat}\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
558 \n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
559 @item m\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
560 A cell array of the text of each match\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
561 \n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
562 @item t\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
563 A cell array of the text of each token matched\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
564 \n\
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
565 @item nm\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
566 A structure containing the text of each matched named token, with the name\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
567 being used as the fieldname. A named token is denoted by\n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
568 @code{(?<name>@dots{})}.\n\
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13759
diff changeset
569 \n\
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
570 @item sp\n\
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
571 A cell array of the text not returned by match, i.e., what remains if you\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
572 split the string based on @var{pat}.\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
573 @end table\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
574 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
575 Particular output arguments, or the order of the output arguments, can be\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
576 selected by additional @var{opt} arguments. These are strings and the\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
577 correspondence between the output arguments and the optional argument\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
578 are\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
579 \n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
580 @multitable @columnfractions 0.2 0.3 0.3 0.2\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
581 @item @tab 'start' @tab @var{s} @tab\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
582 @item @tab 'end' @tab @var{e} @tab\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
583 @item @tab 'tokenExtents' @tab @var{te} @tab\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
584 @item @tab 'match' @tab @var{m} @tab\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
585 @item @tab 'tokens' @tab @var{t} @tab\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
586 @item @tab 'names' @tab @var{nm} @tab\n\
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
587 @item @tab 'split' @tab @var{sp} @tab\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
588 @end multitable\n\
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
589 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
590 Additional arguments are summarized below.\n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
591 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
592 @table @samp\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
593 @item once\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
594 Return only the first occurrence of the pattern.\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
595 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
596 @item matchcase\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
597 Make the matching case sensitive. (default)\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
598 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
599 Alternatively, use (?-i) in the pattern.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
600 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
601 @item ignorecase\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
602 Ignore case when matching the pattern to the string.\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
603 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
604 Alternatively, use (?i) in the pattern.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
605 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
606 @item stringanchors\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12464
diff changeset
607 Match the anchor characters at the beginning and end of the string.\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
608 (default)\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
609 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
610 Alternatively, use (?-m) in the pattern.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
611 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
612 @item lineanchors\n\
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
613 Match the anchor characters at the beginning and end of the line.\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
614 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
615 Alternatively, use (?m) in the pattern.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
616 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
617 @item dotall\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
618 The pattern @code{.} matches all characters including the newline character.\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
619 (default)\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
620 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
621 Alternatively, use (?s) in the pattern.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
622 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
623 @item dotexceptnewline\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
624 The pattern @code{.} matches all characters except the newline character.\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
625 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
626 Alternatively, use (?-s) in the pattern.\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
627 \n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
628 @item literalspacing\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
629 All characters in the pattern, including whitespace, are significant and are\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
630 used in pattern matching. (default)\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
631 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
632 Alternatively, use (?-x) in the pattern.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
633 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
634 @item freespacing\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
635 The pattern may include arbitrary whitespace and also comments beginning with\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
636 the character @samp{#}.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
637 \n\
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
638 Alternatively, use (?x) in the pattern.\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
639 \n\
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
640 @item noemptymatch\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
641 Zero-length matches are not returned. (default)\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
642 \n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
643 @item emptymatch\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
644 Return zero-length matches.\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
645 \n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
646 @code{regexp ('a', 'b*', 'emptymatch'} returns @code{[1 2]} because there are\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
647 zero or more 'b' characters at positions 1 and end-of-string.\n\
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
648 \n\
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
649 @end table\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11553
diff changeset
650 @seealso{regexpi, strfind, regexprep}\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
651 @end deftypefn")
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
652 {
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
653 octave_value_list retval;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
654
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
655 int nargin = args.length ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
656
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
657 if (nargin < 2)
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
658 print_usage ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
659 else if (args(0).is_cell () || args(1).is_cell ())
14454
2232931f2494 Return regexp output when input is a cellstr and there is no return variable assignment.
Rik <octave@nomad.inbox5.com>
parents: 14453
diff changeset
660 retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexp");
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
661 else
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
662 retval = octregexp (args, nargout, "regexp");
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
663
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
664 return retval;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
665 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
666
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
667 /*
8140
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
668 ## PCRE_ERROR_MATCHLIMIT test
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
669 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
670 %! 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
671 %! ws = warning ("query");
8140
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
672 %! unwind_protect
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
673 %! warning ("off");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
674 %! 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
675 %! unwind_protect_cleanup
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
676 %! warning (ws);
8140
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
677 %! end_unwind_protect
cdd05e46f6c9 Increase pcre's match_limit for difficult regexps
Thomas Weber <thomas.weber.mail@gmail.com>
parents: 8093
diff changeset
678
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
679 ## segfault test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
680 %!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
681 ## Infinite loop test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
682 %!assert (isempty (regexp ("abcde", "")))
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
683
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
684 ## 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
685 %!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
686 %!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
687 %!assert (regexp ('abcabc', '^abc$'), zeros (1,0))
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
688
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
689 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
690 %! [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
691 %! 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
692 %! 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
693 %! 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
694 %! 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
695 %! assert (t, cell (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
696
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
697 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
698 %! [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
699 %! 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
700 %! 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
701 %! 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
702 %! 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
703 %! assert (t, cell (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
704
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
705 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
706 %! [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
707 %! assert (s, 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
708 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
709 %! 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
710 %! assert (m{1}, 'firetruck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
711 %! assert (t{1}{1}, 'iretr');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
712
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
713 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
714 %! [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
715 %! assert (s, [1, 12]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
716 %! assert (e, [5, 17]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
717 %! 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
718 %! assert (isempty (te{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
719 %! assert (isempty (te{2}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
720 %! assert (m{1}, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
721 %! assert (m{2}, 'string');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
722 %! 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
723 %! assert (isempty (t{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
724 %! assert (isempty (t{2}));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
725
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
726 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
727 %! [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
728 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
729 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
730 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
731 %! assert (m, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
732 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
733
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
734 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
735 %! [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
736 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
737 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
738 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
739 %! assert (m, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
740 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
741
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
742 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
743 %! [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
744 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
745 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
746 %! 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
747 %! 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
748 %! 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
749 %! 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
750 %! 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
751 %! 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
752 %! 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
753 %! assert (! isempty (fieldnames (nm)));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
754 %! 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
755 %! assert (nm.word1, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
756 %! assert (nm.word2, 'test');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
757
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
758 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
759 %! [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
760 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
761 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
762 %! 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
763 %! 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
764 %! 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
765 %! 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
766 %! 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
767 %! 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
768 %! 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
769 %! assert (!isempty (fieldnames (nm)));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
770 %! 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
771 %! assert (nm.word1, 'short');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
772 %! assert (nm.word2, 'test');
5619
e9112ff172b1 [project @ 2006-02-13 20:05:36 by dbateman]
dbateman
parents: 5582
diff changeset
773
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
774 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
775 %! [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
776 %! 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
777 %! 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
778 %! 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
779 %! 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
780 %! 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
781 %! 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
782 %! 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
783 %! 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
784 %! 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
785 %! assert (nm.last{2}, 'Rogers');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
786
14452
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
787 ## Tests for named tokens
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
788 %!test
10518
fcafe0e9bd58 Handle repeated matches in matches returned by pcre
David Bateman <dbateman@free.fr>
parents: 10504
diff changeset
789 %! # 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
790 %! 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
791
14452
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
792 %!test
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
793 %! ## 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
794 %! str = "abcde";
721be41ea988 Stop segfault when using regular expressions with named capture buffers (bug #35683).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
795 %! 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
796 %! 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
797 %! 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
798 %! 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
799 %! 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
800
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
801 %!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
802 %!assert (regexp ("abc\nabc", '.', 'dotall'), [1:7])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
803 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
804 %! 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
805 %! 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
806 %! assert (regexp ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
807
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
808 %!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
809 %!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
810 %!assert (regexp ("caseCaSe", 'case', "ignorecase"), [1,5])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
811 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
812 %! 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
813 %! assert (regexp ("caseCaSe", '(?i)case'), [1, 5]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
814
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
815 %!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
816 %!assert (regexp ("abc\nabc", 'c$', "stringanchors"), 7)
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
817 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
818 %! 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
819 %! 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
820 %! assert (regexp ("abc\nabc", '(?m)c$'), [3,7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
821
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
822 %!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
823 %!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
824 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
825 %! 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
826 %! 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
827 %! assert (regexp ("this word", '(?x)s w'), zeros (1,0));
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
828
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
829 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
830 %! [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
831 %! assert (s, [1 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
832 %! assert (e, [3 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
833 %! 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
834 %! assert (m, { "OCT", "V" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
835 %! 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
836 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
837 %! assert (sp, { "", "A", "E" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
838
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
839 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
840 %! [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
841 %! assert (s, [1 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
842 %! assert (e, [3 5]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
843 %! assert (te, { [1 3], [5 5] });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
844 %! assert (m, { "OCT", "V" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
845 %! assert (t, { {"OCT"}, {"V"} });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
846 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
847 %! assert (sp, { "", "A", "E" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
848
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
849 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
850 %! [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
851 %! assert (s, [1 4 5 6 7]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
852 %! assert (e, [3 3 5 5 6]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
853 %! 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
854 %! assert (m, { "OCT", "", "V", "", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
855 %! 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
856 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
857 %! assert (sp, { "", "", "A", "", "E", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
858
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
859 %!test
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
860 %! [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
861 %! assert (s, [1 4 5 6 7]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
862 %! assert (e, [3 3 5 5 6]);
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
863 %! 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
864 %! assert (m, { "OCT", "", "V", "", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
865 %! assert (t, { {"OCT"}, {""}, {"V"}, {""}, {""} });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
866 %! assert (isempty (fieldnames (nm)));
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
867 %! assert (sp, { "", "", "A", "", "E", "" });
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
868
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
869 %!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
870 %!error regexp ('string')
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
871
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
872 %!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
873 %!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
874 %!assert (regexp ('Strings', {'t','s'}), {2, 7})
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
875
8093
dcc31f473596 Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
876 ## Test case for lookaround operators
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
877 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
878 %! 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
879 %! 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
880 %! 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
881 %! 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
882 %! 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
883 %! 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
884 %! 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
885
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
886 ## Tests for split option.
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
887 %!shared str
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
888 %! str = "foo bar foo";
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
889 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
890 %! [a, b] = regexp (str, "f..", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
891 %! assert (a, {"foo", "foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
892 %! assert (b, {"", " bar ", ""});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
893 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
894 %! [a, b] = regexp (str, "f..", "match", "split", "once");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
895 %! assert (a, "foo");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
896 %! assert (b, {"", " bar foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
897 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
898 %! [a, b] = regexp (str, "fx.", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
899 %! assert (a, cell (1, 0));
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
900 %! assert (b, {"foo bar foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
901 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
902 %! [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
903 %! assert (a, "");;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
904 %! assert (b, "foo bar foo");
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
905
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
906 %!shared str
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
907 %! str = "foo bar";
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
908 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
909 %! [a, b] = regexp (str, "f..", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
910 %! assert (a, {"foo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
911 %! assert (b, {"", " bar"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
912 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
913 %! [a, b] = regexp (str, "b..", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
914 %! assert (a, {"bar"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
915 %! assert (b, {"foo ", ""});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
916 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
917 %! [a, b] = regexp (str, "x", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
918 %! assert (a, cell (1, 0));
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
919 %! assert (b, {"foo bar"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
920 %!test
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
921 %! [a, b] = regexp (str, "[o]+", "match", "split");
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
922 %! assert (a, {"oo"});
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
923 %! assert (b, {"f", " bar"});
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
924 */
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
925
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6547
diff changeset
926 DEFUN_DLD (regexpi, args, nargout,
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
927 "-*- texinfo -*-\n\
14496
bd592d5482c0 doc: Add SP to list of outputs in docstring for regexp, regexpi.
Rik <octave@nomad.inbox5.com>
parents: 14454
diff changeset
928 @deftypefn {Loadable Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat})\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
929 @deftypefnx {Loadable Function} {[@dots{}] =} regexpi (@var{str}, @var{pat}, \"@var{opt1}\", @dots{})\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
930 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
931 Case insensitive regular expression string matching. Search for @var{pat} in\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
932 @var{str} and return the positions and substrings of any matches, or empty\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
933 values if there are none. @xref{doc-regexp,,regexp}, for details on the\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
934 syntax of the search pattern.\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
935 @seealso{regexp}\n\
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
936 @end deftypefn")
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
937 {
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
938 octave_value_list retval;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
939
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
940 int nargin = args.length ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
941
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
942 if (nargin < 2)
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
943 print_usage ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
944 else if (args(0).is_cell () || args(1).is_cell ())
14454
2232931f2494 Return regexp output when input is a cellstr and there is no return variable assignment.
Rik <octave@nomad.inbox5.com>
parents: 14453
diff changeset
945 retval = octcellregexp (args, (nargout > 0 ? nargout : 1), "regexpi", true);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
946 else
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
947 retval = octregexp (args, nargout, "regexpi", true);
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
948
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
949 return retval;
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
950 }
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
951
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
952 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
953 ## segfault test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
954 %!assert (regexpi ("abcde", "."), [1,2,3,4,5])
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
955
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
956 ## 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
957 %!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
958 %!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
959 %!assert (regexpi ('abcabc', '^ABC$'), zeros (1,0))
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
960
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
961 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
962 %! [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
963 %! 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
964 %! 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
965 %! 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
966 %! 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
967 %! assert (t, cell (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
968
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
969 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
970 %! [s, e, te, m, t] = regexpi (' FiRetrUck ', 'f(.*)uck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
971 %! assert (s, 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
972 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
973 %! assert (te{1}, [3, 7]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
974 %! assert (m{1}, 'FiRetrUck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
975 %! assert (t{1}{1}, 'iRetr');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
976
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
977 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
978 %! [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
979 %! assert (s, 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
980 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
981 %! 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
982 %! assert (m{1}, 'firetruck');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
983 %! assert (t{1}{1}, 'iretr');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
984
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
985 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
986 %! [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
987 %! assert (s, [1, 12]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
988 %! assert (e, [5, 17]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
989 %! assert (size (te), [1, 2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
990 %! assert (isempty (te{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
991 %! assert (isempty (te{2}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
992 %! assert (m{1}, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
993 %! assert (m{2}, 'String');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
994 %! 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
995 %! assert (isempty (t{1}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
996 %! assert (isempty (t{2}));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
997
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
998 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
999 %! [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
1000 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1001 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1002 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1003 %! assert (m, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1004 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1005
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1006 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1007 %! [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
1008 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1009 %! assert (e, 5);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1010 %! assert (isempty (te));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1011 %! assert (m, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1012 %! assert (isempty (t));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1013
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1014 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1015 %! [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
1016 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1017 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1018 %! 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
1019 %! 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
1020 %! 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
1021 %! 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
1022 %! 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
1023 %! 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
1024 %! 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
1025 %! assert (! isempty (fieldnames (nm)));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1026 %! 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
1027 %! assert (nm.word1, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1028 %! assert (nm.word2, 'Test');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1029
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1030 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1031 %! [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
1032 %! assert (s, 1);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1033 %! assert (e, 10);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1034 %! 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
1035 %! 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
1036 %! 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
1037 %! 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
1038 %! 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
1039 %! 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
1040 %! 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
1041 %! assert (!isempty (fieldnames (nm)));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1042 %! 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
1043 %! assert (nm.word1, 'ShoRt');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1044 %! assert (nm.word2, 'Test');
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1045
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1046 %!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
1047 %!assert (regexpi ("abc\nabc", '.', 'dotall'), [1:7])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1048 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1049 %! 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
1050 %! 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
1051 %! assert (regexpi ("abc\nabc", '(?-s).'), [1,2,3,5,6,7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1052
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1053 %!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
1054 %!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
1055 %!assert (regexpi ("caseCaSe", 'case', "ignorecase"), [1, 5])
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1056 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1057 %! 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
1058 %! assert (regexpi ("caseCaSe", '(?i)case'), [1, 5]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1059
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1060 %!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
1061 %!assert (regexpi ("abc\nabc", 'C$', "stringanchors"), 7)
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1062 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1063 %! 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
1064 %! 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
1065 %! assert (regexpi ("abc\nabc", '(?m)C$'), [3, 7]);
5779
12eeebfa7ead [project @ 2006-04-27 19:30:14 by dbateman]
dbateman
parents: 5775
diff changeset
1066
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1067 %!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
1068 %!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
1069 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1070 %! 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
1071 %! 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
1072 %! assert (regexpi ("this word", '(?x)S w'), zeros (1,0));
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1073
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1074 %!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
1075 %!error regexpi ('string')
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1076
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1077 %!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
1078 %!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
1079 %!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
1080 %!assert (regexpi ('Strings', {'t', 's'}), {2, [1, 7]})
5582
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1081 */
6bf56668b01a [project @ 2005-12-15 01:08:20 by jwe]
jwe
parents:
diff changeset
1082
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1083 static octave_value
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1084 octregexprep (const octave_value_list &args, const std::string &who)
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1085 {
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1086 octave_value retval;
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1087
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1088 int nargin = args.length ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1089
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1090 // Make sure we have string, pattern, replacement
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1091 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
1092 if (error_state)
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1093 return retval;
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1094
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1095 const std::string pattern = args(1).string_value ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1096 if (error_state)
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1097 return retval;
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1098
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1099 const std::string replacement = args(2).string_value ();
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1100 if (error_state)
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1101 return retval;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1102
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1103 // Pack options excluding 'tokenize' and various output
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1104 // reordering strings into regexp arg list
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1105 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
1106
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1107 int len = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1108 for (int i = 3; i < nargin; i++)
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1109 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1110 const std::string opt = args(i).string_value ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1111 if (opt != "tokenize" && opt != "start" && opt != "end"
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1112 && opt != "tokenextents" && opt != "match" && opt != "tokens"
13310
583940a28bfd handle "split" option for regexp
John W. Eaton <jwe@octave.org>
parents: 13227
diff changeset
1113 && opt != "names" && opt != "split" && opt != "warnings")
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1114 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1115 regexpargs(len++) = args(i);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1116 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1117 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1118 regexpargs.resize (len);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1119
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1120 regexp::opts options;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1121 bool extra_args = false;
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1122 parse_options (options, regexpargs, who, 0, extra_args);
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1123 if (error_state)
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1124 return retval;
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1125
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1126 return regexp_replace (pattern, buffer, replacement, options, who);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1127 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1128
6549
5a5a09d7deb8 [project @ 2007-04-20 06:55:29 by jwe]
jwe
parents: 6547
diff changeset
1129 DEFUN_DLD (regexprep, args, ,
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1130 "-*- texinfo -*-\n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1131 @deftypefn {Loadable Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr})\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1132 @deftypefnx {Loadable Function} {@var{outstr} =} regexprep (@var{string}, @var{pat}, @var{repstr}, \"@var{opt1}\", @dots{})\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1133 Replace occurrences of pattern @var{pat} in @var{string} with @var{repstr}.\n\
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1134 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1135 The pattern is a regular expression as documented for @code{regexp}.\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1136 @xref{doc-regexp,,regexp}.\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1137 \n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1138 The replacement string may contain @code{$i}, which substitutes\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1139 for the ith set of parentheses in the match string. For example,\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
1140 \n\
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1141 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1142 regexprep (\"Bill Dunn\", '(\\w+) (\\w+)', '$2, $1')\n\
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1143 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10551
diff changeset
1144 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
1145 @noindent\n\
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1146 returns \"Dunn, Bill\"\n\
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1147 \n\
11025
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1148 Options in addition to those of @code{regexp} are\n\
df2152514429 Update docstrings for regular expression functions
Rik <octave@nomad.inbox5.com>
parents: 11018
diff changeset
1149 \n\
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1150 @table @samp\n\
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1151 \n\
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1152 @item once\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6678
diff changeset
1153 Replace only the first occurrence of @var{pat} in the result.\n\
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1154 \n\
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1155 @item warnings\n\
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1156 This option is present for compatibility but is ignored.\n\
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1157 \n\
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1158 @end table\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11553
diff changeset
1159 @seealso{regexp, regexpi, strrep}\n\
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1160 @end deftypefn")
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1161 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1162 octave_value_list retval;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1163 int nargin = args.length ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1164
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1165 if (nargin < 3)
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1166 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1167 print_usage ();
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1168 return retval;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1169 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1170
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1171 if (args(0).is_cell () || args(1).is_cell () || args(2).is_cell ())
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1172 {
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1173 Cell str;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1174 Cell pat;
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1175 Cell rep;
6495
fd09c7e8c4c9 [project @ 2007-04-05 16:18:20 by dbateman]
dbateman
parents: 6361
diff changeset
1176 dim_vector dv0;
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1177 dim_vector dv1 (1, 1);
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1178
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1179 if (args(0).is_cell ())
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1180 str = args(0).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1181 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1182 str = Cell (args(0));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1183
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1184 if (args(1).is_cell ())
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1185 pat = args(1).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1186 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1187 pat = Cell (args(1));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1188
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1189 if (args(2).is_cell ())
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1190 rep = args(2).cell_value ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1191 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1192 rep = Cell (args(2));
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1193
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1194 dv0 = str.dims ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1195 if (pat.numel () != 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1196 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1197 dv1 = pat.dims ();
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1198 if (rep.numel () != 1 && dv1 != rep.dims ())
14024
fc9f204faea0 refactor regexp (bug #34440)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1199 error ("regexprep: inconsistent cell array dimensions");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1200 }
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1201 else if (rep.numel () != 1)
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1202 dv1 = rep.dims ();
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1203
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1204 if (!error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1205 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1206 Cell ret (dv0);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1207 octave_value_list new_args = args;
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1208
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1209 for (octave_idx_type i = 0; i < dv0.numel (); i++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1210 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1211 new_args(0) = str(i);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1212 if (pat.numel() == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1213 new_args(1) = pat(0);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1214 if (rep.numel() == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1215 new_args(2) = rep(0);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1216
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1217 for (octave_idx_type j = 0; j < dv1.numel (); j++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1218 {
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1219 if (pat.numel () != 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1220 new_args(1) = pat(j);
13227
9559417aa965 maint: regexp.cc style fixes
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
1221 if (rep.numel () != 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1222 new_args(2) = rep(j);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1223 new_args(0) = octregexprep (new_args, "regexprep");
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1224
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1225 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1226 break;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1227 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1228
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1229 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1230 break;
6495
fd09c7e8c4c9 [project @ 2007-04-05 16:18:20 by dbateman]
dbateman
parents: 6361
diff changeset
1231
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1232 ret(i) = new_args(0);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1233 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1234
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1235 if (!error_state)
13311
d590d9df5596 regexprep: only return cell array if first arg is cell array
John W. Eaton <jwe@octave.org>
parents: 13310
diff changeset
1236 retval = args(0).is_cell ()
d590d9df5596 regexprep: only return cell array if first arg is cell array
John W. Eaton <jwe@octave.org>
parents: 13310
diff changeset
1237 ? octave_value (ret) : octave_value (ret(0));
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
1238 }
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1239 }
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1240 else
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1241 retval = octregexprep (args, "regexprep");
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1242
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1243 return retval;
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1244 }
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1245
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1246 /*
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1247 %!test # Replace with empty
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1248 %! 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
1249 %! t = regexprep (xml, '<[!?][^>]*>', '');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1250 %! assert (t, ' <tag v="hello">some stuff</tag>');
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1251
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1252 %!test # Replace with non-empty
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1253 %! 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
1254 %! t = regexprep (xml, '<[!?][^>]*>', '?');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1255 %! assert (t, '? <tag v="hello">some stuff?</tag>');
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1256
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1257 %!test # Check that 'tokenize' is ignored
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1258 %! 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
1259 %! t = regexprep (xml, '<[!?][^>]*>', '', 'tokenize');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1260 %! assert (t, ' <tag v="hello">some stuff</tag>');
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1261
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
1262 ## Test capture replacement
12462
e4dbfe3019b1 Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents: 12433
diff changeset
1263 %!test
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7237
diff changeset
1264 %! data = "Bob Smith\nDavid Hollerith\nSam Jenkins";
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7237
diff changeset
1265 %! 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
1266 %! 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
1267 %! assert (t, result);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1268
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11025
diff changeset
1269 ## 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
1270 %!assert (regexprep ('hello', 'world', 'earth'), 'hello')
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1271
14536
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1272 ## Test emptymatch
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1273 %!assert (regexprep ('World', '^', 'Hello '), 'World')
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1274 %!assert (regexprep ('World', '^', 'Hello ', 'emptymatch'), 'Hello World')
6d5c951ec520 Add 'emptymatch', 'noemptymatch' options to regular expressions.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1275
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1276 ## 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
1277 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Za-z0-9_]", "_"), "a_b_c_d_e_f_g")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1278
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1279 ## 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
1280 %!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
1281 %!assert (regexprep ("a[b]c{d}e-f=g", "g", "_"), "a[b]c{d}e-f=_")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1282
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1283 ## Options
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1284 %!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
1285 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "ignorecase"), "a_b_c_d_e_f_g")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1286
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1287 ## Option combinations
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1288 %!assert (regexprep ("a[b]c{d}e-f=g", "[^A-Z0-9_]", "_", "once", "ignorecase"), "a_b]c{d}e-f=g")
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1289
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1290 ## End conditions on replacement
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1291 %!assert (regexprep ("abc", "(b)", ".$1"), "a.bc");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1292 %!assert (regexprep ("abc", "(b)", "$1"), "abc");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1293 %!assert (regexprep ("abc", "(b)", "$1."), "ab.c");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1294 %!assert (regexprep ("abc", "(b)", "$1.."), "ab..c");
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1295
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1296 ## 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
1297 %!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
1298 %!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
1299 %!assert (regexprep ({"abc","cba"}, {"b","a"}, {"?","!"}), {"!?c","c?!"})
6361
776e657c9422 [project @ 2007-02-27 09:45:03 by dbateman]
dbateman
parents: 5866
diff changeset
1300
8093
dcc31f473596 Treat PCRE lookbehind operators in a manner that is approximately correct
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
1301 # Nasty lookbehind expression
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14496
diff changeset
1302 %!assert (regexprep ('x^(-1)+y(-1)+z(-1)=0', '(?<=[a-z]+)\(\-[1-9]*\)', '_minus1'),'x^(-1)+y_minus1+z_minus1=0')
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5779
diff changeset
1303 */