1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 _LIBCPP_BEGIN_NAMESPACE_STD
17 make_error_type_string(regex_constants::error_type ecode
)
21 case regex_constants::error_collate
:
22 return "The expression contained an invalid collating element name.";
23 case regex_constants::error_ctype
:
24 return "The expression contained an invalid character class name.";
25 case regex_constants::error_escape
:
26 return "The expression contained an invalid escaped character, or a "
28 case regex_constants::error_backref
:
29 return "The expression contained an invalid back reference.";
30 case regex_constants::error_brack
:
31 return "The expression contained mismatched [ and ].";
32 case regex_constants::error_paren
:
33 return "The expression contained mismatched ( and ).";
34 case regex_constants::error_brace
:
35 return "The expression contained mismatched { and }.";
36 case regex_constants::error_badbrace
:
37 return "The expression contained an invalid range in a {} expression.";
38 case regex_constants::error_range
:
39 return "The expression contained an invalid character range, "
40 "such as [b-a] in most encodings.";
41 case regex_constants::error_space
:
42 return "There was insufficient memory to convert the expression into "
43 "a finite state machine.";
44 case regex_constants::error_badrepeat
:
45 return "One of *?+{ was not preceded by a valid regular expression.";
46 case regex_constants::error_complexity
:
47 return "The complexity of an attempted match against a regular "
48 "expression exceeded a pre-set level.";
49 case regex_constants::error_stack
:
50 return "There was insufficient memory to determine whether the regular "
51 "expression could match the specified character sequence.";
52 case regex_constants::__re_err_grammar
:
53 return "An invalid regex grammar has been requested.";
54 case regex_constants::__re_err_empty
:
55 return "An empty regex is not allowed in the POSIX grammar.";
56 case regex_constants::__re_err_parse
:
57 return "The parser did not consume the entire regular expression.";
61 return "Unknown error type";
64 regex_error::regex_error(regex_constants::error_type ecode
)
65 : runtime_error(make_error_type_string(ecode
)),
69 regex_error::~regex_error() throw() {}
79 #if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
81 // Sorted via the EBCDIC collating sequence
82 const collationnames collatenames
[] =
93 {"carriage-return", 0xd},
95 {"circumflex-accent", 0x5f},
98 {"commercial-at", 0x7c},
100 {"dollar-sign", 0x5b},
103 {"equals-sign", 0x7e},
104 {"exclamation-mark", 0x5a},
111 {"grave-accent", 0x79},
112 {"greater-than-sign", 0x6e},
115 {"hyphen-minus", 0x60},
120 {"left-brace", 0xc0},
121 {"left-curly-bracket", 0xc0},
122 {"left-parenthesis", 0x4d},
123 {"left-square-bracket", 0xad},
124 {"less-than-sign", 0x4c},
130 {"number-sign", 0x7b},
134 {"percent-sign", 0x6c},
138 {"question-mark", 0x6f},
139 {"quotation-mark", 0x7f},
141 {"reverse-solidus", 0xe0},
142 {"right-brace", 0xd0},
143 {"right-curly-bracket", 0xd0},
144 {"right-parenthesis", 0x5d},
145 {"right-square-bracket", 0xbd},
159 {"underscore", 0x6d},
161 {"vertical-line", 0x4f},
162 {"vertical-tab", 0xb},
198 const collationnames collatenames
[] =
230 {"apostrophe", 0x27},
236 {"carriage-return", 0x0d},
237 {"circumflex", 0x5e},
238 {"circumflex-accent", 0x5e},
241 {"commercial-at", 0x40},
243 {"dollar-sign", 0x24},
246 {"equals-sign", 0x3d},
247 {"exclamation-mark", 0x21},
254 {"grave-accent", 0x60},
255 {"greater-than-sign", 0x3e},
258 {"hyphen-minus", 0x2d},
263 {"left-brace", 0x7b},
264 {"left-curly-bracket", 0x7b},
265 {"left-parenthesis", 0x28},
266 {"left-square-bracket", 0x5b},
267 {"less-than-sign", 0x3c},
273 {"number-sign", 0x23},
277 {"percent-sign", 0x25},
281 {"question-mark", 0x3f},
282 {"quotation-mark", 0x22},
284 {"reverse-solidus", 0x5c},
285 {"right-brace", 0x7d},
286 {"right-curly-bracket", 0x7d},
287 {"right-parenthesis", 0x29},
288 {"right-square-bracket", 0x5d},
302 {"underscore", 0x5f},
304 {"vertical-line", 0x7c},
305 {"vertical-tab", 0x0b},
317 regex_traits
<char>::char_class_type mask_
;
320 const classnames ClassNames
[] =
322 {"alnum", ctype_base::alnum
},
323 {"alpha", ctype_base::alpha
},
324 {"blank", ctype_base::blank
},
325 {"cntrl", ctype_base::cntrl
},
326 {"d", ctype_base::digit
},
327 {"digit", ctype_base::digit
},
328 {"graph", ctype_base::graph
},
329 {"lower", ctype_base::lower
},
330 {"print", ctype_base::print
},
331 {"punct", ctype_base::punct
},
332 {"s", ctype_base::space
},
333 {"space", ctype_base::space
},
334 {"upper", ctype_base::upper
},
335 {"w", regex_traits
<char>::__regex_word
},
336 {"xdigit", ctype_base::xdigit
}
341 bool operator()(const collationnames
& x
, const char* y
)
342 {return strcmp(x
.elem_
, y
) < 0;}
343 bool operator()(const classnames
& x
, const char* y
)
344 {return strcmp(x
.elem_
, y
) < 0;}
350 __get_collation_name(const char* s
)
352 const collationnames
* i
=
353 _VSTD::lower_bound(begin(collatenames
), end(collatenames
), s
, use_strcmp());
355 if (i
!= end(collatenames
) && strcmp(s
, i
->elem_
) == 0)
360 regex_traits
<char>::char_class_type
361 __get_classname(const char* s
, bool __icase
)
363 const classnames
* i
=
364 _VSTD::lower_bound(begin(ClassNames
), end(ClassNames
), s
, use_strcmp());
365 regex_traits
<char>::char_class_type r
= 0;
366 if (i
!= end(ClassNames
) && strcmp(s
, i
->elem_
) == 0)
369 if (r
== regex_traits
<char>::__regex_word
)
370 r
|= ctype_base::alnum
| ctype_base::upper
| ctype_base::lower
;
373 if (r
& (ctype_base::lower
| ctype_base::upper
))
374 r
|= ctype_base::alpha
;
382 __match_any_but_newline
<char>::__exec(__state
& __s
) const
384 if (__s
.__current_
!= __s
.__last_
)
386 switch (*__s
.__current_
)
390 __s
.__do_
= __state::__reject
;
391 __s
.__node_
= nullptr;
394 __s
.__do_
= __state::__accept_and_consume
;
396 __s
.__node_
= this->first();
402 __s
.__do_
= __state::__reject
;
403 __s
.__node_
= nullptr;
409 __match_any_but_newline
<wchar_t>::__exec(__state
& __s
) const
411 if (__s
.__current_
!= __s
.__last_
)
413 switch (*__s
.__current_
)
419 __s
.__do_
= __state::__reject
;
420 __s
.__node_
= nullptr;
423 __s
.__do_
= __state::__accept_and_consume
;
425 __s
.__node_
= this->first();
431 __s
.__do_
= __state::__reject
;
432 __s
.__node_
= nullptr;
436 _LIBCPP_END_NAMESPACE_STD