]>
Commit | Line | Data |
---|---|---|
849cab7b SW |
1 | // class template regex -*- C++ -*- |
2 | ||
99dee823 | 3 | // Copyright (C) 2010-2021 Free Software Foundation, Inc. |
849cab7b SW |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // Under Section 7 of GPL version 3, you are granted additional | |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
24 | ||
25 | /** | |
f910786b BK |
26 | * @file bits/regex_constants.h |
27 | * @brief Constant definitions for the std regex library. | |
849cab7b SW |
28 | * |
29 | * This is an internal header file, included by other library headers. | |
f910786b | 30 | * Do not attempt to use it directly. @headername{regex} |
849cab7b SW |
31 | */ |
32 | ||
12ffa228 BK |
33 | namespace std _GLIBCXX_VISIBILITY(default) |
34 | { | |
4a15d842 FD |
35 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
36 | ||
e07b233d BK |
37 | /** |
38 | * @defgroup regex Regular Expressions | |
39 | * | |
40 | * A facility for performing regular expression pattern matching. | |
41 | * @{ | |
42 | */ | |
43 | ||
849cab7b SW |
44 | /** |
45 | * @namespace std::regex_constants | |
19aaf814 | 46 | * @brief ISO C++ 2011 namespace for options and flags used with std::regex |
849cab7b SW |
47 | */ |
48 | namespace regex_constants | |
49 | { | |
50 | /** | |
51 | * @name 5.1 Regular Expression Syntax Options | |
52 | */ | |
f0b88346 | 53 | ///@{ |
849cab7b | 54 | enum __syntax_option |
b21abcee TS |
55 | { |
56 | _S_icase, | |
57 | _S_nosubs, | |
58 | _S_optimize, | |
59 | _S_collate, | |
60 | _S_ECMAScript, | |
61 | _S_basic, | |
62 | _S_extended, | |
63 | _S_awk, | |
64 | _S_grep, | |
65 | _S_egrep, | |
e4846be7 | 66 | _S_polynomial, |
b21abcee TS |
67 | _S_syntax_last |
68 | }; | |
849cab7b SW |
69 | |
70 | /** | |
71 | * @brief This is a bitmask type indicating how to interpret the regex. | |
72 | * | |
73 | * The @c syntax_option_type is implementation defined but it is valid to | |
74 | * perform bitwise operations on these values and expect the right thing to | |
75 | * happen. | |
76 | * | |
77 | * A valid value of type syntax_option_type shall have exactly one of the | |
78 | * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep | |
79 | * %set. | |
80 | */ | |
28943113 TS |
81 | enum syntax_option_type : unsigned int { }; |
82 | ||
83 | /** | |
84 | * Specifies that the matching of regular expressions against a character | |
85 | * sequence shall be performed without regard to case. | |
86 | */ | |
288695f7 | 87 | _GLIBCXX17_INLINE constexpr syntax_option_type icase = |
28943113 TS |
88 | static_cast<syntax_option_type>(1 << _S_icase); |
89 | ||
90 | /** | |
91 | * Specifies that when a regular expression is matched against a character | |
92 | * container sequence, no sub-expression matches are to be stored in the | |
93 | * supplied match_results structure. | |
94 | */ | |
288695f7 | 95 | _GLIBCXX17_INLINE constexpr syntax_option_type nosubs = |
28943113 TS |
96 | static_cast<syntax_option_type>(1 << _S_nosubs); |
97 | ||
98 | /** | |
99 | * Specifies that the regular expression engine should pay more attention to | |
100 | * the speed with which regular expressions are matched, and less to the | |
101 | * speed with which regular expression objects are constructed. Otherwise | |
102 | * it has no detectable effect on the program output. | |
103 | */ | |
288695f7 | 104 | _GLIBCXX17_INLINE constexpr syntax_option_type optimize = |
28943113 TS |
105 | static_cast<syntax_option_type>(1 << _S_optimize); |
106 | ||
107 | /** | |
108 | * Specifies that character ranges of the form [a-b] should be locale | |
109 | * sensitive. | |
110 | */ | |
288695f7 | 111 | _GLIBCXX17_INLINE constexpr syntax_option_type collate = |
28943113 TS |
112 | static_cast<syntax_option_type>(1 << _S_collate); |
113 | ||
114 | /** | |
115 | * Specifies that the grammar recognized by the regular expression engine is | |
116 | * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript | |
117 | * Language Specification, Standard Ecma-262, third edition, 1999], as | |
118 | * modified in section [28.13]. This grammar is similar to that defined | |
119 | * in the PERL scripting language but extended with elements found in the | |
120 | * POSIX regular expression grammar. | |
121 | */ | |
288695f7 | 122 | _GLIBCXX17_INLINE constexpr syntax_option_type ECMAScript = |
28943113 TS |
123 | static_cast<syntax_option_type>(1 << _S_ECMAScript); |
124 | ||
125 | /** | |
126 | * Specifies that the grammar recognized by the regular expression engine is | |
127 | * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001, | |
128 | * Portable Operating System Interface (POSIX), Base Definitions and | |
129 | * Headers, Section 9, Regular Expressions [IEEE, Information Technology -- | |
130 | * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. | |
131 | */ | |
288695f7 | 132 | _GLIBCXX17_INLINE constexpr syntax_option_type basic = |
28943113 TS |
133 | static_cast<syntax_option_type>(1 << _S_basic); |
134 | ||
135 | /** | |
136 | * Specifies that the grammar recognized by the regular expression engine is | |
137 | * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001, | |
138 | * Portable Operating System Interface (POSIX), Base Definitions and | |
139 | * Headers, Section 9, Regular Expressions. | |
140 | */ | |
288695f7 | 141 | _GLIBCXX17_INLINE constexpr syntax_option_type extended = |
28943113 TS |
142 | static_cast<syntax_option_type>(1 << _S_extended); |
143 | ||
144 | /** | |
145 | * Specifies that the grammar recognized by the regular expression engine is | |
146 | * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is | |
147 | * identical to syntax_option_type extended, except that C-style escape | |
148 | * sequences are supported. These sequences are: | |
149 | * \\\\, \\a, \\b, \\f, \\n, \\r, \\t , \\v, \\&apos,, &apos,, | |
150 | * and \\ddd (where ddd is one, two, or three octal digits). | |
151 | */ | |
288695f7 | 152 | _GLIBCXX17_INLINE constexpr syntax_option_type awk = |
28943113 TS |
153 | static_cast<syntax_option_type>(1 << _S_awk); |
154 | ||
155 | /** | |
156 | * Specifies that the grammar recognized by the regular expression engine is | |
157 | * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is | |
158 | * identical to syntax_option_type basic, except that newlines are treated | |
159 | * as whitespace. | |
160 | */ | |
288695f7 | 161 | _GLIBCXX17_INLINE constexpr syntax_option_type grep = |
28943113 TS |
162 | static_cast<syntax_option_type>(1 << _S_grep); |
163 | ||
164 | /** | |
165 | * Specifies that the grammar recognized by the regular expression engine is | |
166 | * that used by POSIX utility grep when given the -E option in | |
167 | * IEEE Std 1003.1-2001. This option is identical to syntax_option_type | |
168 | * extended, except that newlines are treated as whitespace. | |
169 | */ | |
288695f7 | 170 | _GLIBCXX17_INLINE constexpr syntax_option_type egrep = |
28943113 | 171 | static_cast<syntax_option_type>(1 << _S_egrep); |
849cab7b | 172 | |
e4846be7 TS |
173 | /** |
174 | * Extension: Ensure both space complexity of compiled regex and | |
175 | * time complexity execution are not exponential. | |
176 | * If specified in a regex with back-references, the exception | |
177 | * regex_constants::error_complexity will be thrown. | |
178 | */ | |
288695f7 | 179 | _GLIBCXX17_INLINE constexpr syntax_option_type __polynomial = |
e4846be7 TS |
180 | static_cast<syntax_option_type>(1 << _S_polynomial); |
181 | ||
6646d624 TS |
182 | constexpr inline syntax_option_type |
183 | operator&(syntax_option_type __a, syntax_option_type __b) | |
184 | { | |
185 | return (syntax_option_type)(static_cast<unsigned int>(__a) | |
e280b6ff | 186 | & static_cast<unsigned int>(__b)); |
6646d624 TS |
187 | } |
188 | ||
189 | constexpr inline syntax_option_type | |
190 | operator|(syntax_option_type __a, syntax_option_type __b) | |
191 | { | |
192 | return (syntax_option_type)(static_cast<unsigned int>(__a) | |
e280b6ff | 193 | | static_cast<unsigned int>(__b)); |
6646d624 TS |
194 | } |
195 | ||
196 | constexpr inline syntax_option_type | |
197 | operator^(syntax_option_type __a, syntax_option_type __b) | |
198 | { | |
199 | return (syntax_option_type)(static_cast<unsigned int>(__a) | |
e280b6ff | 200 | ^ static_cast<unsigned int>(__b)); |
6646d624 TS |
201 | } |
202 | ||
203 | constexpr inline syntax_option_type | |
204 | operator~(syntax_option_type __a) | |
205 | { return (syntax_option_type)(~static_cast<unsigned int>(__a)); } | |
206 | ||
207 | inline syntax_option_type& | |
208 | operator&=(syntax_option_type& __a, syntax_option_type __b) | |
209 | { return __a = __a & __b; } | |
210 | ||
211 | inline syntax_option_type& | |
212 | operator|=(syntax_option_type& __a, syntax_option_type __b) | |
213 | { return __a = __a | __b; } | |
214 | ||
215 | inline syntax_option_type& | |
216 | operator^=(syntax_option_type& __a, syntax_option_type __b) | |
217 | { return __a = __a ^ __b; } | |
849cab7b | 218 | |
f0b88346 | 219 | ///@} |
849cab7b SW |
220 | |
221 | /** | |
222 | * @name 5.2 Matching Rules | |
223 | * | |
224 | * Matching a regular expression against a sequence of characters [first, | |
225 | * last) proceeds according to the rules of the grammar specified for the | |
226 | * regular expression object, modified according to the effects listed | |
227 | * below for any bitmask elements set. | |
228 | * | |
229 | */ | |
f0b88346 | 230 | ///@{ |
849cab7b SW |
231 | |
232 | enum __match_flag | |
b21abcee TS |
233 | { |
234 | _S_not_bol, | |
235 | _S_not_eol, | |
236 | _S_not_bow, | |
237 | _S_not_eow, | |
238 | _S_any, | |
239 | _S_not_null, | |
240 | _S_continuous, | |
241 | _S_prev_avail, | |
242 | _S_sed, | |
243 | _S_no_copy, | |
244 | _S_first_only, | |
245 | _S_match_flag_last | |
246 | }; | |
849cab7b SW |
247 | |
248 | /** | |
249 | * @brief This is a bitmask type indicating regex matching rules. | |
250 | * | |
251 | * The @c match_flag_type is implementation defined but it is valid to | |
252 | * perform bitwise operations on these values and expect the right thing to | |
253 | * happen. | |
254 | */ | |
28943113 TS |
255 | enum match_flag_type : unsigned int { }; |
256 | ||
257 | /** | |
258 | * The default matching rules. | |
259 | */ | |
288695f7 DK |
260 | _GLIBCXX17_INLINE constexpr match_flag_type match_default = |
261 | static_cast<match_flag_type>(0); | |
28943113 TS |
262 | |
263 | /** | |
264 | * The first character in the sequence [first, last) is treated as though it | |
265 | * is not at the beginning of a line, so the character (^) in the regular | |
266 | * expression shall not match [first, first). | |
267 | */ | |
288695f7 | 268 | _GLIBCXX17_INLINE constexpr match_flag_type match_not_bol = |
28943113 TS |
269 | static_cast<match_flag_type>(1 << _S_not_bol); |
270 | ||
271 | /** | |
272 | * The last character in the sequence [first, last) is treated as though it | |
273 | * is not at the end of a line, so the character ($) in the regular | |
274 | * expression shall not match [last, last). | |
275 | */ | |
288695f7 | 276 | _GLIBCXX17_INLINE constexpr match_flag_type match_not_eol = |
28943113 TS |
277 | static_cast<match_flag_type>(1 << _S_not_eol); |
278 | ||
279 | /** | |
280 | * The expression \\b is not matched against the sub-sequence | |
281 | * [first,first). | |
282 | */ | |
288695f7 | 283 | _GLIBCXX17_INLINE constexpr match_flag_type match_not_bow = |
28943113 TS |
284 | static_cast<match_flag_type>(1 << _S_not_bow); |
285 | ||
286 | /** | |
287 | * The expression \\b should not be matched against the sub-sequence | |
288 | * [last,last). | |
289 | */ | |
288695f7 | 290 | _GLIBCXX17_INLINE constexpr match_flag_type match_not_eow = |
28943113 TS |
291 | static_cast<match_flag_type>(1 << _S_not_eow); |
292 | ||
293 | /** | |
294 | * If more than one match is possible then any match is an acceptable | |
295 | * result. | |
296 | */ | |
288695f7 | 297 | _GLIBCXX17_INLINE constexpr match_flag_type match_any = |
28943113 TS |
298 | static_cast<match_flag_type>(1 << _S_any); |
299 | ||
300 | /** | |
301 | * The expression does not match an empty sequence. | |
302 | */ | |
288695f7 | 303 | _GLIBCXX17_INLINE constexpr match_flag_type match_not_null = |
28943113 TS |
304 | static_cast<match_flag_type>(1 << _S_not_null); |
305 | ||
306 | /** | |
307 | * The expression only matches a sub-sequence that begins at first . | |
308 | */ | |
288695f7 | 309 | _GLIBCXX17_INLINE constexpr match_flag_type match_continuous = |
28943113 TS |
310 | static_cast<match_flag_type>(1 << _S_continuous); |
311 | ||
312 | /** | |
313 | * --first is a valid iterator position. When this flag is set then the | |
314 | * flags match_not_bol and match_not_bow are ignored by the regular | |
315 | * expression algorithms 28.11 and iterators 28.12. | |
316 | */ | |
288695f7 | 317 | _GLIBCXX17_INLINE constexpr match_flag_type match_prev_avail = |
28943113 TS |
318 | static_cast<match_flag_type>(1 << _S_prev_avail); |
319 | ||
320 | /** | |
321 | * When a regular expression match is to be replaced by a new string, the | |
322 | * new string is constructed using the rules used by the ECMAScript replace | |
323 | * function in ECMA- 262 [Ecma International, ECMAScript Language | |
324 | * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11 | |
325 | * String.prototype.replace. In addition, during search and replace | |
326 | * operations all non-overlapping occurrences of the regular expression | |
327 | * are located and replaced, and sections of the input that did not match | |
328 | * the expression are copied unchanged to the output string. | |
329 | * | |
330 | * Format strings (from ECMA-262 [15.5.4.11]): | |
331 | * @li $$ The dollar-sign itself ($) | |
332 | * @li $& The matched substring. | |
333 | * @li $` The portion of @a string that precedes the matched substring. | |
334 | * This would be match_results::prefix(). | |
335 | * @li $' The portion of @a string that follows the matched substring. | |
336 | * This would be match_results::suffix(). | |
337 | * @li $n The nth capture, where n is in [1,9] and $n is not followed by a | |
338 | * decimal digit. If n <= match_results::size() and the nth capture | |
339 | * is undefined, use the empty string instead. If n > | |
340 | * match_results::size(), the result is implementation-defined. | |
341 | * @li $nn The nnth capture, where nn is a two-digit decimal number on | |
342 | * [01, 99]. If nn <= match_results::size() and the nth capture is | |
343 | * undefined, use the empty string instead. If | |
344 | * nn > match_results::size(), the result is implementation-defined. | |
345 | */ | |
288695f7 DK |
346 | _GLIBCXX17_INLINE constexpr match_flag_type format_default = |
347 | static_cast<match_flag_type>(0); | |
28943113 TS |
348 | |
349 | /** | |
350 | * When a regular expression match is to be replaced by a new string, the | |
351 | * new string is constructed using the rules used by the POSIX sed utility | |
352 | * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable | |
353 | * Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. | |
354 | */ | |
288695f7 | 355 | _GLIBCXX17_INLINE constexpr match_flag_type format_sed = |
28943113 TS |
356 | static_cast<match_flag_type>(1 << _S_sed); |
357 | ||
358 | /** | |
359 | * During a search and replace operation, sections of the character | |
360 | * container sequence being searched that do not match the regular | |
361 | * expression shall not be copied to the output string. | |
362 | */ | |
288695f7 | 363 | _GLIBCXX17_INLINE constexpr match_flag_type format_no_copy = |
28943113 TS |
364 | static_cast<match_flag_type>(1 << _S_no_copy); |
365 | ||
366 | /** | |
367 | * When specified during a search and replace operation, only the first | |
368 | * occurrence of the regular expression shall be replaced. | |
369 | */ | |
288695f7 | 370 | _GLIBCXX17_INLINE constexpr match_flag_type format_first_only = |
28943113 | 371 | static_cast<match_flag_type>(1 << _S_first_only); |
849cab7b | 372 | |
b21abcee TS |
373 | constexpr inline match_flag_type |
374 | operator&(match_flag_type __a, match_flag_type __b) | |
375 | { | |
376 | return (match_flag_type)(static_cast<unsigned int>(__a) | |
377 | & static_cast<unsigned int>(__b)); | |
378 | } | |
379 | ||
380 | constexpr inline match_flag_type | |
381 | operator|(match_flag_type __a, match_flag_type __b) | |
382 | { | |
383 | return (match_flag_type)(static_cast<unsigned int>(__a) | |
384 | | static_cast<unsigned int>(__b)); | |
385 | } | |
386 | ||
387 | constexpr inline match_flag_type | |
388 | operator^(match_flag_type __a, match_flag_type __b) | |
389 | { | |
390 | return (match_flag_type)(static_cast<unsigned int>(__a) | |
391 | ^ static_cast<unsigned int>(__b)); | |
392 | } | |
393 | ||
394 | constexpr inline match_flag_type | |
395 | operator~(match_flag_type __a) | |
396 | { return (match_flag_type)(~static_cast<unsigned int>(__a)); } | |
397 | ||
398 | inline match_flag_type& | |
399 | operator&=(match_flag_type& __a, match_flag_type __b) | |
400 | { return __a = __a & __b; } | |
401 | ||
402 | inline match_flag_type& | |
403 | operator|=(match_flag_type& __a, match_flag_type __b) | |
404 | { return __a = __a | __b; } | |
405 | ||
406 | inline match_flag_type& | |
407 | operator^=(match_flag_type& __a, match_flag_type __b) | |
408 | { return __a = __a ^ __b; } | |
849cab7b | 409 | |
f0b88346 | 410 | ///@} |
849cab7b | 411 | } // namespace regex_constants |
e07b233d | 412 | /* @} */ // group regex |
4a15d842 FD |
413 | |
414 | _GLIBCXX_END_NAMESPACE_VERSION | |
e07b233d | 415 | } // namespace std |
849cab7b | 416 |