annotate libstdc++-v3/include/tr1/regex @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // class template regex -*- C++ -*-
kono
parents:
diff changeset
2
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3 // Copyright (C) 2007-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4 //
kono
parents:
diff changeset
5 // This file is part of the GNU ISO C++ Library. This library is free
kono
parents:
diff changeset
6 // software; you can redistribute it and/or modify it under the
kono
parents:
diff changeset
7 // terms of the GNU General Public License as published by the
kono
parents:
diff changeset
8 // Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 // This library is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /**
kono
parents:
diff changeset
26 * @file tr1/regex
kono
parents:
diff changeset
27 * @author Stephen M. Webb <stephen.webb@bregmasoft.ca>
kono
parents:
diff changeset
28 * This is a TR1 C++ Library header.
kono
parents:
diff changeset
29 */
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 #ifndef _GLIBCXX_TR1_REGEX
kono
parents:
diff changeset
32 #define _GLIBCXX_TR1_REGEX 1
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 #pragma GCC system_header
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 #include <algorithm>
kono
parents:
diff changeset
37 #include <bitset>
kono
parents:
diff changeset
38 #include <iterator>
kono
parents:
diff changeset
39 #include <locale>
kono
parents:
diff changeset
40 #include <stdexcept>
kono
parents:
diff changeset
41 #include <string>
kono
parents:
diff changeset
42 #include <vector>
kono
parents:
diff changeset
43 #include <utility>
kono
parents:
diff changeset
44 #include <sstream>
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 namespace std _GLIBCXX_VISIBILITY(default)
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 namespace tr1
kono
parents:
diff changeset
51 {
kono
parents:
diff changeset
52 /**
kono
parents:
diff changeset
53 * @defgroup tr1_regex Regular Expressions
kono
parents:
diff changeset
54 * A facility for performing regular expression pattern matching.
kono
parents:
diff changeset
55 */
kono
parents:
diff changeset
56 //@{
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 /** @namespace std::regex_constants
kono
parents:
diff changeset
59 * @brief ISO C++ 0x entities sub namespace for regex.
kono
parents:
diff changeset
60 */
kono
parents:
diff changeset
61 namespace regex_constants
kono
parents:
diff changeset
62 {
kono
parents:
diff changeset
63 /**
kono
parents:
diff changeset
64 * @name 5.1 Regular Expression Syntax Options
kono
parents:
diff changeset
65 */
kono
parents:
diff changeset
66 //@{
kono
parents:
diff changeset
67 enum __syntax_option
kono
parents:
diff changeset
68 {
kono
parents:
diff changeset
69 _S_icase,
kono
parents:
diff changeset
70 _S_nosubs,
kono
parents:
diff changeset
71 _S_optimize,
kono
parents:
diff changeset
72 _S_collate,
kono
parents:
diff changeset
73 _S_ECMAScript,
kono
parents:
diff changeset
74 _S_basic,
kono
parents:
diff changeset
75 _S_extended,
kono
parents:
diff changeset
76 _S_awk,
kono
parents:
diff changeset
77 _S_grep,
kono
parents:
diff changeset
78 _S_egrep,
kono
parents:
diff changeset
79 _S_syntax_last
kono
parents:
diff changeset
80 };
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 /**
kono
parents:
diff changeset
83 * @brief This is a bitmask type indicating how to interpret the regex.
kono
parents:
diff changeset
84 *
kono
parents:
diff changeset
85 * The @c syntax_option_type is implementation defined but it is valid to
kono
parents:
diff changeset
86 * perform bitwise operations on these values and expect the right thing to
kono
parents:
diff changeset
87 * happen.
kono
parents:
diff changeset
88 *
kono
parents:
diff changeset
89 * A valid value of type syntax_option_type shall have exactly one of the
kono
parents:
diff changeset
90 * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
kono
parents:
diff changeset
91 * %set.
kono
parents:
diff changeset
92 */
kono
parents:
diff changeset
93 typedef unsigned int syntax_option_type;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 /**
kono
parents:
diff changeset
96 * Specifies that the matching of regular expressions against a character
kono
parents:
diff changeset
97 * sequence shall be performed without regard to case.
kono
parents:
diff changeset
98 */
kono
parents:
diff changeset
99 static const syntax_option_type icase = 1 << _S_icase;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /**
kono
parents:
diff changeset
102 * Specifies that when a regular expression is matched against a character
kono
parents:
diff changeset
103 * container sequence, no sub-expression matches are to be stored in the
kono
parents:
diff changeset
104 * supplied match_results structure.
kono
parents:
diff changeset
105 */
kono
parents:
diff changeset
106 static const syntax_option_type nosubs = 1 << _S_nosubs;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 /**
kono
parents:
diff changeset
109 * Specifies that the regular expression engine should pay more attention to
kono
parents:
diff changeset
110 * the speed with which regular expressions are matched, and less to the
kono
parents:
diff changeset
111 * speed with which regular expression objects are constructed. Otherwise
kono
parents:
diff changeset
112 * it has no detectable effect on the program output.
kono
parents:
diff changeset
113 */
kono
parents:
diff changeset
114 static const syntax_option_type optimize = 1 << _S_optimize;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 /**
kono
parents:
diff changeset
117 * Specifies that character ranges of the form [a-b] should be locale
kono
parents:
diff changeset
118 * sensitive.
kono
parents:
diff changeset
119 */
kono
parents:
diff changeset
120 static const syntax_option_type collate = 1 << _S_collate;
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 /**
kono
parents:
diff changeset
123 * Specifies that the grammar recognized by the regular expression engine is
kono
parents:
diff changeset
124 * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
kono
parents:
diff changeset
125 * Language Specification, Standard Ecma-262, third edition, 1999], as
kono
parents:
diff changeset
126 * modified in tr1 section [7.13]. This grammar is similar to that defined
kono
parents:
diff changeset
127 * in the PERL scripting language but extended with elements found in the
kono
parents:
diff changeset
128 * POSIX regular expression grammar.
kono
parents:
diff changeset
129 */
kono
parents:
diff changeset
130 static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 /**
kono
parents:
diff changeset
133 * Specifies that the grammar recognized by the regular expression engine is
kono
parents:
diff changeset
134 * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
kono
parents:
diff changeset
135 * Portable Operating System Interface (POSIX), Base Definitions and
kono
parents:
diff changeset
136 * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
kono
parents:
diff changeset
137 * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
kono
parents:
diff changeset
138 */
kono
parents:
diff changeset
139 static const syntax_option_type basic = 1 << _S_basic;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 /**
kono
parents:
diff changeset
142 * Specifies that the grammar recognized by the regular expression engine is
kono
parents:
diff changeset
143 * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
kono
parents:
diff changeset
144 * Portable Operating System Interface (POSIX), Base Definitions and Headers,
kono
parents:
diff changeset
145 * Section 9, Regular Expressions.
kono
parents:
diff changeset
146 */
kono
parents:
diff changeset
147 static const syntax_option_type extended = 1 << _S_extended;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /**
kono
parents:
diff changeset
150 * Specifies that the grammar recognized by the regular expression engine is
kono
parents:
diff changeset
151 * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
kono
parents:
diff changeset
152 * identical to syntax_option_type extended, except that C-style escape
kono
parents:
diff changeset
153 * sequences are supported. These sequences are:
kono
parents:
diff changeset
154 * \\\\, \\a, \\b, \\f,
kono
parents:
diff changeset
155 * \\n, \\r, \\t , \\v,
kono
parents:
diff changeset
156 * \\&apos;, &apos;, and \\ddd
kono
parents:
diff changeset
157 * (where ddd is one, two, or three octal digits).
kono
parents:
diff changeset
158 */
kono
parents:
diff changeset
159 static const syntax_option_type awk = 1 << _S_awk;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 /**
kono
parents:
diff changeset
162 * Specifies that the grammar recognized by the regular expression engine is
kono
parents:
diff changeset
163 * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
kono
parents:
diff changeset
164 * identical to syntax_option_type basic, except that newlines are treated
kono
parents:
diff changeset
165 * as whitespace.
kono
parents:
diff changeset
166 */
kono
parents:
diff changeset
167 static const syntax_option_type grep = 1 << _S_grep;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 /**
kono
parents:
diff changeset
170 * Specifies that the grammar recognized by the regular expression engine is
kono
parents:
diff changeset
171 * that used by POSIX utility grep when given the -E option in
kono
parents:
diff changeset
172 * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
kono
parents:
diff changeset
173 * extended, except that newlines are treated as whitespace.
kono
parents:
diff changeset
174 */
kono
parents:
diff changeset
175 static const syntax_option_type egrep = 1 << _S_egrep;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 //@}
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 /**
kono
parents:
diff changeset
180 * @name 5.2 Matching Rules
kono
parents:
diff changeset
181 *
kono
parents:
diff changeset
182 * Matching a regular expression against a sequence of characters [first,
kono
parents:
diff changeset
183 * last) proceeds according to the rules of the grammar specified for the
kono
parents:
diff changeset
184 * regular expression object, modified according to the effects listed
kono
parents:
diff changeset
185 * below for any bitmask elements set.
kono
parents:
diff changeset
186 *
kono
parents:
diff changeset
187 */
kono
parents:
diff changeset
188 //@{
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 enum __match_flag
kono
parents:
diff changeset
191 {
kono
parents:
diff changeset
192 _S_not_bol,
kono
parents:
diff changeset
193 _S_not_eol,
kono
parents:
diff changeset
194 _S_not_bow,
kono
parents:
diff changeset
195 _S_not_eow,
kono
parents:
diff changeset
196 _S_any,
kono
parents:
diff changeset
197 _S_not_null,
kono
parents:
diff changeset
198 _S_continuous,
kono
parents:
diff changeset
199 _S_prev_avail,
kono
parents:
diff changeset
200 _S_sed,
kono
parents:
diff changeset
201 _S_no_copy,
kono
parents:
diff changeset
202 _S_first_only,
kono
parents:
diff changeset
203 _S_match_flag_last
kono
parents:
diff changeset
204 };
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 /**
kono
parents:
diff changeset
207 * @brief This is a bitmask type indicating regex matching rules.
kono
parents:
diff changeset
208 *
kono
parents:
diff changeset
209 * The @c match_flag_type is implementation defined but it is valid to
kono
parents:
diff changeset
210 * perform bitwise operations on these values and expect the right thing to
kono
parents:
diff changeset
211 * happen.
kono
parents:
diff changeset
212 */
kono
parents:
diff changeset
213 typedef std::bitset<_S_match_flag_last> match_flag_type;
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 /**
kono
parents:
diff changeset
216 * The default matching rules.
kono
parents:
diff changeset
217 */
kono
parents:
diff changeset
218 static const match_flag_type match_default = 0;
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 /**
kono
parents:
diff changeset
221 * The first character in the sequence [first, last) is treated as though it
kono
parents:
diff changeset
222 * is not at the beginning of a line, so the character (^) in the regular
kono
parents:
diff changeset
223 * expression shall not match [first, first).
kono
parents:
diff changeset
224 */
kono
parents:
diff changeset
225 static const match_flag_type match_not_bol = 1 << _S_not_bol;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 /**
kono
parents:
diff changeset
228 * The last character in the sequence [first, last) is treated as though it
kono
parents:
diff changeset
229 * is not at the end of a line, so the character ($) in the regular
kono
parents:
diff changeset
230 * expression shall not match [last, last).
kono
parents:
diff changeset
231 */
kono
parents:
diff changeset
232 static const match_flag_type match_not_eol = 1 << _S_not_eol;
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 /**
kono
parents:
diff changeset
235 * The expression \\b is not matched against the sub-sequence
kono
parents:
diff changeset
236 * [first,first).
kono
parents:
diff changeset
237 */
kono
parents:
diff changeset
238 static const match_flag_type match_not_bow = 1 << _S_not_bow;
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 /**
kono
parents:
diff changeset
241 * The expression \\b should not be matched against the sub-sequence
kono
parents:
diff changeset
242 * [last,last).
kono
parents:
diff changeset
243 */
kono
parents:
diff changeset
244 static const match_flag_type match_not_eow = 1 << _S_not_eow;
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 /**
kono
parents:
diff changeset
247 * If more than one match is possible then any match is an acceptable
kono
parents:
diff changeset
248 * result.
kono
parents:
diff changeset
249 */
kono
parents:
diff changeset
250 static const match_flag_type match_any = 1 << _S_any;
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 /**
kono
parents:
diff changeset
253 * The expression does not match an empty sequence.
kono
parents:
diff changeset
254 */
kono
parents:
diff changeset
255 static const match_flag_type match_not_null = 1 << _S_not_null;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 /**
kono
parents:
diff changeset
258 * The expression only matches a sub-sequence that begins at first .
kono
parents:
diff changeset
259 */
kono
parents:
diff changeset
260 static const match_flag_type match_continuous = 1 << _S_continuous;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 /**
kono
parents:
diff changeset
263 * --first is a valid iterator position. When this flag is set then the
kono
parents:
diff changeset
264 * flags match_not_bol and match_not_bow are ignored by the regular
kono
parents:
diff changeset
265 * expression algorithms 7.11 and iterators 7.12.
kono
parents:
diff changeset
266 */
kono
parents:
diff changeset
267 static const match_flag_type match_prev_avail = 1 << _S_prev_avail;
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 /**
kono
parents:
diff changeset
270 * When a regular expression match is to be replaced by a new string, the
kono
parents:
diff changeset
271 * new string is constructed using the rules used by the ECMAScript replace
kono
parents:
diff changeset
272 * function in ECMA- 262 [Ecma International, ECMAScript Language
kono
parents:
diff changeset
273 * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
kono
parents:
diff changeset
274 * String.prototype.replace. In addition, during search and replace
kono
parents:
diff changeset
275 * operations all non-overlapping occurrences of the regular expression
kono
parents:
diff changeset
276 * are located and replaced, and sections of the input that did not match
kono
parents:
diff changeset
277 * the expression are copied unchanged to the output string.
kono
parents:
diff changeset
278 *
kono
parents:
diff changeset
279 * Format strings (from ECMA-262 [15.5.4.11]):
kono
parents:
diff changeset
280 * @li $$ The dollar-sign itself ($)
kono
parents:
diff changeset
281 * @li $& The matched substring.
kono
parents:
diff changeset
282 * @li $` The portion of @a string that precedes the matched substring.
kono
parents:
diff changeset
283 * This would be match_results::prefix().
kono
parents:
diff changeset
284 * @li $' The portion of @a string that follows the matched substring.
kono
parents:
diff changeset
285 * This would be match_results::suffix().
kono
parents:
diff changeset
286 * @li $n The nth capture, where n is in [1,9] and $n is not followed by a
kono
parents:
diff changeset
287 * decimal digit. If n <= match_results::size() and the nth capture
kono
parents:
diff changeset
288 * is undefined, use the empty string instead. If n >
kono
parents:
diff changeset
289 * match_results::size(), the result is implementation-defined.
kono
parents:
diff changeset
290 * @li $nn The nnth capture, where nn is a two-digit decimal number on
kono
parents:
diff changeset
291 * [01, 99]. If nn <= match_results::size() and the nth capture is
kono
parents:
diff changeset
292 * undefined, use the empty string instead. If
kono
parents:
diff changeset
293 * nn > match_results::size(), the result is implementation-defined.
kono
parents:
diff changeset
294 */
kono
parents:
diff changeset
295 static const match_flag_type format_default = 0;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 /**
kono
parents:
diff changeset
298 * When a regular expression match is to be replaced by a new string, the
kono
parents:
diff changeset
299 * new string is constructed using the rules used by the POSIX sed utility
kono
parents:
diff changeset
300 * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
kono
parents:
diff changeset
301 * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
kono
parents:
diff changeset
302 */
kono
parents:
diff changeset
303 static const match_flag_type format_sed = 1 << _S_sed;
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 /**
kono
parents:
diff changeset
306 * During a search and replace operation, sections of the character
kono
parents:
diff changeset
307 * container sequence being searched that do not match the regular
kono
parents:
diff changeset
308 * expression shall not be copied to the output string.
kono
parents:
diff changeset
309 */
kono
parents:
diff changeset
310 static const match_flag_type format_no_copy = 1 << _S_no_copy;
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 /**
kono
parents:
diff changeset
313 * When specified during a search and replace operation, only the first
kono
parents:
diff changeset
314 * occurrence of the regular expression shall be replaced.
kono
parents:
diff changeset
315 */
kono
parents:
diff changeset
316 static const match_flag_type format_first_only = 1 << _S_first_only;
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 //@}
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 /**
kono
parents:
diff changeset
321 * @name 5.3 Error Types
kono
parents:
diff changeset
322 */
kono
parents:
diff changeset
323 //@{
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 enum error_type
kono
parents:
diff changeset
326 {
kono
parents:
diff changeset
327 _S_error_collate,
kono
parents:
diff changeset
328 _S_error_ctype,
kono
parents:
diff changeset
329 _S_error_escape,
kono
parents:
diff changeset
330 _S_error_backref,
kono
parents:
diff changeset
331 _S_error_brack,
kono
parents:
diff changeset
332 _S_error_paren,
kono
parents:
diff changeset
333 _S_error_brace,
kono
parents:
diff changeset
334 _S_error_badbrace,
kono
parents:
diff changeset
335 _S_error_range,
kono
parents:
diff changeset
336 _S_error_space,
kono
parents:
diff changeset
337 _S_error_badrepeat,
kono
parents:
diff changeset
338 _S_error_complexity,
kono
parents:
diff changeset
339 _S_error_stack,
kono
parents:
diff changeset
340 _S_error_last
kono
parents:
diff changeset
341 };
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 /** The expression contained an invalid collating element name. */
kono
parents:
diff changeset
344 static const error_type error_collate(_S_error_collate);
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 /** The expression contained an invalid character class name. */
kono
parents:
diff changeset
347 static const error_type error_ctype(_S_error_ctype);
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 /**
kono
parents:
diff changeset
350 * The expression contained an invalid escaped character, or a trailing
kono
parents:
diff changeset
351 * escape.
kono
parents:
diff changeset
352 */
kono
parents:
diff changeset
353 static const error_type error_escape(_S_error_escape);
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 /** The expression contained an invalid back reference. */
kono
parents:
diff changeset
356 static const error_type error_backref(_S_error_backref);
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 /** The expression contained mismatched [ and ]. */
kono
parents:
diff changeset
359 static const error_type error_brack(_S_error_brack);
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 /** The expression contained mismatched ( and ). */
kono
parents:
diff changeset
362 static const error_type error_paren(_S_error_paren);
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 /** The expression contained mismatched { and } */
kono
parents:
diff changeset
365 static const error_type error_brace(_S_error_brace);
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 /** The expression contained an invalid range in a {} expression. */
kono
parents:
diff changeset
368 static const error_type error_badbrace(_S_error_badbrace);
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 /**
kono
parents:
diff changeset
371 * The expression contained an invalid character range,
kono
parents:
diff changeset
372 * such as [b-a] in most encodings.
kono
parents:
diff changeset
373 */
kono
parents:
diff changeset
374 static const error_type error_range(_S_error_range);
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 /**
kono
parents:
diff changeset
377 * There was insufficient memory to convert the expression into a
kono
parents:
diff changeset
378 * finite state machine.
kono
parents:
diff changeset
379 */
kono
parents:
diff changeset
380 static const error_type error_space(_S_error_space);
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 /**
kono
parents:
diff changeset
383 * One of <em>*?+{</em> was not preceded by a valid regular expression.
kono
parents:
diff changeset
384 */
kono
parents:
diff changeset
385 static const error_type error_badrepeat(_S_error_badrepeat);
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 /**
kono
parents:
diff changeset
388 * The complexity of an attempted match against a regular expression
kono
parents:
diff changeset
389 * exceeded a pre-set level.
kono
parents:
diff changeset
390 */
kono
parents:
diff changeset
391 static const error_type error_complexity(_S_error_complexity);
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 /**
kono
parents:
diff changeset
394 * There was insufficient memory to determine whether the
kono
parents:
diff changeset
395 * regular expression could match the specified character sequence.
kono
parents:
diff changeset
396 */
kono
parents:
diff changeset
397 static const error_type error_stack(_S_error_stack);
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 //@}
kono
parents:
diff changeset
400 }
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 // [7.8] Class regex_error
kono
parents:
diff changeset
403 /**
kono
parents:
diff changeset
404 * @brief A regular expression exception class.
kono
parents:
diff changeset
405 * @ingroup exceptions
kono
parents:
diff changeset
406 *
kono
parents:
diff changeset
407 * The regular expression library throws objects of this class on error.
kono
parents:
diff changeset
408 */
kono
parents:
diff changeset
409 class regex_error
kono
parents:
diff changeset
410 : public std::runtime_error
kono
parents:
diff changeset
411 {
kono
parents:
diff changeset
412 public:
kono
parents:
diff changeset
413 /**
kono
parents:
diff changeset
414 * @brief Constructs a regex_error object.
kono
parents:
diff changeset
415 *
kono
parents:
diff changeset
416 * @param ecode the regex error code.
kono
parents:
diff changeset
417 */
kono
parents:
diff changeset
418 explicit
kono
parents:
diff changeset
419 regex_error(regex_constants::error_type __ecode)
kono
parents:
diff changeset
420 : std::runtime_error("regex_error"), _M_code(__ecode)
kono
parents:
diff changeset
421 { }
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 /**
kono
parents:
diff changeset
424 * @brief Gets the regex error code.
kono
parents:
diff changeset
425 *
kono
parents:
diff changeset
426 * @returns the regex error code.
kono
parents:
diff changeset
427 */
kono
parents:
diff changeset
428 regex_constants::error_type
kono
parents:
diff changeset
429 code() const
kono
parents:
diff changeset
430 { return _M_code; }
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 protected:
kono
parents:
diff changeset
433 regex_constants::error_type _M_code;
kono
parents:
diff changeset
434 };
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 // [7.7] Class regex_traits
kono
parents:
diff changeset
437 /**
kono
parents:
diff changeset
438 * @brief Describes aspects of a regular expression.
kono
parents:
diff changeset
439 *
kono
parents:
diff changeset
440 * A regular expression traits class that satisfies the requirements of tr1
kono
parents:
diff changeset
441 * section [7.2].
kono
parents:
diff changeset
442 *
kono
parents:
diff changeset
443 * The class %regex is parameterized around a set of related types and
kono
parents:
diff changeset
444 * functions used to complete the definition of its semantics. This class
kono
parents:
diff changeset
445 * satisfies the requirements of such a traits class.
kono
parents:
diff changeset
446 */
kono
parents:
diff changeset
447 template<typename _Ch_type>
kono
parents:
diff changeset
448 struct regex_traits
kono
parents:
diff changeset
449 {
kono
parents:
diff changeset
450 public:
kono
parents:
diff changeset
451 typedef _Ch_type char_type;
kono
parents:
diff changeset
452 typedef std::basic_string<char_type> string_type;
kono
parents:
diff changeset
453 typedef std::locale locale_type;
kono
parents:
diff changeset
454 typedef std::ctype_base::mask char_class_type;
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 public:
kono
parents:
diff changeset
457 /**
kono
parents:
diff changeset
458 * @brief Constructs a default traits object.
kono
parents:
diff changeset
459 */
kono
parents:
diff changeset
460 regex_traits()
kono
parents:
diff changeset
461 { }
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 /**
kono
parents:
diff changeset
464 * @brief Gives the length of a C-style string starting at @p __p.
kono
parents:
diff changeset
465 *
kono
parents:
diff changeset
466 * @param __p a pointer to the start of a character sequence.
kono
parents:
diff changeset
467 *
kono
parents:
diff changeset
468 * @returns the number of characters between @p *__p and the first
kono
parents:
diff changeset
469 * default-initialized value of type @p char_type. In other words, uses
kono
parents:
diff changeset
470 * the C-string algorithm for determining the length of a sequence of
kono
parents:
diff changeset
471 * characters.
kono
parents:
diff changeset
472 */
kono
parents:
diff changeset
473 static std::size_t
kono
parents:
diff changeset
474 length(const char_type* __p)
kono
parents:
diff changeset
475 { return string_type::traits_type::length(__p); }
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 /**
kono
parents:
diff changeset
478 * @brief Performs the identity translation.
kono
parents:
diff changeset
479 *
kono
parents:
diff changeset
480 * @param c A character to the locale-specific character set.
kono
parents:
diff changeset
481 *
kono
parents:
diff changeset
482 * @returns c.
kono
parents:
diff changeset
483 */
kono
parents:
diff changeset
484 char_type
kono
parents:
diff changeset
485 translate(char_type __c) const
kono
parents:
diff changeset
486 { return __c; }
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 /**
kono
parents:
diff changeset
489 * @brief Translates a character into a case-insensitive equivalent.
kono
parents:
diff changeset
490 *
kono
parents:
diff changeset
491 * @param c A character to the locale-specific character set.
kono
parents:
diff changeset
492 *
kono
parents:
diff changeset
493 * @returns the locale-specific lower-case equivalent of c.
kono
parents:
diff changeset
494 * @throws std::bad_cast if the imbued locale does not support the ctype
kono
parents:
diff changeset
495 * facet.
kono
parents:
diff changeset
496 */
kono
parents:
diff changeset
497 char_type
kono
parents:
diff changeset
498 translate_nocase(char_type __c) const
kono
parents:
diff changeset
499 {
kono
parents:
diff changeset
500 using std::ctype;
kono
parents:
diff changeset
501 using std::use_facet;
kono
parents:
diff changeset
502 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
kono
parents:
diff changeset
503 }
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 /**
kono
parents:
diff changeset
506 * @brief Gets a sort key for a character sequence.
kono
parents:
diff changeset
507 *
kono
parents:
diff changeset
508 * @param first beginning of the character sequence.
kono
parents:
diff changeset
509 * @param last one-past-the-end of the character sequence.
kono
parents:
diff changeset
510 *
kono
parents:
diff changeset
511 * Returns a sort key for the character sequence designated by the
kono
parents:
diff changeset
512 * iterator range [F1, F2) such that if the character sequence [G1, G2)
kono
parents:
diff changeset
513 * sorts before the character sequence [H1, H2) then
kono
parents:
diff changeset
514 * v.transform(G1, G2) < v.transform(H1, H2).
kono
parents:
diff changeset
515 *
kono
parents:
diff changeset
516 * What this really does is provide a more efficient way to compare a
kono
parents:
diff changeset
517 * string to multiple other strings in locales with fancy collation
kono
parents:
diff changeset
518 * rules and equivalence classes.
kono
parents:
diff changeset
519 *
kono
parents:
diff changeset
520 * @returns a locale-specific sort key equivalent to the input range.
kono
parents:
diff changeset
521 *
kono
parents:
diff changeset
522 * @throws std::bad_cast if the current locale does not have a collate
kono
parents:
diff changeset
523 * facet.
kono
parents:
diff changeset
524 */
kono
parents:
diff changeset
525 template<typename _Fwd_iter>
kono
parents:
diff changeset
526 string_type
kono
parents:
diff changeset
527 transform(_Fwd_iter __first, _Fwd_iter __last) const
kono
parents:
diff changeset
528 {
kono
parents:
diff changeset
529 using std::collate;
kono
parents:
diff changeset
530 using std::use_facet;
kono
parents:
diff changeset
531 const collate<_Ch_type>& __c(use_facet<
kono
parents:
diff changeset
532 collate<_Ch_type> >(_M_locale));
kono
parents:
diff changeset
533 string_type __s(__first, __last);
kono
parents:
diff changeset
534 return __c.transform(__s.data(), __s.data() + __s.size());
kono
parents:
diff changeset
535 }
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 /**
kono
parents:
diff changeset
538 * @brief Dunno.
kono
parents:
diff changeset
539 *
kono
parents:
diff changeset
540 * @param first beginning of the character sequence.
kono
parents:
diff changeset
541 * @param last one-past-the-end of the character sequence.
kono
parents:
diff changeset
542 *
kono
parents:
diff changeset
543 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
kono
parents:
diff changeset
544 * typeid(collate_byname<_Ch_type>) and the form of the sort key
kono
parents:
diff changeset
545 * returned by collate_byname<_Ch_type>::transform(first, last) is known
kono
parents:
diff changeset
546 * and can be converted into a primary sort key then returns that key,
kono
parents:
diff changeset
547 * otherwise returns an empty string. WTF??
kono
parents:
diff changeset
548 *
kono
parents:
diff changeset
549 * @todo Implement this function.
kono
parents:
diff changeset
550 */
kono
parents:
diff changeset
551 template<typename _Fwd_iter>
kono
parents:
diff changeset
552 string_type
kono
parents:
diff changeset
553 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 /**
kono
parents:
diff changeset
556 * @brief Gets a collation element by name.
kono
parents:
diff changeset
557 *
kono
parents:
diff changeset
558 * @param first beginning of the collation element name.
kono
parents:
diff changeset
559 * @param last one-past-the-end of the collation element name.
kono
parents:
diff changeset
560 *
kono
parents:
diff changeset
561 * @returns a sequence of one or more characters that represents the
kono
parents:
diff changeset
562 * collating element consisting of the character sequence designated by
kono
parents:
diff changeset
563 * the iterator range [first, last). Returns an empty string if the
kono
parents:
diff changeset
564 * character sequence is not a valid collating element.
kono
parents:
diff changeset
565 *
kono
parents:
diff changeset
566 * @todo Implement this function.
kono
parents:
diff changeset
567 */
kono
parents:
diff changeset
568 template<typename _Fwd_iter>
kono
parents:
diff changeset
569 string_type
kono
parents:
diff changeset
570 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 /**
kono
parents:
diff changeset
573 * @brief Maps one or more characters to a named character
kono
parents:
diff changeset
574 * classification.
kono
parents:
diff changeset
575 *
kono
parents:
diff changeset
576 * @param first beginning of the character sequence.
kono
parents:
diff changeset
577 * @param last one-past-the-end of the character sequence.
kono
parents:
diff changeset
578 *
kono
parents:
diff changeset
579 * @returns an unspecified value that represents the character
kono
parents:
diff changeset
580 * classification named by the character sequence designated by the
kono
parents:
diff changeset
581 * iterator range [first, last). The value returned shall be independent
kono
parents:
diff changeset
582 * of the case of the characters in the character sequence. If the name
kono
parents:
diff changeset
583 * is not recognized then returns a value that compares equal to 0.
kono
parents:
diff changeset
584 *
kono
parents:
diff changeset
585 * At least the following names (or their wide-character equivalent) are
kono
parents:
diff changeset
586 * supported.
kono
parents:
diff changeset
587 * - d
kono
parents:
diff changeset
588 * - w
kono
parents:
diff changeset
589 * - s
kono
parents:
diff changeset
590 * - alnum
kono
parents:
diff changeset
591 * - alpha
kono
parents:
diff changeset
592 * - blank
kono
parents:
diff changeset
593 * - cntrl
kono
parents:
diff changeset
594 * - digit
kono
parents:
diff changeset
595 * - graph
kono
parents:
diff changeset
596 * - lower
kono
parents:
diff changeset
597 * - print
kono
parents:
diff changeset
598 * - punct
kono
parents:
diff changeset
599 * - space
kono
parents:
diff changeset
600 * - upper
kono
parents:
diff changeset
601 * - xdigit
kono
parents:
diff changeset
602 *
kono
parents:
diff changeset
603 * @todo Implement this function.
kono
parents:
diff changeset
604 */
kono
parents:
diff changeset
605 template<typename _Fwd_iter>
kono
parents:
diff changeset
606 char_class_type
kono
parents:
diff changeset
607 lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 /**
kono
parents:
diff changeset
610 * @brief Determines if @p c is a member of an identified class.
kono
parents:
diff changeset
611 *
kono
parents:
diff changeset
612 * @param c a character.
kono
parents:
diff changeset
613 * @param f a class type (as returned from lookup_classname).
kono
parents:
diff changeset
614 *
kono
parents:
diff changeset
615 * @returns true if the character @p c is a member of the classification
kono
parents:
diff changeset
616 * represented by @p f, false otherwise.
kono
parents:
diff changeset
617 *
kono
parents:
diff changeset
618 * @throws std::bad_cast if the current locale does not have a ctype
kono
parents:
diff changeset
619 * facet.
kono
parents:
diff changeset
620 */
kono
parents:
diff changeset
621 bool
kono
parents:
diff changeset
622 isctype(_Ch_type __c, char_class_type __f) const;
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 /**
kono
parents:
diff changeset
625 * @brief Converts a digit to an int.
kono
parents:
diff changeset
626 *
kono
parents:
diff changeset
627 * @param ch a character representing a digit.
kono
parents:
diff changeset
628 * @param radix the radix if the numeric conversion (limited to 8, 10,
kono
parents:
diff changeset
629 * or 16).
kono
parents:
diff changeset
630 *
kono
parents:
diff changeset
631 * @returns the value represented by the digit ch in base radix if the
kono
parents:
diff changeset
632 * character ch is a valid digit in base radix; otherwise returns -1.
kono
parents:
diff changeset
633 */
kono
parents:
diff changeset
634 int
kono
parents:
diff changeset
635 value(_Ch_type __ch, int __radix) const;
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 /**
kono
parents:
diff changeset
638 * @brief Imbues the regex_traits object with a copy of a new locale.
kono
parents:
diff changeset
639 *
kono
parents:
diff changeset
640 * @param loc A locale.
kono
parents:
diff changeset
641 *
kono
parents:
diff changeset
642 * @returns a copy of the previous locale in use by the regex_traits
kono
parents:
diff changeset
643 * object.
kono
parents:
diff changeset
644 *
kono
parents:
diff changeset
645 * @note Calling imbue with a different locale than the one currently in
kono
parents:
diff changeset
646 * use invalidates all cached data held by *this.
kono
parents:
diff changeset
647 */
kono
parents:
diff changeset
648 locale_type
kono
parents:
diff changeset
649 imbue(locale_type __loc)
kono
parents:
diff changeset
650 {
kono
parents:
diff changeset
651 std::swap(_M_locale, __loc);
kono
parents:
diff changeset
652 return __loc;
kono
parents:
diff changeset
653 }
kono
parents:
diff changeset
654
kono
parents:
diff changeset
655 /**
kono
parents:
diff changeset
656 * @brief Gets a copy of the current locale in use by the regex_traits
kono
parents:
diff changeset
657 * object.
kono
parents:
diff changeset
658 */
kono
parents:
diff changeset
659 locale_type
kono
parents:
diff changeset
660 getloc() const
kono
parents:
diff changeset
661 { return _M_locale; }
kono
parents:
diff changeset
662
kono
parents:
diff changeset
663 protected:
kono
parents:
diff changeset
664 locale_type _M_locale;
kono
parents:
diff changeset
665 };
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 template<typename _Ch_type>
kono
parents:
diff changeset
668 bool regex_traits<_Ch_type>::
kono
parents:
diff changeset
669 isctype(_Ch_type __c, char_class_type __f) const
kono
parents:
diff changeset
670 {
kono
parents:
diff changeset
671 using std::ctype;
kono
parents:
diff changeset
672 using std::use_facet;
kono
parents:
diff changeset
673 const ctype<_Ch_type>& __ctype(use_facet<
kono
parents:
diff changeset
674 ctype<_Ch_type> >(_M_locale));
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 if (__ctype.is(__c, __f))
kono
parents:
diff changeset
677 return true;
kono
parents:
diff changeset
678 #if 0
kono
parents:
diff changeset
679 // special case of underscore in [[:w:]]
kono
parents:
diff changeset
680 if (__c == __ctype.widen('_'))
kono
parents:
diff changeset
681 {
kono
parents:
diff changeset
682 const char* const __wb[] = "w";
kono
parents:
diff changeset
683 char_class_type __wt = this->lookup_classname(__wb,
kono
parents:
diff changeset
684 __wb + sizeof(__wb));
kono
parents:
diff changeset
685 if (__f | __wt)
kono
parents:
diff changeset
686 return true;
kono
parents:
diff changeset
687 }
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 // special case of [[:space:]] in [[:blank:]]
kono
parents:
diff changeset
690 if (__c == __ctype.isspace(__c))
kono
parents:
diff changeset
691 {
kono
parents:
diff changeset
692 const char* const __bb[] = "blank";
kono
parents:
diff changeset
693 char_class_type __bt = this->lookup_classname(__bb,
kono
parents:
diff changeset
694 __bb + sizeof(__bb));
kono
parents:
diff changeset
695 if (__f | __bt)
kono
parents:
diff changeset
696 return true;
kono
parents:
diff changeset
697 }
kono
parents:
diff changeset
698 #endif
kono
parents:
diff changeset
699 return false;
kono
parents:
diff changeset
700 }
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 template<typename _Ch_type>
kono
parents:
diff changeset
703 int regex_traits<_Ch_type>::
kono
parents:
diff changeset
704 value(_Ch_type __ch, int __radix) const
kono
parents:
diff changeset
705 {
kono
parents:
diff changeset
706 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
kono
parents:
diff changeset
707 int __v;
kono
parents:
diff changeset
708 if (__radix == 8)
kono
parents:
diff changeset
709 __is >> std::oct;
kono
parents:
diff changeset
710 else if (__radix == 16)
kono
parents:
diff changeset
711 __is >> std::hex;
kono
parents:
diff changeset
712 __is >> __v;
kono
parents:
diff changeset
713 return __is.fail() ? -1 : __v;
kono
parents:
diff changeset
714 }
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 // [7.8] Class basic_regex
kono
parents:
diff changeset
717 /**
kono
parents:
diff changeset
718 * Objects of specializations of this class represent regular expressions
kono
parents:
diff changeset
719 * constructed from sequences of character type @p _Ch_type.
kono
parents:
diff changeset
720 *
kono
parents:
diff changeset
721 * Storage for the regular expression is allocated and deallocated as
kono
parents:
diff changeset
722 * necessary by the member functions of this class.
kono
parents:
diff changeset
723 */
kono
parents:
diff changeset
724 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
kono
parents:
diff changeset
725 class basic_regex
kono
parents:
diff changeset
726 {
kono
parents:
diff changeset
727 public:
kono
parents:
diff changeset
728 // types:
kono
parents:
diff changeset
729 typedef _Ch_type value_type;
kono
parents:
diff changeset
730 typedef regex_constants::syntax_option_type flag_type;
kono
parents:
diff changeset
731 typedef typename _Rx_traits::locale_type locale_type;
kono
parents:
diff changeset
732 typedef typename _Rx_traits::string_type string_type;
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 /**
kono
parents:
diff changeset
735 * @name Constants
kono
parents:
diff changeset
736 * tr1 [7.8.1] std [28.8.1]
kono
parents:
diff changeset
737 */
kono
parents:
diff changeset
738 //@{
kono
parents:
diff changeset
739 static const regex_constants::syntax_option_type icase
kono
parents:
diff changeset
740 = regex_constants::icase;
kono
parents:
diff changeset
741 static const regex_constants::syntax_option_type nosubs
kono
parents:
diff changeset
742 = regex_constants::nosubs;
kono
parents:
diff changeset
743 static const regex_constants::syntax_option_type optimize
kono
parents:
diff changeset
744 = regex_constants::optimize;
kono
parents:
diff changeset
745 static const regex_constants::syntax_option_type collate
kono
parents:
diff changeset
746 = regex_constants::collate;
kono
parents:
diff changeset
747 static const regex_constants::syntax_option_type ECMAScript
kono
parents:
diff changeset
748 = regex_constants::ECMAScript;
kono
parents:
diff changeset
749 static const regex_constants::syntax_option_type basic
kono
parents:
diff changeset
750 = regex_constants::basic;
kono
parents:
diff changeset
751 static const regex_constants::syntax_option_type extended
kono
parents:
diff changeset
752 = regex_constants::extended;
kono
parents:
diff changeset
753 static const regex_constants::syntax_option_type awk
kono
parents:
diff changeset
754 = regex_constants::awk;
kono
parents:
diff changeset
755 static const regex_constants::syntax_option_type grep
kono
parents:
diff changeset
756 = regex_constants::grep;
kono
parents:
diff changeset
757 static const regex_constants::syntax_option_type egrep
kono
parents:
diff changeset
758 = regex_constants::egrep;
kono
parents:
diff changeset
759 //@}
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 // [7.8.2] construct/copy/destroy
kono
parents:
diff changeset
762 /**
kono
parents:
diff changeset
763 * Constructs a basic regular expression that does not match any
kono
parents:
diff changeset
764 * character sequence.
kono
parents:
diff changeset
765 */
kono
parents:
diff changeset
766 basic_regex()
kono
parents:
diff changeset
767 : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
kono
parents:
diff changeset
768 { _M_compile(); }
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 /**
kono
parents:
diff changeset
771 * @brief Constructs a basic regular expression from the sequence
kono
parents:
diff changeset
772 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
kono
parents:
diff changeset
773 * flags in @p f.
kono
parents:
diff changeset
774 *
kono
parents:
diff changeset
775 * @param p A pointer to the start of a C-style null-terminated string
kono
parents:
diff changeset
776 * containing a regular expression.
kono
parents:
diff changeset
777 * @param f Flags indicating the syntax rules and options.
kono
parents:
diff changeset
778 *
kono
parents:
diff changeset
779 * @throws regex_error if @p p is not a valid regular expression.
kono
parents:
diff changeset
780 */
kono
parents:
diff changeset
781 explicit
kono
parents:
diff changeset
782 basic_regex(const _Ch_type* __p,
kono
parents:
diff changeset
783 flag_type __f = regex_constants::ECMAScript)
kono
parents:
diff changeset
784 : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
kono
parents:
diff changeset
785 { _M_compile(); }
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 /**
kono
parents:
diff changeset
788 * @brief Constructs a basic regular expression from the sequence
kono
parents:
diff changeset
789 * [p, p + len) interpreted according to the flags in @p f.
kono
parents:
diff changeset
790 *
kono
parents:
diff changeset
791 * @param p A pointer to the start of a string containing a regular
kono
parents:
diff changeset
792 * expression.
kono
parents:
diff changeset
793 * @param len The length of the string containing the regular expression.
kono
parents:
diff changeset
794 * @param f Flags indicating the syntax rules and options.
kono
parents:
diff changeset
795 *
kono
parents:
diff changeset
796 * @throws regex_error if @p p is not a valid regular expression.
kono
parents:
diff changeset
797 */
kono
parents:
diff changeset
798 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
kono
parents:
diff changeset
799 : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
kono
parents:
diff changeset
800 { _M_compile(); }
kono
parents:
diff changeset
801
kono
parents:
diff changeset
802 /**
kono
parents:
diff changeset
803 * @brief Copy-constructs a basic regular expression.
kono
parents:
diff changeset
804 *
kono
parents:
diff changeset
805 * @param rhs A @p regex object.
kono
parents:
diff changeset
806 */
kono
parents:
diff changeset
807 basic_regex(const basic_regex& __rhs)
kono
parents:
diff changeset
808 : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
kono
parents:
diff changeset
809 _M_mark_count(__rhs._M_mark_count)
kono
parents:
diff changeset
810 { _M_compile(); }
kono
parents:
diff changeset
811
kono
parents:
diff changeset
812 /**
kono
parents:
diff changeset
813 * @brief Constructs a basic regular expression from the string
kono
parents:
diff changeset
814 * @p s interpreted according to the flags in @p f.
kono
parents:
diff changeset
815 *
kono
parents:
diff changeset
816 * @param s A string containing a regular expression.
kono
parents:
diff changeset
817 * @param f Flags indicating the syntax rules and options.
kono
parents:
diff changeset
818 *
kono
parents:
diff changeset
819 * @throws regex_error if @p s is not a valid regular expression.
kono
parents:
diff changeset
820 */
kono
parents:
diff changeset
821 template<typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
822 explicit
kono
parents:
diff changeset
823 basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
kono
parents:
diff changeset
824 flag_type __f = regex_constants::ECMAScript)
kono
parents:
diff changeset
825 : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
kono
parents:
diff changeset
826 { _M_compile(); }
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 /**
kono
parents:
diff changeset
829 * @brief Constructs a basic regular expression from the range
kono
parents:
diff changeset
830 * [first, last) interpreted according to the flags in @p f.
kono
parents:
diff changeset
831 *
kono
parents:
diff changeset
832 * @param first The start of a range containing a valid regular
kono
parents:
diff changeset
833 * expression.
kono
parents:
diff changeset
834 * @param last The end of a range containing a valid regular
kono
parents:
diff changeset
835 * expression.
kono
parents:
diff changeset
836 * @param f The format flags of the regular expression.
kono
parents:
diff changeset
837 *
kono
parents:
diff changeset
838 * @throws regex_error if @p [first, last) is not a valid regular
kono
parents:
diff changeset
839 * expression.
kono
parents:
diff changeset
840 */
kono
parents:
diff changeset
841 template<typename _InputIterator>
kono
parents:
diff changeset
842 basic_regex(_InputIterator __first, _InputIterator __last,
kono
parents:
diff changeset
843 flag_type __f = regex_constants::ECMAScript)
kono
parents:
diff changeset
844 : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
kono
parents:
diff changeset
845 { _M_compile(); }
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
kono
parents:
diff changeset
848 /**
kono
parents:
diff changeset
849 * @brief Constructs a basic regular expression from an initializer list.
kono
parents:
diff changeset
850 *
kono
parents:
diff changeset
851 * @param l The initializer list.
kono
parents:
diff changeset
852 * @param f The format flags of the regular expression.
kono
parents:
diff changeset
853 *
kono
parents:
diff changeset
854 * @throws regex_error if @p l is not a valid regular expression.
kono
parents:
diff changeset
855 */
kono
parents:
diff changeset
856 basic_regex(initializer_list<_Ch_type> __l,
kono
parents:
diff changeset
857 flag_type __f = regex_constants::ECMAScript)
kono
parents:
diff changeset
858 : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
kono
parents:
diff changeset
859 { _M_compile(); }
kono
parents:
diff changeset
860 #endif
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 /**
kono
parents:
diff changeset
863 * @brief Destroys a basic regular expression.
kono
parents:
diff changeset
864 */
kono
parents:
diff changeset
865 ~basic_regex()
kono
parents:
diff changeset
866 { }
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 /**
kono
parents:
diff changeset
869 * @brief Assigns one regular expression to another.
kono
parents:
diff changeset
870 */
kono
parents:
diff changeset
871 basic_regex&
kono
parents:
diff changeset
872 operator=(const basic_regex& __rhs)
kono
parents:
diff changeset
873 { return this->assign(__rhs); }
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 /**
kono
parents:
diff changeset
876 * @brief Replaces a regular expression with a new one constructed from
kono
parents:
diff changeset
877 * a C-style null-terminated string.
kono
parents:
diff changeset
878 *
kono
parents:
diff changeset
879 * @param A pointer to the start of a null-terminated C-style string
kono
parents:
diff changeset
880 * containing a regular expression.
kono
parents:
diff changeset
881 */
kono
parents:
diff changeset
882 basic_regex&
kono
parents:
diff changeset
883 operator=(const _Ch_type* __p)
kono
parents:
diff changeset
884 { return this->assign(__p, flags()); }
kono
parents:
diff changeset
885
kono
parents:
diff changeset
886 /**
kono
parents:
diff changeset
887 * @brief Replaces a regular expression with a new one constructed from
kono
parents:
diff changeset
888 * a string.
kono
parents:
diff changeset
889 *
kono
parents:
diff changeset
890 * @param A pointer to a string containing a regular expression.
kono
parents:
diff changeset
891 */
kono
parents:
diff changeset
892 template<typename _Ch_typeraits, typename _Allocator>
kono
parents:
diff changeset
893 basic_regex&
kono
parents:
diff changeset
894 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
kono
parents:
diff changeset
895 { return this->assign(__s, flags()); }
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 // [7.8.3] assign
kono
parents:
diff changeset
898 /**
kono
parents:
diff changeset
899 * @brief the real assignment operator.
kono
parents:
diff changeset
900 *
kono
parents:
diff changeset
901 * @param that Another regular expression object.
kono
parents:
diff changeset
902 */
kono
parents:
diff changeset
903 basic_regex&
kono
parents:
diff changeset
904 assign(const basic_regex& __that)
kono
parents:
diff changeset
905 {
kono
parents:
diff changeset
906 basic_regex __tmp(__that);
kono
parents:
diff changeset
907 this->swap(__tmp);
kono
parents:
diff changeset
908 return *this;
kono
parents:
diff changeset
909 }
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 /**
kono
parents:
diff changeset
912 * @brief Assigns a new regular expression to a regex object from a
kono
parents:
diff changeset
913 * C-style null-terminated string containing a regular expression
kono
parents:
diff changeset
914 * pattern.
kono
parents:
diff changeset
915 *
kono
parents:
diff changeset
916 * @param p A pointer to a C-style null-terminated string containing
kono
parents:
diff changeset
917 * a regular expression pattern.
kono
parents:
diff changeset
918 * @param flags Syntax option flags.
kono
parents:
diff changeset
919 *
kono
parents:
diff changeset
920 * @throws regex_error if p does not contain a valid regular expression
kono
parents:
diff changeset
921 * pattern interpreted according to @p flags. If regex_error is thrown,
kono
parents:
diff changeset
922 * *this remains unchanged.
kono
parents:
diff changeset
923 */
kono
parents:
diff changeset
924 basic_regex&
kono
parents:
diff changeset
925 assign(const _Ch_type* __p,
kono
parents:
diff changeset
926 flag_type __flags = regex_constants::ECMAScript)
kono
parents:
diff changeset
927 { return this->assign(string_type(__p), __flags); }
kono
parents:
diff changeset
928
kono
parents:
diff changeset
929 /**
kono
parents:
diff changeset
930 * @brief Assigns a new regular expression to a regex object from a
kono
parents:
diff changeset
931 * C-style string containing a regular expression pattern.
kono
parents:
diff changeset
932 *
kono
parents:
diff changeset
933 * @param p A pointer to a C-style string containing a
kono
parents:
diff changeset
934 * regular expression pattern.
kono
parents:
diff changeset
935 * @param len The length of the regular expression pattern string.
kono
parents:
diff changeset
936 * @param flags Syntax option flags.
kono
parents:
diff changeset
937 *
kono
parents:
diff changeset
938 * @throws regex_error if p does not contain a valid regular expression
kono
parents:
diff changeset
939 * pattern interpreted according to @p flags. If regex_error is thrown,
kono
parents:
diff changeset
940 * *this remains unchanged.
kono
parents:
diff changeset
941 */
kono
parents:
diff changeset
942 basic_regex&
kono
parents:
diff changeset
943 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
kono
parents:
diff changeset
944 { return this->assign(string_type(__p, __len), __flags); }
kono
parents:
diff changeset
945
kono
parents:
diff changeset
946 /**
kono
parents:
diff changeset
947 * @brief Assigns a new regular expression to a regex object from a
kono
parents:
diff changeset
948 * string containing a regular expression pattern.
kono
parents:
diff changeset
949 *
kono
parents:
diff changeset
950 * @param s A string containing a regular expression pattern.
kono
parents:
diff changeset
951 * @param flags Syntax option flags.
kono
parents:
diff changeset
952 *
kono
parents:
diff changeset
953 * @throws regex_error if p does not contain a valid regular expression
kono
parents:
diff changeset
954 * pattern interpreted according to @p flags. If regex_error is thrown,
kono
parents:
diff changeset
955 * *this remains unchanged.
kono
parents:
diff changeset
956 */
kono
parents:
diff changeset
957 template<typename _Ch_typeraits, typename _Allocator>
kono
parents:
diff changeset
958 basic_regex&
kono
parents:
diff changeset
959 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
kono
parents:
diff changeset
960 flag_type __f = regex_constants::ECMAScript)
kono
parents:
diff changeset
961 {
kono
parents:
diff changeset
962 basic_regex __tmp(__s, __f);
kono
parents:
diff changeset
963 this->swap(__tmp);
kono
parents:
diff changeset
964 return *this;
kono
parents:
diff changeset
965 }
kono
parents:
diff changeset
966
kono
parents:
diff changeset
967 /**
kono
parents:
diff changeset
968 * @brief Assigns a new regular expression to a regex object.
kono
parents:
diff changeset
969 *
kono
parents:
diff changeset
970 * @param first The start of a range containing a valid regular
kono
parents:
diff changeset
971 * expression.
kono
parents:
diff changeset
972 * @param last The end of a range containing a valid regular
kono
parents:
diff changeset
973 * expression.
kono
parents:
diff changeset
974 * @param flags Syntax option flags.
kono
parents:
diff changeset
975 *
kono
parents:
diff changeset
976 * @throws regex_error if p does not contain a valid regular expression
kono
parents:
diff changeset
977 * pattern interpreted according to @p flags. If regex_error is thrown,
kono
parents:
diff changeset
978 * the object remains unchanged.
kono
parents:
diff changeset
979 */
kono
parents:
diff changeset
980 template<typename _InputIterator>
kono
parents:
diff changeset
981 basic_regex&
kono
parents:
diff changeset
982 assign(_InputIterator __first, _InputIterator __last,
kono
parents:
diff changeset
983 flag_type __flags = regex_constants::ECMAScript)
kono
parents:
diff changeset
984 { return this->assign(string_type(__first, __last), __flags); }
kono
parents:
diff changeset
985
kono
parents:
diff changeset
986 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
kono
parents:
diff changeset
987 /**
kono
parents:
diff changeset
988 * @brief Assigns a new regular expression to a regex object.
kono
parents:
diff changeset
989 *
kono
parents:
diff changeset
990 * @param l An initializer list representing a regular expression.
kono
parents:
diff changeset
991 * @param flags Syntax option flags.
kono
parents:
diff changeset
992 *
kono
parents:
diff changeset
993 * @throws regex_error if @p l does not contain a valid regular
kono
parents:
diff changeset
994 * expression pattern interpreted according to @p flags. If regex_error
kono
parents:
diff changeset
995 * is thrown, the object remains unchanged.
kono
parents:
diff changeset
996 */
kono
parents:
diff changeset
997 basic_regex&
kono
parents:
diff changeset
998 assign(initializer_list<_Ch_type> __l,
kono
parents:
diff changeset
999 flag_type __f = regex_constants::ECMAScript)
kono
parents:
diff changeset
1000 { return this->assign(__l.begin(), __l.end(), __f); }
kono
parents:
diff changeset
1001 #endif
kono
parents:
diff changeset
1002
kono
parents:
diff changeset
1003 // [7.8.4] const operations
kono
parents:
diff changeset
1004 /**
kono
parents:
diff changeset
1005 * @brief Gets the number of marked subexpressions within the regular
kono
parents:
diff changeset
1006 * expression.
kono
parents:
diff changeset
1007 */
kono
parents:
diff changeset
1008 unsigned int
kono
parents:
diff changeset
1009 mark_count() const
kono
parents:
diff changeset
1010 { return _M_mark_count; }
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 /**
kono
parents:
diff changeset
1013 * @brief Gets the flags used to construct the regular expression
kono
parents:
diff changeset
1014 * or in the last call to assign().
kono
parents:
diff changeset
1015 */
kono
parents:
diff changeset
1016 flag_type
kono
parents:
diff changeset
1017 flags() const
kono
parents:
diff changeset
1018 { return _M_flags; }
kono
parents:
diff changeset
1019
kono
parents:
diff changeset
1020 // [7.8.5] locale
kono
parents:
diff changeset
1021 /**
kono
parents:
diff changeset
1022 * @brief Imbues the regular expression object with the given locale.
kono
parents:
diff changeset
1023 *
kono
parents:
diff changeset
1024 * @param loc A locale.
kono
parents:
diff changeset
1025 */
kono
parents:
diff changeset
1026 locale_type
kono
parents:
diff changeset
1027 imbue(locale_type __loc)
kono
parents:
diff changeset
1028 { return _M_traits.imbue(__loc); }
kono
parents:
diff changeset
1029
kono
parents:
diff changeset
1030 /**
kono
parents:
diff changeset
1031 * @brief Gets the locale currently imbued in the regular expression
kono
parents:
diff changeset
1032 * object.
kono
parents:
diff changeset
1033 */
kono
parents:
diff changeset
1034 locale_type
kono
parents:
diff changeset
1035 getloc() const
kono
parents:
diff changeset
1036 { return _M_traits.getloc(); }
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 // [7.8.6] swap
kono
parents:
diff changeset
1039 /**
kono
parents:
diff changeset
1040 * @brief Swaps the contents of two regular expression objects.
kono
parents:
diff changeset
1041 *
kono
parents:
diff changeset
1042 * @param rhs Another regular expression object.
kono
parents:
diff changeset
1043 */
kono
parents:
diff changeset
1044 void
kono
parents:
diff changeset
1045 swap(basic_regex& __rhs)
kono
parents:
diff changeset
1046 {
kono
parents:
diff changeset
1047 std::swap(_M_flags, __rhs._M_flags);
kono
parents:
diff changeset
1048 std::swap(_M_pattern, __rhs._M_pattern);
kono
parents:
diff changeset
1049 std::swap(_M_mark_count, __rhs._M_mark_count);
kono
parents:
diff changeset
1050 std::swap(_M_traits, __rhs._M_traits);
kono
parents:
diff changeset
1051 }
kono
parents:
diff changeset
1052
kono
parents:
diff changeset
1053 private:
kono
parents:
diff changeset
1054 /**
kono
parents:
diff changeset
1055 * @brief Compiles a regular expression pattern into a NFA.
kono
parents:
diff changeset
1056 * @todo Implement this function.
kono
parents:
diff changeset
1057 */
kono
parents:
diff changeset
1058 void _M_compile();
kono
parents:
diff changeset
1059
kono
parents:
diff changeset
1060 protected:
kono
parents:
diff changeset
1061 flag_type _M_flags;
kono
parents:
diff changeset
1062 string_type _M_pattern;
kono
parents:
diff changeset
1063 unsigned int _M_mark_count;
kono
parents:
diff changeset
1064 _Rx_traits _M_traits;
kono
parents:
diff changeset
1065 };
kono
parents:
diff changeset
1066
kono
parents:
diff changeset
1067 /** @brief Standard regular expressions. */
kono
parents:
diff changeset
1068 typedef basic_regex<char> regex;
kono
parents:
diff changeset
1069 #ifdef _GLIBCXX_USE_WCHAR_T
kono
parents:
diff changeset
1070 /** @brief Standard wide-character regular expressions. */
kono
parents:
diff changeset
1071 typedef basic_regex<wchar_t> wregex;
kono
parents:
diff changeset
1072 #endif
kono
parents:
diff changeset
1073
kono
parents:
diff changeset
1074
kono
parents:
diff changeset
1075 // [7.8.6] basic_regex swap
kono
parents:
diff changeset
1076 /**
kono
parents:
diff changeset
1077 * @brief Swaps the contents of two regular expression objects.
kono
parents:
diff changeset
1078 * @param lhs First regular expression.
kono
parents:
diff changeset
1079 * @param rhs Second regular expression.
kono
parents:
diff changeset
1080 */
kono
parents:
diff changeset
1081 template<typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
1082 inline void
kono
parents:
diff changeset
1083 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
kono
parents:
diff changeset
1084 basic_regex<_Ch_type, _Rx_traits>& __rhs)
kono
parents:
diff changeset
1085 { __lhs.swap(__rhs); }
kono
parents:
diff changeset
1086
kono
parents:
diff changeset
1087
kono
parents:
diff changeset
1088 // [7.9] Class template sub_match
kono
parents:
diff changeset
1089 /**
kono
parents:
diff changeset
1090 * A sequence of characters matched by a particular marked sub-expression.
kono
parents:
diff changeset
1091 *
kono
parents:
diff changeset
1092 * An object of this class is essentially a pair of iterators marking a
kono
parents:
diff changeset
1093 * matched subexpression within a regular expression pattern match. Such
kono
parents:
diff changeset
1094 * objects can be converted to and compared with std::basic_string objects
kono
parents:
diff changeset
1095 * of a similar base character type as the pattern matched by the regular
kono
parents:
diff changeset
1096 * expression.
kono
parents:
diff changeset
1097 *
kono
parents:
diff changeset
1098 * The iterators that make up the pair are the usual half-open interval
kono
parents:
diff changeset
1099 * referencing the actual original pattern matched.
kono
parents:
diff changeset
1100 */
kono
parents:
diff changeset
1101 template<typename _BiIter>
kono
parents:
diff changeset
1102 class sub_match : public std::pair<_BiIter, _BiIter>
kono
parents:
diff changeset
1103 {
kono
parents:
diff changeset
1104 public:
kono
parents:
diff changeset
1105 typedef typename iterator_traits<_BiIter>::value_type value_type;
kono
parents:
diff changeset
1106 typedef typename iterator_traits<_BiIter>::difference_type
kono
parents:
diff changeset
1107 difference_type;
kono
parents:
diff changeset
1108 typedef _BiIter iterator;
kono
parents:
diff changeset
1109
kono
parents:
diff changeset
1110 public:
kono
parents:
diff changeset
1111 bool matched;
kono
parents:
diff changeset
1112
kono
parents:
diff changeset
1113 /**
kono
parents:
diff changeset
1114 * Gets the length of the matching sequence.
kono
parents:
diff changeset
1115 */
kono
parents:
diff changeset
1116 difference_type
kono
parents:
diff changeset
1117 length() const
kono
parents:
diff changeset
1118 { return this->matched ? std::distance(this->first, this->second) : 0; }
kono
parents:
diff changeset
1119
kono
parents:
diff changeset
1120 /**
kono
parents:
diff changeset
1121 * @brief Gets the matching sequence as a string.
kono
parents:
diff changeset
1122 *
kono
parents:
diff changeset
1123 * @returns the matching sequence as a string.
kono
parents:
diff changeset
1124 *
kono
parents:
diff changeset
1125 * This is the implicit conversion operator. It is identical to the
kono
parents:
diff changeset
1126 * str() member function except that it will want to pop up in
kono
parents:
diff changeset
1127 * unexpected places and cause a great deal of confusion and cursing
kono
parents:
diff changeset
1128 * from the unwary.
kono
parents:
diff changeset
1129 */
kono
parents:
diff changeset
1130 operator basic_string<value_type>() const
kono
parents:
diff changeset
1131 {
kono
parents:
diff changeset
1132 return this->matched
kono
parents:
diff changeset
1133 ? std::basic_string<value_type>(this->first, this->second)
kono
parents:
diff changeset
1134 : std::basic_string<value_type>();
kono
parents:
diff changeset
1135 }
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 /**
kono
parents:
diff changeset
1138 * @brief Gets the matching sequence as a string.
kono
parents:
diff changeset
1139 *
kono
parents:
diff changeset
1140 * @returns the matching sequence as a string.
kono
parents:
diff changeset
1141 */
kono
parents:
diff changeset
1142 basic_string<value_type>
kono
parents:
diff changeset
1143 str() const
kono
parents:
diff changeset
1144 {
kono
parents:
diff changeset
1145 return this->matched
kono
parents:
diff changeset
1146 ? std::basic_string<value_type>(this->first, this->second)
kono
parents:
diff changeset
1147 : std::basic_string<value_type>();
kono
parents:
diff changeset
1148 }
kono
parents:
diff changeset
1149
kono
parents:
diff changeset
1150 /**
kono
parents:
diff changeset
1151 * @brief Compares this and another matched sequence.
kono
parents:
diff changeset
1152 *
kono
parents:
diff changeset
1153 * @param s Another matched sequence to compare to this one.
kono
parents:
diff changeset
1154 *
kono
parents:
diff changeset
1155 * @retval <0 this matched sequence will collate before @p s.
kono
parents:
diff changeset
1156 * @retval =0 this matched sequence is equivalent to @p s.
kono
parents:
diff changeset
1157 * @retval <0 this matched sequence will collate after @p s.
kono
parents:
diff changeset
1158 */
kono
parents:
diff changeset
1159 int
kono
parents:
diff changeset
1160 compare(const sub_match& __s) const
kono
parents:
diff changeset
1161 { return this->str().compare(__s.str()); }
kono
parents:
diff changeset
1162
kono
parents:
diff changeset
1163 /**
kono
parents:
diff changeset
1164 * @brief Compares this sub_match to a string.
kono
parents:
diff changeset
1165 *
kono
parents:
diff changeset
1166 * @param s A string to compare to this sub_match.
kono
parents:
diff changeset
1167 *
kono
parents:
diff changeset
1168 * @retval <0 this matched sequence will collate before @p s.
kono
parents:
diff changeset
1169 * @retval =0 this matched sequence is equivalent to @p s.
kono
parents:
diff changeset
1170 * @retval <0 this matched sequence will collate after @p s.
kono
parents:
diff changeset
1171 */
kono
parents:
diff changeset
1172 int
kono
parents:
diff changeset
1173 compare(const basic_string<value_type>& __s) const
kono
parents:
diff changeset
1174 { return this->str().compare(__s); }
kono
parents:
diff changeset
1175
kono
parents:
diff changeset
1176 /**
kono
parents:
diff changeset
1177 * @brief Compares this sub_match to a C-style string.
kono
parents:
diff changeset
1178 *
kono
parents:
diff changeset
1179 * @param s A C-style string to compare to this sub_match.
kono
parents:
diff changeset
1180 *
kono
parents:
diff changeset
1181 * @retval <0 this matched sequence will collate before @p s.
kono
parents:
diff changeset
1182 * @retval =0 this matched sequence is equivalent to @p s.
kono
parents:
diff changeset
1183 * @retval <0 this matched sequence will collate after @p s.
kono
parents:
diff changeset
1184 */
kono
parents:
diff changeset
1185 int
kono
parents:
diff changeset
1186 compare(const value_type* __s) const
kono
parents:
diff changeset
1187 { return this->str().compare(__s); }
kono
parents:
diff changeset
1188 };
kono
parents:
diff changeset
1189
kono
parents:
diff changeset
1190
kono
parents:
diff changeset
1191 /** @brief Standard regex submatch over a C-style null-terminated string. */
kono
parents:
diff changeset
1192 typedef sub_match<const char*> csub_match;
kono
parents:
diff changeset
1193 /** @brief Standard regex submatch over a standard string. */
kono
parents:
diff changeset
1194 typedef sub_match<string::const_iterator> ssub_match;
kono
parents:
diff changeset
1195 #ifdef _GLIBCXX_USE_WCHAR_T
kono
parents:
diff changeset
1196 /** @brief Regex submatch over a C-style null-terminated wide string. */
kono
parents:
diff changeset
1197 typedef sub_match<const wchar_t*> wcsub_match;
kono
parents:
diff changeset
1198 /** @brief Regex submatch over a standard wide string. */
kono
parents:
diff changeset
1199 typedef sub_match<wstring::const_iterator> wssub_match;
kono
parents:
diff changeset
1200 #endif
kono
parents:
diff changeset
1201
kono
parents:
diff changeset
1202 // [7.9.2] sub_match non-member operators
kono
parents:
diff changeset
1203
kono
parents:
diff changeset
1204 /**
kono
parents:
diff changeset
1205 * @brief Tests the equivalence of two regular expression submatches.
kono
parents:
diff changeset
1206 * @param lhs First regular expression submatch.
kono
parents:
diff changeset
1207 * @param rhs Second regular expression submatch.
kono
parents:
diff changeset
1208 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1209 */
kono
parents:
diff changeset
1210 template<typename _BiIter>
kono
parents:
diff changeset
1211 inline bool
kono
parents:
diff changeset
1212 operator==(const sub_match<_BiIter>& __lhs,
kono
parents:
diff changeset
1213 const sub_match<_BiIter>& __rhs)
kono
parents:
diff changeset
1214 { return __lhs.compare(__rhs) == 0; }
kono
parents:
diff changeset
1215
kono
parents:
diff changeset
1216 /**
kono
parents:
diff changeset
1217 * @brief Tests the inequivalence of two regular expression submatches.
kono
parents:
diff changeset
1218 * @param lhs First regular expression submatch.
kono
parents:
diff changeset
1219 * @param rhs Second regular expression submatch.
kono
parents:
diff changeset
1220 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1221 */
kono
parents:
diff changeset
1222 template<typename _BiIter>
kono
parents:
diff changeset
1223 inline bool
kono
parents:
diff changeset
1224 operator!=(const sub_match<_BiIter>& __lhs,
kono
parents:
diff changeset
1225 const sub_match<_BiIter>& __rhs)
kono
parents:
diff changeset
1226 { return __lhs.compare(__rhs) != 0; }
kono
parents:
diff changeset
1227
kono
parents:
diff changeset
1228 /**
kono
parents:
diff changeset
1229 * @brief Tests the ordering of two regular expression submatches.
kono
parents:
diff changeset
1230 * @param lhs First regular expression submatch.
kono
parents:
diff changeset
1231 * @param rhs Second regular expression submatch.
kono
parents:
diff changeset
1232 * @returns true if @a lhs precedes @a rhs, false otherwise.
kono
parents:
diff changeset
1233 */
kono
parents:
diff changeset
1234 template<typename _BiIter>
kono
parents:
diff changeset
1235 inline bool
kono
parents:
diff changeset
1236 operator<(const sub_match<_BiIter>& __lhs,
kono
parents:
diff changeset
1237 const sub_match<_BiIter>& __rhs)
kono
parents:
diff changeset
1238 { return __lhs.compare(__rhs) < 0; }
kono
parents:
diff changeset
1239
kono
parents:
diff changeset
1240 /**
kono
parents:
diff changeset
1241 * @brief Tests the ordering of two regular expression submatches.
kono
parents:
diff changeset
1242 * @param lhs First regular expression submatch.
kono
parents:
diff changeset
1243 * @param rhs Second regular expression submatch.
kono
parents:
diff changeset
1244 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
kono
parents:
diff changeset
1245 */
kono
parents:
diff changeset
1246 template<typename _BiIter>
kono
parents:
diff changeset
1247 inline bool
kono
parents:
diff changeset
1248 operator<=(const sub_match<_BiIter>& __lhs,
kono
parents:
diff changeset
1249 const sub_match<_BiIter>& __rhs)
kono
parents:
diff changeset
1250 { return __lhs.compare(__rhs) <= 0; }
kono
parents:
diff changeset
1251
kono
parents:
diff changeset
1252 /**
kono
parents:
diff changeset
1253 * @brief Tests the ordering of two regular expression submatches.
kono
parents:
diff changeset
1254 * @param lhs First regular expression submatch.
kono
parents:
diff changeset
1255 * @param rhs Second regular expression submatch.
kono
parents:
diff changeset
1256 * @returns true if @a lhs does not precede @a rhs, false otherwise.
kono
parents:
diff changeset
1257 */
kono
parents:
diff changeset
1258 template<typename _BiIter>
kono
parents:
diff changeset
1259 inline bool
kono
parents:
diff changeset
1260 operator>=(const sub_match<_BiIter>& __lhs,
kono
parents:
diff changeset
1261 const sub_match<_BiIter>& __rhs)
kono
parents:
diff changeset
1262 { return __lhs.compare(__rhs) >= 0; }
kono
parents:
diff changeset
1263
kono
parents:
diff changeset
1264 /**
kono
parents:
diff changeset
1265 * @brief Tests the ordering of two regular expression submatches.
kono
parents:
diff changeset
1266 * @param lhs First regular expression submatch.
kono
parents:
diff changeset
1267 * @param rhs Second regular expression submatch.
kono
parents:
diff changeset
1268 * @returns true if @a lhs succeeds @a rhs, false otherwise.
kono
parents:
diff changeset
1269 */
kono
parents:
diff changeset
1270 template<typename _BiIter>
kono
parents:
diff changeset
1271 inline bool
kono
parents:
diff changeset
1272 operator>(const sub_match<_BiIter>& __lhs,
kono
parents:
diff changeset
1273 const sub_match<_BiIter>& __rhs)
kono
parents:
diff changeset
1274 { return __lhs.compare(__rhs) > 0; }
kono
parents:
diff changeset
1275
kono
parents:
diff changeset
1276 /**
kono
parents:
diff changeset
1277 * @brief Tests the equivalence of a string and a regular expression
kono
parents:
diff changeset
1278 * submatch.
kono
parents:
diff changeset
1279 * @param lhs A string.
kono
parents:
diff changeset
1280 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1281 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1282 */
kono
parents:
diff changeset
1283 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1284 inline bool
kono
parents:
diff changeset
1285 operator==(const basic_string<
kono
parents:
diff changeset
1286 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1287 _Ch_traits, _Ch_alloc>& __lhs,
kono
parents:
diff changeset
1288 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1289 { return __lhs == __rhs.str(); }
kono
parents:
diff changeset
1290
kono
parents:
diff changeset
1291 /**
kono
parents:
diff changeset
1292 * @brief Tests the inequivalence of a string and a regular expression
kono
parents:
diff changeset
1293 * submatch.
kono
parents:
diff changeset
1294 * @param lhs A string.
kono
parents:
diff changeset
1295 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1296 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1297 */
kono
parents:
diff changeset
1298 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1299 inline bool
kono
parents:
diff changeset
1300 operator!=(const basic_string<
kono
parents:
diff changeset
1301 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1302 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1303 { return __lhs != __rhs.str(); }
kono
parents:
diff changeset
1304
kono
parents:
diff changeset
1305 /**
kono
parents:
diff changeset
1306 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1307 * @param lhs A string.
kono
parents:
diff changeset
1308 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1309 * @returns true if @a lhs precedes @a rhs, false otherwise.
kono
parents:
diff changeset
1310 */
kono
parents:
diff changeset
1311 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1312 inline bool
kono
parents:
diff changeset
1313 operator<(const basic_string<
kono
parents:
diff changeset
1314 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1315 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1316 { return __lhs < __rhs.str(); }
kono
parents:
diff changeset
1317
kono
parents:
diff changeset
1318 /**
kono
parents:
diff changeset
1319 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1320 * @param lhs A string.
kono
parents:
diff changeset
1321 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1322 * @returns true if @a lhs succeeds @a rhs, false otherwise.
kono
parents:
diff changeset
1323 */
kono
parents:
diff changeset
1324 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1325 inline bool
kono
parents:
diff changeset
1326 operator>(const basic_string<
kono
parents:
diff changeset
1327 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1328 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1329 { return __lhs > __rhs.str(); }
kono
parents:
diff changeset
1330
kono
parents:
diff changeset
1331 /**
kono
parents:
diff changeset
1332 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1333 * @param lhs A string.
kono
parents:
diff changeset
1334 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1335 * @returns true if @a lhs does not precede @a rhs, false otherwise.
kono
parents:
diff changeset
1336 */
kono
parents:
diff changeset
1337 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1338 inline bool
kono
parents:
diff changeset
1339 operator>=(const basic_string<
kono
parents:
diff changeset
1340 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1341 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1342 { return __lhs >= __rhs.str(); }
kono
parents:
diff changeset
1343
kono
parents:
diff changeset
1344 /**
kono
parents:
diff changeset
1345 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1346 * @param lhs A string.
kono
parents:
diff changeset
1347 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1348 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
kono
parents:
diff changeset
1349 */
kono
parents:
diff changeset
1350 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1351 inline bool
kono
parents:
diff changeset
1352 operator<=(const basic_string<
kono
parents:
diff changeset
1353 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1354 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1355 { return __lhs <= __rhs.str(); }
kono
parents:
diff changeset
1356
kono
parents:
diff changeset
1357 /**
kono
parents:
diff changeset
1358 * @brief Tests the equivalence of a regular expression submatch and a
kono
parents:
diff changeset
1359 * string.
kono
parents:
diff changeset
1360 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1361 * @param rhs A string.
kono
parents:
diff changeset
1362 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1363 */
kono
parents:
diff changeset
1364 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1365 inline bool
kono
parents:
diff changeset
1366 operator==(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1367 const basic_string<
kono
parents:
diff changeset
1368 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1369 _Ch_traits, _Ch_alloc>& __rhs)
kono
parents:
diff changeset
1370 { return __lhs.str() == __rhs; }
kono
parents:
diff changeset
1371
kono
parents:
diff changeset
1372 /**
kono
parents:
diff changeset
1373 * @brief Tests the inequivalence of a regular expression submatch and a
kono
parents:
diff changeset
1374 * string.
kono
parents:
diff changeset
1375 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1376 * @param rhs A string.
kono
parents:
diff changeset
1377 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1378 */
kono
parents:
diff changeset
1379 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
kono
parents:
diff changeset
1380 inline bool
kono
parents:
diff changeset
1381 operator!=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1382 const basic_string<
kono
parents:
diff changeset
1383 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1384 _Ch_traits, _Ch_alloc>& __rhs)
kono
parents:
diff changeset
1385 { return __lhs.str() != __rhs; }
kono
parents:
diff changeset
1386
kono
parents:
diff changeset
1387 /**
kono
parents:
diff changeset
1388 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1389 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1390 * @param rhs A string.
kono
parents:
diff changeset
1391 * @returns true if @a lhs precedes @a rhs, false otherwise.
kono
parents:
diff changeset
1392 */
kono
parents:
diff changeset
1393 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
kono
parents:
diff changeset
1394 inline bool
kono
parents:
diff changeset
1395 operator<(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1396 const basic_string<
kono
parents:
diff changeset
1397 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1398 _Ch_traits, _Ch_alloc>& __rhs)
kono
parents:
diff changeset
1399 { return __lhs.str() < __rhs; }
kono
parents:
diff changeset
1400
kono
parents:
diff changeset
1401 /**
kono
parents:
diff changeset
1402 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1403 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1404 * @param rhs A string.
kono
parents:
diff changeset
1405 * @returns true if @a lhs succeeds @a rhs, false otherwise.
kono
parents:
diff changeset
1406 */
kono
parents:
diff changeset
1407 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
kono
parents:
diff changeset
1408 inline bool
kono
parents:
diff changeset
1409 operator>(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1410 const basic_string<
kono
parents:
diff changeset
1411 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1412 _Ch_traits, _Ch_alloc>& __rhs)
kono
parents:
diff changeset
1413 { return __lhs.str() > __rhs; }
kono
parents:
diff changeset
1414
kono
parents:
diff changeset
1415 /**
kono
parents:
diff changeset
1416 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1417 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1418 * @param rhs A string.
kono
parents:
diff changeset
1419 * @returns true if @a lhs does not precede @a rhs, false otherwise.
kono
parents:
diff changeset
1420 */
kono
parents:
diff changeset
1421 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
kono
parents:
diff changeset
1422 inline bool
kono
parents:
diff changeset
1423 operator>=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1424 const basic_string<
kono
parents:
diff changeset
1425 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1426 _Ch_traits, _Ch_alloc>& __rhs)
kono
parents:
diff changeset
1427 { return __lhs.str() >= __rhs; }
kono
parents:
diff changeset
1428
kono
parents:
diff changeset
1429 /**
kono
parents:
diff changeset
1430 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1431 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1432 * @param rhs A string.
kono
parents:
diff changeset
1433 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
kono
parents:
diff changeset
1434 */
kono
parents:
diff changeset
1435 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
kono
parents:
diff changeset
1436 inline bool
kono
parents:
diff changeset
1437 operator<=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1438 const basic_string<
kono
parents:
diff changeset
1439 typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
1440 _Ch_traits, _Ch_alloc>& __rhs)
kono
parents:
diff changeset
1441 { return __lhs.str() <= __rhs; }
kono
parents:
diff changeset
1442
kono
parents:
diff changeset
1443 /**
kono
parents:
diff changeset
1444 * @brief Tests the equivalence of a C string and a regular expression
kono
parents:
diff changeset
1445 * submatch.
kono
parents:
diff changeset
1446 * @param lhs A C string.
kono
parents:
diff changeset
1447 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1448 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1449 */
kono
parents:
diff changeset
1450 template<typename _Bi_iter>
kono
parents:
diff changeset
1451 inline bool
kono
parents:
diff changeset
1452 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
kono
parents:
diff changeset
1453 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1454 { return __lhs == __rhs.str(); }
kono
parents:
diff changeset
1455
kono
parents:
diff changeset
1456 /**
kono
parents:
diff changeset
1457 * @brief Tests the inequivalence of an iterator value and a regular
kono
parents:
diff changeset
1458 * expression submatch.
kono
parents:
diff changeset
1459 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1460 * @param rhs A string.
kono
parents:
diff changeset
1461 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1462 */
kono
parents:
diff changeset
1463 template<typename _Bi_iter>
kono
parents:
diff changeset
1464 inline bool
kono
parents:
diff changeset
1465 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
kono
parents:
diff changeset
1466 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1467 { return __lhs != __rhs.str(); }
kono
parents:
diff changeset
1468
kono
parents:
diff changeset
1469 /**
kono
parents:
diff changeset
1470 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1471 * @param lhs A string.
kono
parents:
diff changeset
1472 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1473 * @returns true if @a lhs precedes @a rhs, false otherwise.
kono
parents:
diff changeset
1474 */
kono
parents:
diff changeset
1475 template<typename _Bi_iter>
kono
parents:
diff changeset
1476 inline bool
kono
parents:
diff changeset
1477 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
kono
parents:
diff changeset
1478 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1479 { return __lhs < __rhs.str(); }
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 /**
kono
parents:
diff changeset
1482 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1483 * @param lhs A string.
kono
parents:
diff changeset
1484 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1485 * @returns true if @a lhs succeeds @a rhs, false otherwise.
kono
parents:
diff changeset
1486 */
kono
parents:
diff changeset
1487 template<typename _Bi_iter>
kono
parents:
diff changeset
1488 inline bool
kono
parents:
diff changeset
1489 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
kono
parents:
diff changeset
1490 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1491 { return __lhs > __rhs.str(); }
kono
parents:
diff changeset
1492
kono
parents:
diff changeset
1493 /**
kono
parents:
diff changeset
1494 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1495 * @param lhs A string.
kono
parents:
diff changeset
1496 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1497 * @returns true if @a lhs does not precede @a rhs, false otherwise.
kono
parents:
diff changeset
1498 */
kono
parents:
diff changeset
1499 template<typename _Bi_iter>
kono
parents:
diff changeset
1500 inline bool
kono
parents:
diff changeset
1501 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
kono
parents:
diff changeset
1502 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1503 { return __lhs >= __rhs.str(); }
kono
parents:
diff changeset
1504
kono
parents:
diff changeset
1505 /**
kono
parents:
diff changeset
1506 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1507 * @param lhs A string.
kono
parents:
diff changeset
1508 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1509 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
kono
parents:
diff changeset
1510 */
kono
parents:
diff changeset
1511 template<typename _Bi_iter>
kono
parents:
diff changeset
1512 inline bool
kono
parents:
diff changeset
1513 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
kono
parents:
diff changeset
1514 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1515 { return __lhs <= __rhs.str(); }
kono
parents:
diff changeset
1516
kono
parents:
diff changeset
1517 /**
kono
parents:
diff changeset
1518 * @brief Tests the equivalence of a regular expression submatch and a
kono
parents:
diff changeset
1519 * string.
kono
parents:
diff changeset
1520 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1521 * @param rhs A pointer to a string?
kono
parents:
diff changeset
1522 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1523 */
kono
parents:
diff changeset
1524 template<typename _Bi_iter>
kono
parents:
diff changeset
1525 inline bool
kono
parents:
diff changeset
1526 operator==(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1527 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
kono
parents:
diff changeset
1528 { return __lhs.str() == __rhs; }
kono
parents:
diff changeset
1529
kono
parents:
diff changeset
1530 /**
kono
parents:
diff changeset
1531 * @brief Tests the inequivalence of a regular expression submatch and a
kono
parents:
diff changeset
1532 * string.
kono
parents:
diff changeset
1533 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1534 * @param rhs A pointer to a string.
kono
parents:
diff changeset
1535 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1536 */
kono
parents:
diff changeset
1537 template<typename _Bi_iter>
kono
parents:
diff changeset
1538 inline bool
kono
parents:
diff changeset
1539 operator!=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1540 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
kono
parents:
diff changeset
1541 { return __lhs.str() != __rhs; }
kono
parents:
diff changeset
1542
kono
parents:
diff changeset
1543 /**
kono
parents:
diff changeset
1544 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1545 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1546 * @param rhs A string.
kono
parents:
diff changeset
1547 * @returns true if @a lhs precedes @a rhs, false otherwise.
kono
parents:
diff changeset
1548 */
kono
parents:
diff changeset
1549 template<typename _Bi_iter>
kono
parents:
diff changeset
1550 inline bool
kono
parents:
diff changeset
1551 operator<(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1552 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
kono
parents:
diff changeset
1553 { return __lhs.str() < __rhs; }
kono
parents:
diff changeset
1554
kono
parents:
diff changeset
1555 /**
kono
parents:
diff changeset
1556 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1557 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1558 * @param rhs A string.
kono
parents:
diff changeset
1559 * @returns true if @a lhs succeeds @a rhs, false otherwise.
kono
parents:
diff changeset
1560 */
kono
parents:
diff changeset
1561 template<typename _Bi_iter>
kono
parents:
diff changeset
1562 inline bool
kono
parents:
diff changeset
1563 operator>(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1564 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
kono
parents:
diff changeset
1565 { return __lhs.str() > __rhs; }
kono
parents:
diff changeset
1566
kono
parents:
diff changeset
1567 /**
kono
parents:
diff changeset
1568 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1569 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1570 * @param rhs A string.
kono
parents:
diff changeset
1571 * @returns true if @a lhs does not precede @a rhs, false otherwise.
kono
parents:
diff changeset
1572 */
kono
parents:
diff changeset
1573 template<typename _Bi_iter>
kono
parents:
diff changeset
1574 inline bool
kono
parents:
diff changeset
1575 operator>=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1576 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
kono
parents:
diff changeset
1577 { return __lhs.str() >= __rhs; }
kono
parents:
diff changeset
1578
kono
parents:
diff changeset
1579 /**
kono
parents:
diff changeset
1580 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1581 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1582 * @param rhs A string.
kono
parents:
diff changeset
1583 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
kono
parents:
diff changeset
1584 */
kono
parents:
diff changeset
1585 template<typename _Bi_iter>
kono
parents:
diff changeset
1586 inline bool
kono
parents:
diff changeset
1587 operator<=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1588 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
kono
parents:
diff changeset
1589 { return __lhs.str() <= __rhs; }
kono
parents:
diff changeset
1590
kono
parents:
diff changeset
1591 /**
kono
parents:
diff changeset
1592 * @brief Tests the equivalence of a string and a regular expression
kono
parents:
diff changeset
1593 * submatch.
kono
parents:
diff changeset
1594 * @param lhs A string.
kono
parents:
diff changeset
1595 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1596 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1597 */
kono
parents:
diff changeset
1598 template<typename _Bi_iter>
kono
parents:
diff changeset
1599 inline bool
kono
parents:
diff changeset
1600 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
kono
parents:
diff changeset
1601 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1602 { return __lhs == __rhs.str(); }
kono
parents:
diff changeset
1603
kono
parents:
diff changeset
1604 /**
kono
parents:
diff changeset
1605 * @brief Tests the inequivalence of a string and a regular expression
kono
parents:
diff changeset
1606 * submatch.
kono
parents:
diff changeset
1607 * @param lhs A string.
kono
parents:
diff changeset
1608 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1609 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1610 */
kono
parents:
diff changeset
1611 template<typename _Bi_iter>
kono
parents:
diff changeset
1612 inline bool
kono
parents:
diff changeset
1613 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
kono
parents:
diff changeset
1614 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1615 { return __lhs != __rhs.str(); }
kono
parents:
diff changeset
1616
kono
parents:
diff changeset
1617 /**
kono
parents:
diff changeset
1618 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1619 * @param lhs A string.
kono
parents:
diff changeset
1620 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1621 * @returns true if @a lhs precedes @a rhs, false otherwise.
kono
parents:
diff changeset
1622 */
kono
parents:
diff changeset
1623 template<typename _Bi_iter>
kono
parents:
diff changeset
1624 inline bool
kono
parents:
diff changeset
1625 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
kono
parents:
diff changeset
1626 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1627 { return __lhs < __rhs.str(); }
kono
parents:
diff changeset
1628
kono
parents:
diff changeset
1629 /**
kono
parents:
diff changeset
1630 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1631 * @param lhs A string.
kono
parents:
diff changeset
1632 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1633 * @returns true if @a lhs succeeds @a rhs, false otherwise.
kono
parents:
diff changeset
1634 */
kono
parents:
diff changeset
1635 template<typename _Bi_iter>
kono
parents:
diff changeset
1636 inline bool
kono
parents:
diff changeset
1637 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
kono
parents:
diff changeset
1638 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1639 { return __lhs > __rhs.str(); }
kono
parents:
diff changeset
1640
kono
parents:
diff changeset
1641 /**
kono
parents:
diff changeset
1642 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1643 * @param lhs A string.
kono
parents:
diff changeset
1644 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1645 * @returns true if @a lhs does not precede @a rhs, false otherwise.
kono
parents:
diff changeset
1646 */
kono
parents:
diff changeset
1647 template<typename _Bi_iter>
kono
parents:
diff changeset
1648 inline bool
kono
parents:
diff changeset
1649 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
kono
parents:
diff changeset
1650 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1651 { return __lhs >= __rhs.str(); }
kono
parents:
diff changeset
1652
kono
parents:
diff changeset
1653 /**
kono
parents:
diff changeset
1654 * @brief Tests the ordering of a string and a regular expression submatch.
kono
parents:
diff changeset
1655 * @param lhs A string.
kono
parents:
diff changeset
1656 * @param rhs A regular expression submatch.
kono
parents:
diff changeset
1657 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
kono
parents:
diff changeset
1658 */
kono
parents:
diff changeset
1659 template<typename _Bi_iter>
kono
parents:
diff changeset
1660 inline bool
kono
parents:
diff changeset
1661 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
kono
parents:
diff changeset
1662 const sub_match<_Bi_iter>& __rhs)
kono
parents:
diff changeset
1663 { return __lhs <= __rhs.str(); }
kono
parents:
diff changeset
1664
kono
parents:
diff changeset
1665 /**
kono
parents:
diff changeset
1666 * @brief Tests the equivalence of a regular expression submatch and a
kono
parents:
diff changeset
1667 * string.
kono
parents:
diff changeset
1668 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1669 * @param rhs A const string reference.
kono
parents:
diff changeset
1670 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1671 */
kono
parents:
diff changeset
1672 template<typename _Bi_iter>
kono
parents:
diff changeset
1673 inline bool
kono
parents:
diff changeset
1674 operator==(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1675 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
kono
parents:
diff changeset
1676 { return __lhs.str() == __rhs; }
kono
parents:
diff changeset
1677
kono
parents:
diff changeset
1678 /**
kono
parents:
diff changeset
1679 * @brief Tests the inequivalence of a regular expression submatch and a
kono
parents:
diff changeset
1680 * string.
kono
parents:
diff changeset
1681 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1682 * @param rhs A const string reference.
kono
parents:
diff changeset
1683 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
kono
parents:
diff changeset
1684 */
kono
parents:
diff changeset
1685 template<typename _Bi_iter>
kono
parents:
diff changeset
1686 inline bool
kono
parents:
diff changeset
1687 operator!=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1688 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
kono
parents:
diff changeset
1689 { return __lhs.str() != __rhs; }
kono
parents:
diff changeset
1690
kono
parents:
diff changeset
1691 /**
kono
parents:
diff changeset
1692 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1693 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1694 * @param rhs A const string reference.
kono
parents:
diff changeset
1695 * @returns true if @a lhs precedes @a rhs, false otherwise.
kono
parents:
diff changeset
1696 */
kono
parents:
diff changeset
1697 template<typename _Bi_iter>
kono
parents:
diff changeset
1698 inline bool
kono
parents:
diff changeset
1699 operator<(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1700 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
kono
parents:
diff changeset
1701 { return __lhs.str() < __rhs; }
kono
parents:
diff changeset
1702
kono
parents:
diff changeset
1703 /**
kono
parents:
diff changeset
1704 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1705 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1706 * @param rhs A const string reference.
kono
parents:
diff changeset
1707 * @returns true if @a lhs succeeds @a rhs, false otherwise.
kono
parents:
diff changeset
1708 */
kono
parents:
diff changeset
1709 template<typename _Bi_iter>
kono
parents:
diff changeset
1710 inline bool
kono
parents:
diff changeset
1711 operator>(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1712 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
kono
parents:
diff changeset
1713 { return __lhs.str() > __rhs; }
kono
parents:
diff changeset
1714
kono
parents:
diff changeset
1715 /**
kono
parents:
diff changeset
1716 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1717 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1718 * @param rhs A const string reference.
kono
parents:
diff changeset
1719 * @returns true if @a lhs does not precede @a rhs, false otherwise.
kono
parents:
diff changeset
1720 */
kono
parents:
diff changeset
1721 template<typename _Bi_iter>
kono
parents:
diff changeset
1722 inline bool
kono
parents:
diff changeset
1723 operator>=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1724 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
kono
parents:
diff changeset
1725 { return __lhs.str() >= __rhs; }
kono
parents:
diff changeset
1726
kono
parents:
diff changeset
1727 /**
kono
parents:
diff changeset
1728 * @brief Tests the ordering of a regular expression submatch and a string.
kono
parents:
diff changeset
1729 * @param lhs A regular expression submatch.
kono
parents:
diff changeset
1730 * @param rhs A const string reference.
kono
parents:
diff changeset
1731 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
kono
parents:
diff changeset
1732 */
kono
parents:
diff changeset
1733 template<typename _Bi_iter>
kono
parents:
diff changeset
1734 inline bool
kono
parents:
diff changeset
1735 operator<=(const sub_match<_Bi_iter>& __lhs,
kono
parents:
diff changeset
1736 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
kono
parents:
diff changeset
1737 { return __lhs.str() <= __rhs; }
kono
parents:
diff changeset
1738
kono
parents:
diff changeset
1739 /**
kono
parents:
diff changeset
1740 * @brief Inserts a matched string into an output stream.
kono
parents:
diff changeset
1741 *
kono
parents:
diff changeset
1742 * @param os The output stream.
kono
parents:
diff changeset
1743 * @param m A submatch string.
kono
parents:
diff changeset
1744 *
kono
parents:
diff changeset
1745 * @returns the output stream with the submatch string inserted.
kono
parents:
diff changeset
1746 */
kono
parents:
diff changeset
1747 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
kono
parents:
diff changeset
1748 inline
kono
parents:
diff changeset
1749 basic_ostream<_Ch_type, _Ch_traits>&
kono
parents:
diff changeset
1750 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
kono
parents:
diff changeset
1751 const sub_match<_Bi_iter>& __m)
kono
parents:
diff changeset
1752 { return __os << __m.str(); }
kono
parents:
diff changeset
1753
kono
parents:
diff changeset
1754 // [7.10] Class template match_results
kono
parents:
diff changeset
1755 /**
kono
parents:
diff changeset
1756 * @brief The results of a match or search operation.
kono
parents:
diff changeset
1757 *
kono
parents:
diff changeset
1758 * A collection of character sequences representing the result of a regular
kono
parents:
diff changeset
1759 * expression match. Storage for the collection is allocated and freed as
kono
parents:
diff changeset
1760 * necessary by the member functions of class template match_results.
kono
parents:
diff changeset
1761 *
kono
parents:
diff changeset
1762 * This class satisfies the Sequence requirements, with the exception that
kono
parents:
diff changeset
1763 * only the operations defined for a const-qualified Sequence are supported.
kono
parents:
diff changeset
1764 *
kono
parents:
diff changeset
1765 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
kono
parents:
diff changeset
1766 * the whole match. In this case the sub_match member matched is always true.
kono
parents:
diff changeset
1767 * The sub_match object stored at index n denotes what matched the marked
kono
parents:
diff changeset
1768 * sub-expression n within the matched expression. If the sub-expression n
kono
parents:
diff changeset
1769 * participated in a regular expression match then the sub_match member
kono
parents:
diff changeset
1770 * matched evaluates to true, and members first and second denote the range
kono
parents:
diff changeset
1771 * of characters [first, second) which formed that match. Otherwise matched
kono
parents:
diff changeset
1772 * is false, and members first and second point to the end of the sequence
kono
parents:
diff changeset
1773 * that was searched.
kono
parents:
diff changeset
1774 *
kono
parents:
diff changeset
1775 * @nosubgrouping
kono
parents:
diff changeset
1776 */
kono
parents:
diff changeset
1777 template<typename _Bi_iter,
kono
parents:
diff changeset
1778 typename _Allocator = allocator<sub_match<_Bi_iter> > >
kono
parents:
diff changeset
1779 class match_results
kono
parents:
diff changeset
1780 : private std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
kono
parents:
diff changeset
1781 {
kono
parents:
diff changeset
1782 private:
kono
parents:
diff changeset
1783 typedef std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
kono
parents:
diff changeset
1784 _Base_type;
kono
parents:
diff changeset
1785
kono
parents:
diff changeset
1786 public:
kono
parents:
diff changeset
1787 /**
kono
parents:
diff changeset
1788 * @name 10.? Public Types
kono
parents:
diff changeset
1789 */
kono
parents:
diff changeset
1790 //@{
kono
parents:
diff changeset
1791 typedef sub_match<_Bi_iter> value_type;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1792 typedef typename _Base_type::const_reference const_reference;
111
kono
parents:
diff changeset
1793 typedef const_reference reference;
kono
parents:
diff changeset
1794 typedef typename _Base_type::const_iterator const_iterator;
kono
parents:
diff changeset
1795 typedef const_iterator iterator;
kono
parents:
diff changeset
1796 typedef typename iterator_traits<_Bi_iter>::difference_type
kono
parents:
diff changeset
1797 difference_type;
kono
parents:
diff changeset
1798 typedef typename _Allocator::size_type size_type;
kono
parents:
diff changeset
1799 typedef _Allocator allocator_type;
kono
parents:
diff changeset
1800 typedef typename iterator_traits<_Bi_iter>::value_type char_type;
kono
parents:
diff changeset
1801 typedef basic_string<char_type> string_type;
kono
parents:
diff changeset
1802 //@}
kono
parents:
diff changeset
1803
kono
parents:
diff changeset
1804 public:
kono
parents:
diff changeset
1805 /**
kono
parents:
diff changeset
1806 * @name 10.1 Construction, Copying, and Destruction
kono
parents:
diff changeset
1807 */
kono
parents:
diff changeset
1808 //@{
kono
parents:
diff changeset
1809
kono
parents:
diff changeset
1810 /**
kono
parents:
diff changeset
1811 * @brief Constructs a default %match_results container.
kono
parents:
diff changeset
1812 * @post size() returns 0 and str() returns an empty string.
kono
parents:
diff changeset
1813 */
kono
parents:
diff changeset
1814 explicit
kono
parents:
diff changeset
1815 match_results(const _Allocator& __a = _Allocator())
kono
parents:
diff changeset
1816 : _Base_type(__a), _M_matched(false)
kono
parents:
diff changeset
1817 { }
kono
parents:
diff changeset
1818
kono
parents:
diff changeset
1819 /**
kono
parents:
diff changeset
1820 * @brief Copy constructs a %match_results.
kono
parents:
diff changeset
1821 */
kono
parents:
diff changeset
1822 match_results(const match_results& __rhs)
kono
parents:
diff changeset
1823 : _Base_type(__rhs), _M_matched(__rhs._M_matched),
kono
parents:
diff changeset
1824 _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
kono
parents:
diff changeset
1825 { }
kono
parents:
diff changeset
1826
kono
parents:
diff changeset
1827 /**
kono
parents:
diff changeset
1828 * @brief Assigns rhs to *this.
kono
parents:
diff changeset
1829 */
kono
parents:
diff changeset
1830 match_results&
kono
parents:
diff changeset
1831 operator=(const match_results& __rhs)
kono
parents:
diff changeset
1832 {
kono
parents:
diff changeset
1833 match_results __tmp(__rhs);
kono
parents:
diff changeset
1834 this->swap(__tmp);
kono
parents:
diff changeset
1835 return *this;
kono
parents:
diff changeset
1836 }
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 /**
kono
parents:
diff changeset
1839 * @brief Destroys a %match_results object.
kono
parents:
diff changeset
1840 */
kono
parents:
diff changeset
1841 ~match_results()
kono
parents:
diff changeset
1842 { }
kono
parents:
diff changeset
1843
kono
parents:
diff changeset
1844 //@}
kono
parents:
diff changeset
1845
kono
parents:
diff changeset
1846 /**
kono
parents:
diff changeset
1847 * @name 10.2 Size
kono
parents:
diff changeset
1848 */
kono
parents:
diff changeset
1849 //@{
kono
parents:
diff changeset
1850
kono
parents:
diff changeset
1851 /**
kono
parents:
diff changeset
1852 * @brief Gets the number of matches and submatches.
kono
parents:
diff changeset
1853 *
kono
parents:
diff changeset
1854 * The number of matches for a given regular expression will be either 0
kono
parents:
diff changeset
1855 * if there was no match or mark_count() + 1 if a match was successful.
kono
parents:
diff changeset
1856 * Some matches may be empty.
kono
parents:
diff changeset
1857 *
kono
parents:
diff changeset
1858 * @returns the number of matches found.
kono
parents:
diff changeset
1859 */
kono
parents:
diff changeset
1860 size_type
kono
parents:
diff changeset
1861 size() const
kono
parents:
diff changeset
1862 { return _M_matched ? _Base_type::size() + 1 : 0; }
kono
parents:
diff changeset
1863
kono
parents:
diff changeset
1864 //size_type
kono
parents:
diff changeset
1865 //max_size() const;
kono
parents:
diff changeset
1866 using _Base_type::max_size;
kono
parents:
diff changeset
1867
kono
parents:
diff changeset
1868 /**
kono
parents:
diff changeset
1869 * @brief Indicates if the %match_results contains no results.
kono
parents:
diff changeset
1870 * @retval true The %match_results object is empty.
kono
parents:
diff changeset
1871 * @retval false The %match_results object is not empty.
kono
parents:
diff changeset
1872 */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1873 _GLIBCXX_NODISCARD bool
111
kono
parents:
diff changeset
1874 empty() const
kono
parents:
diff changeset
1875 { return size() == 0; }
kono
parents:
diff changeset
1876
kono
parents:
diff changeset
1877 //@}
kono
parents:
diff changeset
1878
kono
parents:
diff changeset
1879 /**
kono
parents:
diff changeset
1880 * @name 10.3 Element Access
kono
parents:
diff changeset
1881 */
kono
parents:
diff changeset
1882 //@{
kono
parents:
diff changeset
1883
kono
parents:
diff changeset
1884 /**
kono
parents:
diff changeset
1885 * @brief Gets the length of the indicated submatch.
kono
parents:
diff changeset
1886 * @param sub indicates the submatch.
kono
parents:
diff changeset
1887 *
kono
parents:
diff changeset
1888 * This function returns the length of the indicated submatch, or the
kono
parents:
diff changeset
1889 * length of the entire match if @p sub is zero (the default).
kono
parents:
diff changeset
1890 */
kono
parents:
diff changeset
1891 difference_type
kono
parents:
diff changeset
1892 length(size_type __sub = 0) const
kono
parents:
diff changeset
1893 { return _M_matched ? this->str(__sub).length() : 0; }
kono
parents:
diff changeset
1894
kono
parents:
diff changeset
1895 /**
kono
parents:
diff changeset
1896 * @brief Gets the offset of the beginning of the indicated submatch.
kono
parents:
diff changeset
1897 * @param sub indicates the submatch.
kono
parents:
diff changeset
1898 *
kono
parents:
diff changeset
1899 * This function returns the offset from the beginning of the target
kono
parents:
diff changeset
1900 * sequence to the beginning of the submatch, unless the value of @p sub
kono
parents:
diff changeset
1901 * is zero (the default), in which case this function returns the offset
kono
parents:
diff changeset
1902 * from the beginning of the target sequence to the beginning of the
kono
parents:
diff changeset
1903 * match.
kono
parents:
diff changeset
1904 */
kono
parents:
diff changeset
1905 difference_type
kono
parents:
diff changeset
1906 position(size_type __sub = 0) const
kono
parents:
diff changeset
1907 {
kono
parents:
diff changeset
1908 return _M_matched ? std::distance(this->prefix().first,
kono
parents:
diff changeset
1909 (*this)[__sub].first) : 0;
kono
parents:
diff changeset
1910 }
kono
parents:
diff changeset
1911
kono
parents:
diff changeset
1912 /**
kono
parents:
diff changeset
1913 * @brief Gets the match or submatch converted to a string type.
kono
parents:
diff changeset
1914 * @param sub indicates the submatch.
kono
parents:
diff changeset
1915 *
kono
parents:
diff changeset
1916 * This function gets the submatch (or match, if @p sub is zero) extracted
kono
parents:
diff changeset
1917 * from the target range and converted to the associated string type.
kono
parents:
diff changeset
1918 */
kono
parents:
diff changeset
1919 string_type
kono
parents:
diff changeset
1920 str(size_type __sub = 0) const
kono
parents:
diff changeset
1921 { return _M_matched ? (*this)[__sub].str() : string_type(); }
kono
parents:
diff changeset
1922
kono
parents:
diff changeset
1923 /**
kono
parents:
diff changeset
1924 * @brief Gets a %sub_match reference for the match or submatch.
kono
parents:
diff changeset
1925 * @param sub indicates the submatch.
kono
parents:
diff changeset
1926 *
kono
parents:
diff changeset
1927 * This function gets a reference to the indicated submatch, or the entire
kono
parents:
diff changeset
1928 * match if @p sub is zero.
kono
parents:
diff changeset
1929 *
kono
parents:
diff changeset
1930 * If @p sub >= size() then this function returns a %sub_match with a
kono
parents:
diff changeset
1931 * special value indicating no submatch.
kono
parents:
diff changeset
1932 */
kono
parents:
diff changeset
1933 const_reference
kono
parents:
diff changeset
1934 operator[](size_type __sub) const
kono
parents:
diff changeset
1935 { return _Base_type::operator[](__sub); }
kono
parents:
diff changeset
1936
kono
parents:
diff changeset
1937 /**
kono
parents:
diff changeset
1938 * @brief Gets a %sub_match representing the match prefix.
kono
parents:
diff changeset
1939 *
kono
parents:
diff changeset
1940 * This function gets a reference to a %sub_match object representing the
kono
parents:
diff changeset
1941 * part of the target range between the start of the target range and the
kono
parents:
diff changeset
1942 * start of the match.
kono
parents:
diff changeset
1943 */
kono
parents:
diff changeset
1944 const_reference
kono
parents:
diff changeset
1945 prefix() const
kono
parents:
diff changeset
1946 { return _M_prefix; }
kono
parents:
diff changeset
1947
kono
parents:
diff changeset
1948 /**
kono
parents:
diff changeset
1949 * @brief Gets a %sub_match representing the match suffix.
kono
parents:
diff changeset
1950 *
kono
parents:
diff changeset
1951 * This function gets a reference to a %sub_match object representing the
kono
parents:
diff changeset
1952 * part of the target range between the end of the match and the end of
kono
parents:
diff changeset
1953 * the target range.
kono
parents:
diff changeset
1954 */
kono
parents:
diff changeset
1955 const_reference
kono
parents:
diff changeset
1956 suffix() const
kono
parents:
diff changeset
1957 { return _M_suffix; }
kono
parents:
diff changeset
1958
kono
parents:
diff changeset
1959 /**
kono
parents:
diff changeset
1960 * @brief Gets an iterator to the start of the %sub_match collection.
kono
parents:
diff changeset
1961 */
kono
parents:
diff changeset
1962 const_iterator
kono
parents:
diff changeset
1963 begin() const
kono
parents:
diff changeset
1964 { return _Base_type::begin(); }
kono
parents:
diff changeset
1965
kono
parents:
diff changeset
1966 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
kono
parents:
diff changeset
1967 /**
kono
parents:
diff changeset
1968 * @brief Gets an iterator to the start of the %sub_match collection.
kono
parents:
diff changeset
1969 */
kono
parents:
diff changeset
1970 const_iterator
kono
parents:
diff changeset
1971 cbegin() const
kono
parents:
diff changeset
1972 { return _Base_type::begin(); }
kono
parents:
diff changeset
1973 #endif
kono
parents:
diff changeset
1974
kono
parents:
diff changeset
1975 /**
kono
parents:
diff changeset
1976 * @brief Gets an iterator to one-past-the-end of the collection.
kono
parents:
diff changeset
1977 */
kono
parents:
diff changeset
1978 const_iterator
kono
parents:
diff changeset
1979 end() const
kono
parents:
diff changeset
1980 { return _Base_type::end(); }
kono
parents:
diff changeset
1981
kono
parents:
diff changeset
1982 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
kono
parents:
diff changeset
1983 /**
kono
parents:
diff changeset
1984 * @brief Gets an iterator to one-past-the-end of the collection.
kono
parents:
diff changeset
1985 */
kono
parents:
diff changeset
1986 const_iterator
kono
parents:
diff changeset
1987 cend() const
kono
parents:
diff changeset
1988 { return _Base_type::end(); }
kono
parents:
diff changeset
1989 #endif
kono
parents:
diff changeset
1990
kono
parents:
diff changeset
1991 //@}
kono
parents:
diff changeset
1992
kono
parents:
diff changeset
1993 /**
kono
parents:
diff changeset
1994 * @name 10.4 Formatting
kono
parents:
diff changeset
1995 *
kono
parents:
diff changeset
1996 * These functions perform formatted substitution of the matched
kono
parents:
diff changeset
1997 * character sequences into their target. The format specifiers
kono
parents:
diff changeset
1998 * and escape sequences accepted by these functions are
kono
parents:
diff changeset
1999 * determined by their @p flags parameter as documented above.
kono
parents:
diff changeset
2000 */
kono
parents:
diff changeset
2001 //@{
kono
parents:
diff changeset
2002
kono
parents:
diff changeset
2003 /**
kono
parents:
diff changeset
2004 * @todo Implement this function.
kono
parents:
diff changeset
2005 */
kono
parents:
diff changeset
2006 template<typename _Out_iter>
kono
parents:
diff changeset
2007 _Out_iter
kono
parents:
diff changeset
2008 format(_Out_iter __out, const string_type& __fmt,
kono
parents:
diff changeset
2009 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2010 = regex_constants::format_default) const;
kono
parents:
diff changeset
2011
kono
parents:
diff changeset
2012 /**
kono
parents:
diff changeset
2013 * @todo Implement this function.
kono
parents:
diff changeset
2014 */
kono
parents:
diff changeset
2015 string_type
kono
parents:
diff changeset
2016 format(const string_type& __fmt,
kono
parents:
diff changeset
2017 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2018 = regex_constants::format_default) const;
kono
parents:
diff changeset
2019
kono
parents:
diff changeset
2020 //@}
kono
parents:
diff changeset
2021
kono
parents:
diff changeset
2022 /**
kono
parents:
diff changeset
2023 * @name 10.5 Allocator
kono
parents:
diff changeset
2024 */
kono
parents:
diff changeset
2025 //@{
kono
parents:
diff changeset
2026
kono
parents:
diff changeset
2027 /**
kono
parents:
diff changeset
2028 * @brief Gets a copy of the allocator.
kono
parents:
diff changeset
2029 */
kono
parents:
diff changeset
2030 //allocator_type
kono
parents:
diff changeset
2031 //get_allocator() const;
kono
parents:
diff changeset
2032 using _Base_type::get_allocator;
kono
parents:
diff changeset
2033
kono
parents:
diff changeset
2034 //@}
kono
parents:
diff changeset
2035
kono
parents:
diff changeset
2036 /**
kono
parents:
diff changeset
2037 * @name 10.6 Swap
kono
parents:
diff changeset
2038 */
kono
parents:
diff changeset
2039 //@{
kono
parents:
diff changeset
2040
kono
parents:
diff changeset
2041 /**
kono
parents:
diff changeset
2042 * @brief Swaps the contents of two match_results.
kono
parents:
diff changeset
2043 */
kono
parents:
diff changeset
2044 void
kono
parents:
diff changeset
2045 swap(match_results& __that)
kono
parents:
diff changeset
2046 {
kono
parents:
diff changeset
2047 _Base_type::swap(__that);
kono
parents:
diff changeset
2048 std::swap(_M_matched, __that._M_matched);
kono
parents:
diff changeset
2049 std::swap(_M_prefix, __that._M_prefix);
kono
parents:
diff changeset
2050 std::swap(_M_suffix, __that._M_suffix);
kono
parents:
diff changeset
2051 }
kono
parents:
diff changeset
2052 //@}
kono
parents:
diff changeset
2053
kono
parents:
diff changeset
2054 private:
kono
parents:
diff changeset
2055 bool _M_matched;
kono
parents:
diff changeset
2056 value_type _M_prefix;
kono
parents:
diff changeset
2057 value_type _M_suffix;
kono
parents:
diff changeset
2058 };
kono
parents:
diff changeset
2059
kono
parents:
diff changeset
2060 typedef match_results<const char*> cmatch;
kono
parents:
diff changeset
2061 typedef match_results<string::const_iterator> smatch;
kono
parents:
diff changeset
2062 #ifdef _GLIBCXX_USE_WCHAR_T
kono
parents:
diff changeset
2063 typedef match_results<const wchar_t*> wcmatch;
kono
parents:
diff changeset
2064 typedef match_results<wstring::const_iterator> wsmatch;
kono
parents:
diff changeset
2065 #endif
kono
parents:
diff changeset
2066
kono
parents:
diff changeset
2067 // match_results comparisons
kono
parents:
diff changeset
2068 /**
kono
parents:
diff changeset
2069 * @brief Compares two match_results for equality.
kono
parents:
diff changeset
2070 * @returns true if the two objects refer to the same match,
kono
parents:
diff changeset
2071 * false otherwise.
kono
parents:
diff changeset
2072 * @todo Implement this function.
kono
parents:
diff changeset
2073 */
kono
parents:
diff changeset
2074 template<typename _Bi_iter, typename _Allocator>
kono
parents:
diff changeset
2075 inline bool
kono
parents:
diff changeset
2076 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
kono
parents:
diff changeset
2077 const match_results<_Bi_iter, _Allocator>& __m2);
kono
parents:
diff changeset
2078
kono
parents:
diff changeset
2079 /**
kono
parents:
diff changeset
2080 * @brief Compares two match_results for inequality.
kono
parents:
diff changeset
2081 * @returns true if the two objects do not refer to the same match,
kono
parents:
diff changeset
2082 * false otherwise.
kono
parents:
diff changeset
2083 */
kono
parents:
diff changeset
2084 template<typename _Bi_iter, class _Allocator>
kono
parents:
diff changeset
2085 inline bool
kono
parents:
diff changeset
2086 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
kono
parents:
diff changeset
2087 const match_results<_Bi_iter, _Allocator>& __m2)
kono
parents:
diff changeset
2088 { return !(__m1 == __m2); }
kono
parents:
diff changeset
2089
kono
parents:
diff changeset
2090 // [7.10.6] match_results swap
kono
parents:
diff changeset
2091 /**
kono
parents:
diff changeset
2092 * @brief Swaps two match results.
kono
parents:
diff changeset
2093 * @param lhs A match result.
kono
parents:
diff changeset
2094 * @param rhs A match result.
kono
parents:
diff changeset
2095 *
kono
parents:
diff changeset
2096 * The contents of the two match_results objects are swapped.
kono
parents:
diff changeset
2097 */
kono
parents:
diff changeset
2098 template<typename _Bi_iter, typename _Allocator>
kono
parents:
diff changeset
2099 inline void
kono
parents:
diff changeset
2100 swap(match_results<_Bi_iter, _Allocator>& __lhs,
kono
parents:
diff changeset
2101 match_results<_Bi_iter, _Allocator>& __rhs)
kono
parents:
diff changeset
2102 { __lhs.swap(__rhs); }
kono
parents:
diff changeset
2103
kono
parents:
diff changeset
2104 // [7.11.2] Function template regex_match
kono
parents:
diff changeset
2105 /**
kono
parents:
diff changeset
2106 * @name Matching, Searching, and Replacing
kono
parents:
diff changeset
2107 */
kono
parents:
diff changeset
2108 //@{
kono
parents:
diff changeset
2109
kono
parents:
diff changeset
2110 /**
kono
parents:
diff changeset
2111 * @brief Determines if there is a match between the regular expression @p e
kono
parents:
diff changeset
2112 * and all of the character sequence [first, last).
kono
parents:
diff changeset
2113 *
kono
parents:
diff changeset
2114 * @param first Beginning of the character sequence to match.
kono
parents:
diff changeset
2115 * @param last One-past-the-end of the character sequence to match.
kono
parents:
diff changeset
2116 * @param m The match results.
kono
parents:
diff changeset
2117 * @param re The regular expression.
kono
parents:
diff changeset
2118 * @param flags Controls how the regular expression is matched.
kono
parents:
diff changeset
2119 *
kono
parents:
diff changeset
2120 * @retval true A match exists.
kono
parents:
diff changeset
2121 * @retval false Otherwise.
kono
parents:
diff changeset
2122 *
kono
parents:
diff changeset
2123 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2124 *
kono
parents:
diff changeset
2125 * @todo Implement this function.
kono
parents:
diff changeset
2126 */
kono
parents:
diff changeset
2127 template<typename _Bi_iter, typename _Allocator,
kono
parents:
diff changeset
2128 typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2129 bool
kono
parents:
diff changeset
2130 regex_match(_Bi_iter __first, _Bi_iter __last,
kono
parents:
diff changeset
2131 match_results<_Bi_iter, _Allocator>& __m,
kono
parents:
diff changeset
2132 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2133 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2134 = regex_constants::match_default);
kono
parents:
diff changeset
2135
kono
parents:
diff changeset
2136 /**
kono
parents:
diff changeset
2137 * @brief Indicates if there is a match between the regular expression @p e
kono
parents:
diff changeset
2138 * and all of the character sequence [first, last).
kono
parents:
diff changeset
2139 *
kono
parents:
diff changeset
2140 * @param first Beginning of the character sequence to match.
kono
parents:
diff changeset
2141 * @param last One-past-the-end of the character sequence to match.
kono
parents:
diff changeset
2142 * @param re The regular expression.
kono
parents:
diff changeset
2143 * @param flags Controls how the regular expression is matched.
kono
parents:
diff changeset
2144 *
kono
parents:
diff changeset
2145 * @retval true A match exists.
kono
parents:
diff changeset
2146 * @retval false Otherwise.
kono
parents:
diff changeset
2147 *
kono
parents:
diff changeset
2148 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2149 */
kono
parents:
diff changeset
2150 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2151 bool
kono
parents:
diff changeset
2152 regex_match(_Bi_iter __first, _Bi_iter __last,
kono
parents:
diff changeset
2153 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2154 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2155 = regex_constants::match_default)
kono
parents:
diff changeset
2156 {
kono
parents:
diff changeset
2157 match_results<_Bi_iter> __what;
kono
parents:
diff changeset
2158 return regex_match(__first, __last, __what, __re, __flags);
kono
parents:
diff changeset
2159 }
kono
parents:
diff changeset
2160
kono
parents:
diff changeset
2161 /**
kono
parents:
diff changeset
2162 * @brief Determines if there is a match between the regular expression @p e
kono
parents:
diff changeset
2163 * and a C-style null-terminated string.
kono
parents:
diff changeset
2164 *
kono
parents:
diff changeset
2165 * @param s The C-style null-terminated string to match.
kono
parents:
diff changeset
2166 * @param m The match results.
kono
parents:
diff changeset
2167 * @param re The regular expression.
kono
parents:
diff changeset
2168 * @param f Controls how the regular expression is matched.
kono
parents:
diff changeset
2169 *
kono
parents:
diff changeset
2170 * @retval true A match exists.
kono
parents:
diff changeset
2171 * @retval false Otherwise.
kono
parents:
diff changeset
2172 *
kono
parents:
diff changeset
2173 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2174 */
kono
parents:
diff changeset
2175 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
kono
parents:
diff changeset
2176 inline bool
kono
parents:
diff changeset
2177 regex_match(const _Ch_type* __s,
kono
parents:
diff changeset
2178 match_results<const _Ch_type*, _Allocator>& __m,
kono
parents:
diff changeset
2179 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2180 regex_constants::match_flag_type __f
kono
parents:
diff changeset
2181 = regex_constants::match_default)
kono
parents:
diff changeset
2182 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
kono
parents:
diff changeset
2183
kono
parents:
diff changeset
2184 /**
kono
parents:
diff changeset
2185 * @brief Determines if there is a match between the regular expression @p e
kono
parents:
diff changeset
2186 * and a string.
kono
parents:
diff changeset
2187 *
kono
parents:
diff changeset
2188 * @param s The string to match.
kono
parents:
diff changeset
2189 * @param m The match results.
kono
parents:
diff changeset
2190 * @param re The regular expression.
kono
parents:
diff changeset
2191 * @param flags Controls how the regular expression is matched.
kono
parents:
diff changeset
2192 *
kono
parents:
diff changeset
2193 * @retval true A match exists.
kono
parents:
diff changeset
2194 * @retval false Otherwise.
kono
parents:
diff changeset
2195 *
kono
parents:
diff changeset
2196 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2197 */
kono
parents:
diff changeset
2198 template<typename _Ch_traits, typename _Ch_alloc,
kono
parents:
diff changeset
2199 typename _Allocator, typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2200 inline bool
kono
parents:
diff changeset
2201 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
kono
parents:
diff changeset
2202 match_results<typename basic_string<_Ch_type,
kono
parents:
diff changeset
2203 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
kono
parents:
diff changeset
2204 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2205 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2206 = regex_constants::match_default)
kono
parents:
diff changeset
2207 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
kono
parents:
diff changeset
2208
kono
parents:
diff changeset
2209 /**
kono
parents:
diff changeset
2210 * @brief Indicates if there is a match between the regular expression @p e
kono
parents:
diff changeset
2211 * and a C-style null-terminated string.
kono
parents:
diff changeset
2212 *
kono
parents:
diff changeset
2213 * @param s The C-style null-terminated string to match.
kono
parents:
diff changeset
2214 * @param re The regular expression.
kono
parents:
diff changeset
2215 * @param f Controls how the regular expression is matched.
kono
parents:
diff changeset
2216 *
kono
parents:
diff changeset
2217 * @retval true A match exists.
kono
parents:
diff changeset
2218 * @retval false Otherwise.
kono
parents:
diff changeset
2219 *
kono
parents:
diff changeset
2220 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2221 */
kono
parents:
diff changeset
2222 template<typename _Ch_type, class _Rx_traits>
kono
parents:
diff changeset
2223 inline bool
kono
parents:
diff changeset
2224 regex_match(const _Ch_type* __s,
kono
parents:
diff changeset
2225 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2226 regex_constants::match_flag_type __f
kono
parents:
diff changeset
2227 = regex_constants::match_default)
kono
parents:
diff changeset
2228 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
kono
parents:
diff changeset
2229
kono
parents:
diff changeset
2230 /**
kono
parents:
diff changeset
2231 * @brief Indicates if there is a match between the regular expression @p e
kono
parents:
diff changeset
2232 * and a string.
kono
parents:
diff changeset
2233 *
kono
parents:
diff changeset
2234 * @param s [IN] The string to match.
kono
parents:
diff changeset
2235 * @param re [IN] The regular expression.
kono
parents:
diff changeset
2236 * @param flags [IN] Controls how the regular expression is matched.
kono
parents:
diff changeset
2237 *
kono
parents:
diff changeset
2238 * @retval true A match exists.
kono
parents:
diff changeset
2239 * @retval false Otherwise.
kono
parents:
diff changeset
2240 *
kono
parents:
diff changeset
2241 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2242 */
kono
parents:
diff changeset
2243 template<typename _Ch_traits, typename _Str_allocator,
kono
parents:
diff changeset
2244 typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2245 inline bool
kono
parents:
diff changeset
2246 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
kono
parents:
diff changeset
2247 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2248 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2249 = regex_constants::match_default)
kono
parents:
diff changeset
2250 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
kono
parents:
diff changeset
2251
kono
parents:
diff changeset
2252 // [7.11.3] Function template regex_search
kono
parents:
diff changeset
2253 /**
kono
parents:
diff changeset
2254 * Searches for a regular expression within a range.
kono
parents:
diff changeset
2255 * @param first [IN] The start of the string to search.
kono
parents:
diff changeset
2256 * @param last [IN] One-past-the-end of the string to search.
kono
parents:
diff changeset
2257 * @param m [OUT] The match results.
kono
parents:
diff changeset
2258 * @param re [IN] The regular expression to search for.
kono
parents:
diff changeset
2259 * @param flags [IN] Search policy flags.
kono
parents:
diff changeset
2260 * @retval true A match was found within the string.
kono
parents:
diff changeset
2261 * @retval false No match was found within the string, the content of %m is
kono
parents:
diff changeset
2262 * undefined.
kono
parents:
diff changeset
2263 *
kono
parents:
diff changeset
2264 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2265 *
kono
parents:
diff changeset
2266 * @todo Implement this function.
kono
parents:
diff changeset
2267 */
kono
parents:
diff changeset
2268 template<typename _Bi_iter, typename _Allocator,
kono
parents:
diff changeset
2269 typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2270 inline bool
kono
parents:
diff changeset
2271 regex_search(_Bi_iter __first, _Bi_iter __last,
kono
parents:
diff changeset
2272 match_results<_Bi_iter, _Allocator>& __m,
kono
parents:
diff changeset
2273 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2274 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2275 = regex_constants::match_default);
kono
parents:
diff changeset
2276
kono
parents:
diff changeset
2277 /**
kono
parents:
diff changeset
2278 * Searches for a regular expression within a range.
kono
parents:
diff changeset
2279 * @param first [IN] The start of the string to search.
kono
parents:
diff changeset
2280 * @param last [IN] One-past-the-end of the string to search.
kono
parents:
diff changeset
2281 * @param re [IN] The regular expression to search for.
kono
parents:
diff changeset
2282 * @param flags [IN] Search policy flags.
kono
parents:
diff changeset
2283 * @retval true A match was found within the string.
kono
parents:
diff changeset
2284 * @retval false No match was found within the string.
kono
parents:
diff changeset
2285 * @doctodo
kono
parents:
diff changeset
2286 *
kono
parents:
diff changeset
2287 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2288 */
kono
parents:
diff changeset
2289 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2290 inline bool
kono
parents:
diff changeset
2291 regex_search(_Bi_iter __first, _Bi_iter __last,
kono
parents:
diff changeset
2292 const basic_regex<_Ch_type, _Rx_traits>& __re,
kono
parents:
diff changeset
2293 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2294 = regex_constants::match_default)
kono
parents:
diff changeset
2295 {
kono
parents:
diff changeset
2296 match_results<_Bi_iter> __what;
kono
parents:
diff changeset
2297 return regex_search(__first, __last, __what, __re, __flags);
kono
parents:
diff changeset
2298 }
kono
parents:
diff changeset
2299
kono
parents:
diff changeset
2300 /**
kono
parents:
diff changeset
2301 * @brief Searches for a regular expression within a C-string.
kono
parents:
diff changeset
2302 * @param s [IN] A C-string to search for the regex.
kono
parents:
diff changeset
2303 * @param m [OUT] The set of regex matches.
kono
parents:
diff changeset
2304 * @param e [IN] The regex to search for in @p s.
kono
parents:
diff changeset
2305 * @param f [IN] The search flags.
kono
parents:
diff changeset
2306 * @retval true A match was found within the string.
kono
parents:
diff changeset
2307 * @retval false No match was found within the string, the content of %m is
kono
parents:
diff changeset
2308 * undefined.
kono
parents:
diff changeset
2309 * @doctodo
kono
parents:
diff changeset
2310 *
kono
parents:
diff changeset
2311 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2312 */
kono
parents:
diff changeset
2313 template<typename _Ch_type, class _Allocator, class _Rx_traits>
kono
parents:
diff changeset
2314 inline bool
kono
parents:
diff changeset
2315 regex_search(const _Ch_type* __s,
kono
parents:
diff changeset
2316 match_results<const _Ch_type*, _Allocator>& __m,
kono
parents:
diff changeset
2317 const basic_regex<_Ch_type, _Rx_traits>& __e,
kono
parents:
diff changeset
2318 regex_constants::match_flag_type __f
kono
parents:
diff changeset
2319 = regex_constants::match_default)
kono
parents:
diff changeset
2320 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
kono
parents:
diff changeset
2321
kono
parents:
diff changeset
2322 /**
kono
parents:
diff changeset
2323 * @brief Searches for a regular expression within a C-string.
kono
parents:
diff changeset
2324 * @param s [IN] The C-string to search.
kono
parents:
diff changeset
2325 * @param e [IN] The regular expression to search for.
kono
parents:
diff changeset
2326 * @param f [IN] Search policy flags.
kono
parents:
diff changeset
2327 * @retval true A match was found within the string.
kono
parents:
diff changeset
2328 * @retval false No match was found within the string.
kono
parents:
diff changeset
2329 * @doctodo
kono
parents:
diff changeset
2330 *
kono
parents:
diff changeset
2331 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2332 */
kono
parents:
diff changeset
2333 template<typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2334 inline bool
kono
parents:
diff changeset
2335 regex_search(const _Ch_type* __s,
kono
parents:
diff changeset
2336 const basic_regex<_Ch_type, _Rx_traits>& __e,
kono
parents:
diff changeset
2337 regex_constants::match_flag_type __f
kono
parents:
diff changeset
2338 = regex_constants::match_default)
kono
parents:
diff changeset
2339 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
kono
parents:
diff changeset
2340
kono
parents:
diff changeset
2341 /**
kono
parents:
diff changeset
2342 * @brief Searches for a regular expression within a string.
kono
parents:
diff changeset
2343 * @param s [IN] The string to search.
kono
parents:
diff changeset
2344 * @param e [IN] The regular expression to search for.
kono
parents:
diff changeset
2345 * @param flags [IN] Search policy flags.
kono
parents:
diff changeset
2346 * @retval true A match was found within the string.
kono
parents:
diff changeset
2347 * @retval false No match was found within the string.
kono
parents:
diff changeset
2348 * @doctodo
kono
parents:
diff changeset
2349 *
kono
parents:
diff changeset
2350 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2351 */
kono
parents:
diff changeset
2352 template<typename _Ch_traits, typename _String_allocator,
kono
parents:
diff changeset
2353 typename _Ch_type, typename _Rx_traits>
kono
parents:
diff changeset
2354 inline bool
kono
parents:
diff changeset
2355 regex_search(const basic_string<_Ch_type, _Ch_traits,
kono
parents:
diff changeset
2356 _String_allocator>& __s,
kono
parents:
diff changeset
2357 const basic_regex<_Ch_type, _Rx_traits>& __e,
kono
parents:
diff changeset
2358 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2359 = regex_constants::match_default)
kono
parents:
diff changeset
2360 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
kono
parents:
diff changeset
2361
kono
parents:
diff changeset
2362 /**
kono
parents:
diff changeset
2363 * @brief Searches for a regular expression within a string.
kono
parents:
diff changeset
2364 * @param s [IN] A C++ string to search for the regex.
kono
parents:
diff changeset
2365 * @param m [OUT] The set of regex matches.
kono
parents:
diff changeset
2366 * @param e [IN] The regex to search for in @p s.
kono
parents:
diff changeset
2367 * @param f [IN] The search flags.
kono
parents:
diff changeset
2368 * @retval true A match was found within the string.
kono
parents:
diff changeset
2369 * @retval false No match was found within the string, the content of %m is
kono
parents:
diff changeset
2370 * undefined.
kono
parents:
diff changeset
2371 *
kono
parents:
diff changeset
2372 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2373 */
kono
parents:
diff changeset
2374 template<typename _Ch_traits, typename _Ch_alloc,
kono
parents:
diff changeset
2375 typename _Allocator, typename _Ch_type,
kono
parents:
diff changeset
2376 typename _Rx_traits>
kono
parents:
diff changeset
2377 inline bool
kono
parents:
diff changeset
2378 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
kono
parents:
diff changeset
2379 match_results<typename basic_string<_Ch_type,
kono
parents:
diff changeset
2380 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
kono
parents:
diff changeset
2381 const basic_regex<_Ch_type, _Rx_traits>& __e,
kono
parents:
diff changeset
2382 regex_constants::match_flag_type __f
kono
parents:
diff changeset
2383 = regex_constants::match_default)
kono
parents:
diff changeset
2384 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
kono
parents:
diff changeset
2385
kono
parents:
diff changeset
2386 // tr1 [7.11.4] std [28.11.4] Function template regex_replace
kono
parents:
diff changeset
2387 /**
kono
parents:
diff changeset
2388 * @doctodo
kono
parents:
diff changeset
2389 * @param out
kono
parents:
diff changeset
2390 * @param first
kono
parents:
diff changeset
2391 * @param last
kono
parents:
diff changeset
2392 * @param e
kono
parents:
diff changeset
2393 * @param fmt
kono
parents:
diff changeset
2394 * @param flags
kono
parents:
diff changeset
2395 *
kono
parents:
diff changeset
2396 * @returns out
kono
parents:
diff changeset
2397 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2398 *
kono
parents:
diff changeset
2399 * @todo Implement this function.
kono
parents:
diff changeset
2400 */
kono
parents:
diff changeset
2401 template<typename _Out_iter, typename _Bi_iter,
kono
parents:
diff changeset
2402 typename _Rx_traits, typename _Ch_type>
kono
parents:
diff changeset
2403 inline _Out_iter
kono
parents:
diff changeset
2404 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
kono
parents:
diff changeset
2405 const basic_regex<_Ch_type, _Rx_traits>& __e,
kono
parents:
diff changeset
2406 const basic_string<_Ch_type>& __fmt,
kono
parents:
diff changeset
2407 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2408 = regex_constants::match_default);
kono
parents:
diff changeset
2409
kono
parents:
diff changeset
2410 /**
kono
parents:
diff changeset
2411 * @doctodo
kono
parents:
diff changeset
2412 * @param s
kono
parents:
diff changeset
2413 * @param e
kono
parents:
diff changeset
2414 * @param fmt
kono
parents:
diff changeset
2415 * @param flags
kono
parents:
diff changeset
2416 *
kono
parents:
diff changeset
2417 * @returns a copy of string @p s with replacements.
kono
parents:
diff changeset
2418 *
kono
parents:
diff changeset
2419 * @throws an exception of type regex_error.
kono
parents:
diff changeset
2420 */
kono
parents:
diff changeset
2421 template<typename _Rx_traits, typename _Ch_type>
kono
parents:
diff changeset
2422 inline basic_string<_Ch_type>
kono
parents:
diff changeset
2423 regex_replace(const basic_string<_Ch_type>& __s,
kono
parents:
diff changeset
2424 const basic_regex<_Ch_type, _Rx_traits>& __e,
kono
parents:
diff changeset
2425 const basic_string<_Ch_type>& __fmt,
kono
parents:
diff changeset
2426 regex_constants::match_flag_type __flags
kono
parents:
diff changeset
2427 = regex_constants::match_default)
kono
parents:
diff changeset
2428 {
kono
parents:
diff changeset
2429 std::string __result;
kono
parents:
diff changeset
2430 regex_replace(std::back_inserter(__result),
kono
parents:
diff changeset
2431 __s.begin(), __s.end(), __e, __fmt, __flags);
kono
parents:
diff changeset
2432 return __result;
kono
parents:
diff changeset
2433 }
kono
parents:
diff changeset
2434
kono
parents:
diff changeset
2435 //@}
kono
parents:
diff changeset
2436
kono
parents:
diff changeset
2437 // tr1 [7.12.1] std [28.12] Class template regex_iterator
kono
parents:
diff changeset
2438 /**
kono
parents:
diff changeset
2439 * An iterator adaptor that will provide repeated calls of regex_search over
kono
parents:
diff changeset
2440 * a range until no more matches remain.
kono
parents:
diff changeset
2441 */
kono
parents:
diff changeset
2442 template<typename _Bi_iter,
kono
parents:
diff changeset
2443 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
2444 typename _Rx_traits = regex_traits<_Ch_type> >
kono
parents:
diff changeset
2445 class regex_iterator
kono
parents:
diff changeset
2446 {
kono
parents:
diff changeset
2447 public:
kono
parents:
diff changeset
2448 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
kono
parents:
diff changeset
2449 typedef match_results<_Bi_iter> value_type;
kono
parents:
diff changeset
2450 typedef std::ptrdiff_t difference_type;
kono
parents:
diff changeset
2451 typedef const value_type* pointer;
kono
parents:
diff changeset
2452 typedef const value_type& reference;
kono
parents:
diff changeset
2453 typedef std::forward_iterator_tag iterator_category;
kono
parents:
diff changeset
2454
kono
parents:
diff changeset
2455 public:
kono
parents:
diff changeset
2456 /**
kono
parents:
diff changeset
2457 * @brief Provides a singular iterator, useful for indicating
kono
parents:
diff changeset
2458 * one-past-the-end of a range.
kono
parents:
diff changeset
2459 * @todo Implement this function.
kono
parents:
diff changeset
2460 * @doctodo
kono
parents:
diff changeset
2461 */
kono
parents:
diff changeset
2462 regex_iterator();
kono
parents:
diff changeset
2463
kono
parents:
diff changeset
2464 /**
kono
parents:
diff changeset
2465 * Constructs a %regex_iterator...
kono
parents:
diff changeset
2466 * @param a [IN] The start of a text range to search.
kono
parents:
diff changeset
2467 * @param b [IN] One-past-the-end of the text range to search.
kono
parents:
diff changeset
2468 * @param re [IN] The regular expression to match.
kono
parents:
diff changeset
2469 * @param m [IN] Policy flags for match rules.
kono
parents:
diff changeset
2470 * @todo Implement this function.
kono
parents:
diff changeset
2471 * @doctodo
kono
parents:
diff changeset
2472 */
kono
parents:
diff changeset
2473 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
kono
parents:
diff changeset
2474 regex_constants::match_flag_type __m
kono
parents:
diff changeset
2475 = regex_constants::match_default);
kono
parents:
diff changeset
2476
kono
parents:
diff changeset
2477 /**
kono
parents:
diff changeset
2478 * Copy constructs a %regex_iterator.
kono
parents:
diff changeset
2479 * @todo Implement this function.
kono
parents:
diff changeset
2480 * @doctodo
kono
parents:
diff changeset
2481 */
kono
parents:
diff changeset
2482 regex_iterator(const regex_iterator& __rhs);
kono
parents:
diff changeset
2483
kono
parents:
diff changeset
2484 /**
kono
parents:
diff changeset
2485 * @todo Implement this function.
kono
parents:
diff changeset
2486 * @doctodo
kono
parents:
diff changeset
2487 */
kono
parents:
diff changeset
2488 regex_iterator&
kono
parents:
diff changeset
2489 operator=(const regex_iterator& __rhs);
kono
parents:
diff changeset
2490
kono
parents:
diff changeset
2491 /**
kono
parents:
diff changeset
2492 * @todo Implement this function.
kono
parents:
diff changeset
2493 * @doctodo
kono
parents:
diff changeset
2494 */
kono
parents:
diff changeset
2495 bool
kono
parents:
diff changeset
2496 operator==(const regex_iterator& __rhs);
kono
parents:
diff changeset
2497
kono
parents:
diff changeset
2498 /**
kono
parents:
diff changeset
2499 * @todo Implement this function.
kono
parents:
diff changeset
2500 * @doctodo
kono
parents:
diff changeset
2501 */
kono
parents:
diff changeset
2502 bool
kono
parents:
diff changeset
2503 operator!=(const regex_iterator& __rhs);
kono
parents:
diff changeset
2504
kono
parents:
diff changeset
2505 /**
kono
parents:
diff changeset
2506 * @todo Implement this function.
kono
parents:
diff changeset
2507 * @doctodo
kono
parents:
diff changeset
2508 */
kono
parents:
diff changeset
2509 const value_type&
kono
parents:
diff changeset
2510 operator*();
kono
parents:
diff changeset
2511
kono
parents:
diff changeset
2512 /**
kono
parents:
diff changeset
2513 * @todo Implement this function.
kono
parents:
diff changeset
2514 * @doctodo
kono
parents:
diff changeset
2515 */
kono
parents:
diff changeset
2516 const value_type*
kono
parents:
diff changeset
2517 operator->();
kono
parents:
diff changeset
2518
kono
parents:
diff changeset
2519 /**
kono
parents:
diff changeset
2520 * @todo Implement this function.
kono
parents:
diff changeset
2521 * @doctodo
kono
parents:
diff changeset
2522 */
kono
parents:
diff changeset
2523 regex_iterator&
kono
parents:
diff changeset
2524 operator++();
kono
parents:
diff changeset
2525
kono
parents:
diff changeset
2526 /**
kono
parents:
diff changeset
2527 * @todo Implement this function.
kono
parents:
diff changeset
2528 * @doctodo
kono
parents:
diff changeset
2529 */
kono
parents:
diff changeset
2530 regex_iterator
kono
parents:
diff changeset
2531 operator++(int);
kono
parents:
diff changeset
2532
kono
parents:
diff changeset
2533 private:
kono
parents:
diff changeset
2534 // these members are shown for exposition only:
kono
parents:
diff changeset
2535 _Bi_iter begin;
kono
parents:
diff changeset
2536 _Bi_iter end;
kono
parents:
diff changeset
2537 const regex_type* pregex;
kono
parents:
diff changeset
2538 regex_constants::match_flag_type flags;
kono
parents:
diff changeset
2539 match_results<_Bi_iter> match;
kono
parents:
diff changeset
2540 };
kono
parents:
diff changeset
2541
kono
parents:
diff changeset
2542 typedef regex_iterator<const char*> cregex_iterator;
kono
parents:
diff changeset
2543 typedef regex_iterator<string::const_iterator> sregex_iterator;
kono
parents:
diff changeset
2544 #ifdef _GLIBCXX_USE_WCHAR_T
kono
parents:
diff changeset
2545 typedef regex_iterator<const wchar_t*> wcregex_iterator;
kono
parents:
diff changeset
2546 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
kono
parents:
diff changeset
2547 #endif
kono
parents:
diff changeset
2548
kono
parents:
diff changeset
2549 // [7.12.2] Class template regex_token_iterator
kono
parents:
diff changeset
2550 /**
kono
parents:
diff changeset
2551 * Iterates over submatches in a range (or @a splits a text string).
kono
parents:
diff changeset
2552 *
kono
parents:
diff changeset
2553 * The purpose of this iterator is to enumerate all, or all specified,
kono
parents:
diff changeset
2554 * matches of a regular expression within a text range. The dereferenced
kono
parents:
diff changeset
2555 * value of an iterator of this class is a std::tr1::sub_match object.
kono
parents:
diff changeset
2556 */
kono
parents:
diff changeset
2557 template<typename _Bi_iter,
kono
parents:
diff changeset
2558 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
kono
parents:
diff changeset
2559 typename _Rx_traits = regex_traits<_Ch_type> >
kono
parents:
diff changeset
2560 class regex_token_iterator
kono
parents:
diff changeset
2561 {
kono
parents:
diff changeset
2562 public:
kono
parents:
diff changeset
2563 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
kono
parents:
diff changeset
2564 typedef sub_match<_Bi_iter> value_type;
kono
parents:
diff changeset
2565 typedef std::ptrdiff_t difference_type;
kono
parents:
diff changeset
2566 typedef const value_type* pointer;
kono
parents:
diff changeset
2567 typedef const value_type& reference;
kono
parents:
diff changeset
2568 typedef std::forward_iterator_tag iterator_category;
kono
parents:
diff changeset
2569
kono
parents:
diff changeset
2570 public:
kono
parents:
diff changeset
2571 /**
kono
parents:
diff changeset
2572 * @brief Default constructs a %regex_token_iterator.
kono
parents:
diff changeset
2573 * @todo Implement this function.
kono
parents:
diff changeset
2574 *
kono
parents:
diff changeset
2575 * A default-constructed %regex_token_iterator is a singular iterator
kono
parents:
diff changeset
2576 * that will compare equal to the one-past-the-end value for any
kono
parents:
diff changeset
2577 * iterator of the same type.
kono
parents:
diff changeset
2578 */
kono
parents:
diff changeset
2579 regex_token_iterator();
kono
parents:
diff changeset
2580
kono
parents:
diff changeset
2581 /**
kono
parents:
diff changeset
2582 * Constructs a %regex_token_iterator...
kono
parents:
diff changeset
2583 * @param a [IN] The start of the text to search.
kono
parents:
diff changeset
2584 * @param b [IN] One-past-the-end of the text to search.
kono
parents:
diff changeset
2585 * @param re [IN] The regular expression to search for.
kono
parents:
diff changeset
2586 * @param submatch [IN] Which submatch to return. There are some
kono
parents:
diff changeset
2587 * special values for this parameter:
kono
parents:
diff changeset
2588 * - -1 each enumerated subexpression does NOT
kono
parents:
diff changeset
2589 * match the regular expression (aka field
kono
parents:
diff changeset
2590 * splitting)
kono
parents:
diff changeset
2591 * - 0 the entire string matching the
kono
parents:
diff changeset
2592 * subexpression is returned for each match
kono
parents:
diff changeset
2593 * within the text.
kono
parents:
diff changeset
2594 * - >0 enumerates only the indicated
kono
parents:
diff changeset
2595 * subexpression from a match within the text.
kono
parents:
diff changeset
2596 * @param m [IN] Policy flags for match rules.
kono
parents:
diff changeset
2597 *
kono
parents:
diff changeset
2598 * @todo Implement this function.
kono
parents:
diff changeset
2599 * @doctodo
kono
parents:
diff changeset
2600 */
kono
parents:
diff changeset
2601 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
kono
parents:
diff changeset
2602 int __submatch = 0,
kono
parents:
diff changeset
2603 regex_constants::match_flag_type __m
kono
parents:
diff changeset
2604 = regex_constants::match_default);
kono
parents:
diff changeset
2605
kono
parents:
diff changeset
2606 /**
kono
parents:
diff changeset
2607 * Constructs a %regex_token_iterator...
kono
parents:
diff changeset
2608 * @param a [IN] The start of the text to search.
kono
parents:
diff changeset
2609 * @param b [IN] One-past-the-end of the text to search.
kono
parents:
diff changeset
2610 * @param re [IN] The regular expression to search for.
kono
parents:
diff changeset
2611 * @param submatches [IN] A list of subexpressions to return for each
kono
parents:
diff changeset
2612 * regular expression match within the text.
kono
parents:
diff changeset
2613 * @param m [IN] Policy flags for match rules.
kono
parents:
diff changeset
2614 *
kono
parents:
diff changeset
2615 * @todo Implement this function.
kono
parents:
diff changeset
2616 * @doctodo
kono
parents:
diff changeset
2617 */
kono
parents:
diff changeset
2618 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
kono
parents:
diff changeset
2619 const regex_type& __re,
kono
parents:
diff changeset
2620 const std::vector<int>& __submatches,
kono
parents:
diff changeset
2621 regex_constants::match_flag_type __m
kono
parents:
diff changeset
2622 = regex_constants::match_default);
kono
parents:
diff changeset
2623
kono
parents:
diff changeset
2624 /**
kono
parents:
diff changeset
2625 * Constructs a %regex_token_iterator...
kono
parents:
diff changeset
2626 * @param a [IN] The start of the text to search.
kono
parents:
diff changeset
2627 * @param b [IN] One-past-the-end of the text to search.
kono
parents:
diff changeset
2628 * @param re [IN] The regular expression to search for.
kono
parents:
diff changeset
2629 * @param submatches [IN] A list of subexpressions to return for each
kono
parents:
diff changeset
2630 * regular expression match within the text.
kono
parents:
diff changeset
2631 * @param m [IN] Policy flags for match rules.
kono
parents:
diff changeset
2632
kono
parents:
diff changeset
2633 * @todo Implement this function.
kono
parents:
diff changeset
2634 * @doctodo
kono
parents:
diff changeset
2635 */
kono
parents:
diff changeset
2636 template<std::size_t _Nm>
kono
parents:
diff changeset
2637 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
kono
parents:
diff changeset
2638 const regex_type& __re,
kono
parents:
diff changeset
2639 const int (&__submatches)[_Nm],
kono
parents:
diff changeset
2640 regex_constants::match_flag_type __m
kono
parents:
diff changeset
2641 = regex_constants::match_default);
kono
parents:
diff changeset
2642
kono
parents:
diff changeset
2643 /**
kono
parents:
diff changeset
2644 * @brief Copy constructs a %regex_token_iterator.
kono
parents:
diff changeset
2645 * @param rhs [IN] A %regex_token_iterator to copy.
kono
parents:
diff changeset
2646 * @todo Implement this function.
kono
parents:
diff changeset
2647 */
kono
parents:
diff changeset
2648 regex_token_iterator(const regex_token_iterator& __rhs);
kono
parents:
diff changeset
2649
kono
parents:
diff changeset
2650 /**
kono
parents:
diff changeset
2651 * @brief Assigns a %regex_token_iterator to another.
kono
parents:
diff changeset
2652 * @param rhs [IN] A %regex_token_iterator to copy.
kono
parents:
diff changeset
2653 * @todo Implement this function.
kono
parents:
diff changeset
2654 */
kono
parents:
diff changeset
2655 regex_token_iterator&
kono
parents:
diff changeset
2656 operator=(const regex_token_iterator& __rhs);
kono
parents:
diff changeset
2657
kono
parents:
diff changeset
2658 /**
kono
parents:
diff changeset
2659 * @brief Compares a %regex_token_iterator to another for equality.
kono
parents:
diff changeset
2660 * @todo Implement this function.
kono
parents:
diff changeset
2661 */
kono
parents:
diff changeset
2662 bool
kono
parents:
diff changeset
2663 operator==(const regex_token_iterator& __rhs);
kono
parents:
diff changeset
2664
kono
parents:
diff changeset
2665 /**
kono
parents:
diff changeset
2666 * @brief Compares a %regex_token_iterator to another for inequality.
kono
parents:
diff changeset
2667 * @todo Implement this function.
kono
parents:
diff changeset
2668 */
kono
parents:
diff changeset
2669 bool
kono
parents:
diff changeset
2670 operator!=(const regex_token_iterator& __rhs);
kono
parents:
diff changeset
2671
kono
parents:
diff changeset
2672 /**
kono
parents:
diff changeset
2673 * @brief Dereferences a %regex_token_iterator.
kono
parents:
diff changeset
2674 * @todo Implement this function.
kono
parents:
diff changeset
2675 */
kono
parents:
diff changeset
2676 const value_type&
kono
parents:
diff changeset
2677 operator*();
kono
parents:
diff changeset
2678
kono
parents:
diff changeset
2679 /**
kono
parents:
diff changeset
2680 * @brief Selects a %regex_token_iterator member.
kono
parents:
diff changeset
2681 * @todo Implement this function.
kono
parents:
diff changeset
2682 */
kono
parents:
diff changeset
2683 const value_type*
kono
parents:
diff changeset
2684 operator->();
kono
parents:
diff changeset
2685
kono
parents:
diff changeset
2686 /**
kono
parents:
diff changeset
2687 * @brief Increments a %regex_token_iterator.
kono
parents:
diff changeset
2688 * @todo Implement this function.
kono
parents:
diff changeset
2689 */
kono
parents:
diff changeset
2690 regex_token_iterator&
kono
parents:
diff changeset
2691 operator++();
kono
parents:
diff changeset
2692
kono
parents:
diff changeset
2693 /**
kono
parents:
diff changeset
2694 * @brief Postincrements a %regex_token_iterator.
kono
parents:
diff changeset
2695 * @todo Implement this function.
kono
parents:
diff changeset
2696 */
kono
parents:
diff changeset
2697 regex_token_iterator
kono
parents:
diff changeset
2698 operator++(int);
kono
parents:
diff changeset
2699
kono
parents:
diff changeset
2700 private: // data members for exposition only:
kono
parents:
diff changeset
2701 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
kono
parents:
diff changeset
2702
kono
parents:
diff changeset
2703 position_iterator __position;
kono
parents:
diff changeset
2704 const value_type* __result;
kono
parents:
diff changeset
2705 value_type __suffix;
kono
parents:
diff changeset
2706 std::size_t __n;
kono
parents:
diff changeset
2707 std::vector<int> __subs;
kono
parents:
diff changeset
2708 };
kono
parents:
diff changeset
2709
kono
parents:
diff changeset
2710 /** @brief Token iterator for C-style NULL-terminated strings. */
kono
parents:
diff changeset
2711 typedef regex_token_iterator<const char*> cregex_token_iterator;
kono
parents:
diff changeset
2712 /** @brief Token iterator for standard strings. */
kono
parents:
diff changeset
2713 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
kono
parents:
diff changeset
2714 #ifdef _GLIBCXX_USE_WCHAR_T
kono
parents:
diff changeset
2715 /** @brief Token iterator for C-style NULL-terminated wide strings. */
kono
parents:
diff changeset
2716 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
kono
parents:
diff changeset
2717 /** @brief Token iterator for standard wide-character strings. */
kono
parents:
diff changeset
2718 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
kono
parents:
diff changeset
2719 #endif
kono
parents:
diff changeset
2720
kono
parents:
diff changeset
2721 //@}
kono
parents:
diff changeset
2722 }
kono
parents:
diff changeset
2723
kono
parents:
diff changeset
2724 _GLIBCXX_END_NAMESPACE_VERSION
kono
parents:
diff changeset
2725 }
kono
parents:
diff changeset
2726
kono
parents:
diff changeset
2727 #endif // _GLIBCXX_TR1_REGEX