1 //===-------------------------- regex.cpp ---------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
14 _LIBCPP_BEGIN_NAMESPACE_STD
18 make_error_type_string(regex_constants::error_type ecode
)
22 case regex_constants::error_collate
:
23 return "The expression contained an invalid collating element name.";
24 case regex_constants::error_ctype
:
25 return "The expression contained an invalid character class name.";
26 case regex_constants::error_escape
:
27 return "The expression contained an invalid escaped character, or a "
29 case regex_constants::error_backref
:
30 return "The expression contained an invalid back reference.";
31 case regex_constants::error_brack
:
32 return "The expression contained mismatched [ and ].";
33 case regex_constants::error_paren
:
34 return "The expression contained mismatched ( and ).";
35 case regex_constants::error_brace
:
36 return "The expression contained mismatched { and }.";
37 case regex_constants::error_badbrace
:
38 return "The expression contained an invalid range in a {} expression.";
39 case regex_constants::error_range
:
40 return "The expression contained an invalid character range, "
41 "such as [b-a] in most encodings.";
42 case regex_constants::error_space
:
43 return "There was insufficient memory to convert the expression into "
44 "a finite state machine.";
45 case regex_constants::error_badrepeat
:
46 return "One of *?+{ was not preceded by a valid regular expression.";
47 case regex_constants::error_complexity
:
48 return "The complexity of an attempted match against a regular "
49 "expression exceeded a pre-set level.";
50 case regex_constants::error_stack
:
51 return "There was insufficient memory to determine whether the regular "
52 "expression could match the specified character sequence.";
53 case regex_constants::__re_err_grammar
:
54 return "An invalid regex grammar has been requested.";
55 case regex_constants::__re_err_empty
:
56 return "An empty regex is not allowed in the POSIX grammar.";
60 return "Unknown error type";
63 regex_error::regex_error(regex_constants::error_type ecode
)
64 : runtime_error(make_error_type_string(ecode
)),
68 regex_error::~regex_error() throw() {}
72 #pragma clang diagnostic push
73 #pragma clang diagnostic ignored "-Wpadded"
81 #pragma clang diagnostic pop
83 const collationnames collatenames
[] =
115 {"apostrophe", 0x27},
121 {"carriage-return", 0x0d},
122 {"circumflex", 0x5e},
123 {"circumflex-accent", 0x5e},
126 {"commercial-at", 0x40},
128 {"dollar-sign", 0x24},
131 {"equals-sign", 0x3d},
132 {"exclamation-mark", 0x21},
139 {"grave-accent", 0x60},
140 {"greater-than-sign", 0x3e},
143 {"hyphen-minus", 0x2d},
148 {"left-brace", 0x7b},
149 {"left-curly-bracket", 0x7b},
150 {"left-parenthesis", 0x28},
151 {"left-square-bracket", 0x5b},
152 {"less-than-sign", 0x3c},
158 {"number-sign", 0x23},
162 {"percent-sign", 0x25},
166 {"question-mark", 0x3f},
167 {"quotation-mark", 0x22},
169 {"reverse-solidus", 0x5c},
170 {"right-brace", 0x7d},
171 {"right-curly-bracket", 0x7d},
172 {"right-parenthesis", 0x29},
173 {"right-square-bracket", 0x5d},
187 {"underscore", 0x5f},
189 {"vertical-line", 0x7c},
190 {"vertical-tab", 0x0b},
198 #pragma clang diagnostic push
199 #pragma clang diagnostic ignored "-Wpadded"
204 ctype_base::mask mask_
;
207 #pragma clang diagnostic pop
209 const classnames ClassNames
[] =
211 {"alnum", ctype_base::alnum
},
212 {"alpha", ctype_base::alpha
},
213 {"blank", ctype_base::blank
},
214 {"cntrl", ctype_base::cntrl
},
215 {"d", ctype_base::digit
},
216 {"digit", ctype_base::digit
},
217 {"graph", ctype_base::graph
},
218 {"lower", ctype_base::lower
},
219 {"print", ctype_base::print
},
220 {"punct", ctype_base::punct
},
221 {"s", ctype_base::space
},
222 {"space", ctype_base::space
},
223 {"upper", ctype_base::upper
},
224 {"w", regex_traits
<char>::__regex_word
},
225 {"xdigit", ctype_base::xdigit
}
230 bool operator()(const collationnames
& x
, const char* y
)
231 {return strcmp(x
.elem_
, y
) < 0;}
232 bool operator()(const classnames
& x
, const char* y
)
233 {return strcmp(x
.elem_
, y
) < 0;}
239 __get_collation_name(const char* s
)
241 const collationnames
* i
=
242 _VSTD::lower_bound(begin(collatenames
), end(collatenames
), s
, use_strcmp());
244 if (i
!= end(collatenames
) && strcmp(s
, i
->elem_
) == 0)
250 __get_classname(const char* s
, bool __icase
)
252 const classnames
* i
=
253 _VSTD::lower_bound(begin(ClassNames
), end(ClassNames
), s
, use_strcmp());
254 ctype_base::mask r
= 0;
255 if (i
!= end(ClassNames
) && strcmp(s
, i
->elem_
) == 0)
258 if (r
== regex_traits
<char>::__regex_word
)
259 r
|= ctype_base::alnum
| ctype_base::upper
| ctype_base::lower
;
262 if (r
& (ctype_base::lower
| ctype_base::upper
))
263 r
|= ctype_base::alpha
;
271 __match_any_but_newline
<char>::__exec(__state
& __s
) const
273 if (__s
.__current_
!= __s
.__last_
)
275 switch (*__s
.__current_
)
279 __s
.__do_
= __state::__reject
;
280 __s
.__node_
= nullptr;
283 __s
.__do_
= __state::__accept_and_consume
;
285 __s
.__node_
= this->first();
291 __s
.__do_
= __state::__reject
;
292 __s
.__node_
= nullptr;
298 __match_any_but_newline
<wchar_t>::__exec(__state
& __s
) const
300 if (__s
.__current_
!= __s
.__last_
)
302 switch (*__s
.__current_
)
308 __s
.__do_
= __state::__reject
;
309 __s
.__node_
= nullptr;
312 __s
.__do_
= __state::__accept_and_consume
;
314 __s
.__node_
= this->first();
320 __s
.__do_
= __state::__reject
;
321 __s
.__node_
= nullptr;
325 _LIBCPP_END_NAMESPACE_STD