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 #if defined(__clang__)
73 #pragma clang diagnostic push
74 #pragma clang diagnostic ignored "-Wpadded"
83 #if defined(__clang__)
84 #pragma clang diagnostic pop
87 const collationnames collatenames[] =
119 {"apostrophe", 0x27},
125 {"carriage-return", 0x0d},
126 {"circumflex", 0x5e},
127 {"circumflex-accent", 0x5e},
130 {"commercial-at", 0x40},
132 {"dollar-sign", 0x24},
135 {"equals-sign", 0x3d},
136 {"exclamation-mark", 0x21},
143 {"grave-accent", 0x60},
144 {"greater-than-sign", 0x3e},
147 {"hyphen-minus", 0x2d},
152 {"left-brace", 0x7b},
153 {"left-curly-bracket", 0x7b},
154 {"left-parenthesis", 0x28},
155 {"left-square-bracket", 0x5b},
156 {"less-than-sign", 0x3c},
162 {"number-sign", 0x23},
166 {"percent-sign", 0x25},
170 {"question-mark", 0x3f},
171 {"quotation-mark", 0x22},
173 {"reverse-solidus", 0x5c},
174 {"right-brace", 0x7d},
175 {"right-curly-bracket", 0x7d},
176 {"right-parenthesis", 0x29},
177 {"right-square-bracket", 0x5d},
191 {"underscore", 0x5f},
193 {"vertical-line", 0x7c},
194 {"vertical-tab", 0x0b},
202 #if defined(__clang__)
203 #pragma clang diagnostic push
204 #pragma clang diagnostic ignored "-Wpadded"
210 regex_traits<char>::char_class_type mask_;
213 #if defined(__clang__)
214 #pragma clang diagnostic pop
217 const classnames ClassNames[] =
219 {"alnum", ctype_base::alnum},
220 {"alpha", ctype_base::alpha},
221 {"blank", ctype_base::blank},
222 {"cntrl", ctype_base::cntrl},
223 {"d", ctype_base::digit},
224 {"digit", ctype_base::digit},
225 {"graph", ctype_base::graph},
226 {"lower", ctype_base::lower},
227 {"print", ctype_base::print},
228 {"punct", ctype_base::punct},
229 {"s", ctype_base::space},
230 {"space", ctype_base::space},
231 {"upper", ctype_base::upper},
232 {"w", regex_traits<char>::__regex_word},
233 {"xdigit", ctype_base::xdigit}
238 bool operator()(const collationnames& x, const char* y)
239 {return strcmp(x.elem_, y) < 0;}
240 bool operator()(const classnames& x, const char* y)
241 {return strcmp(x.elem_, y) < 0;}
247 __get_collation_name(const char* s)
249 const collationnames* i =
250 _VSTD::lower_bound(begin(collatenames), end(collatenames), s, use_strcmp());
252 if (i != end(collatenames) && strcmp(s, i->elem_) == 0)
257 regex_traits<char>::char_class_type
258 __get_classname(const char* s, bool __icase)
260 const classnames* i =
261 _VSTD::lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp());
262 regex_traits<char>::char_class_type r = 0;
263 if (i != end(ClassNames) && strcmp(s, i->elem_) == 0)
266 if (r == regex_traits<char>::__regex_word)
267 r |= ctype_base::alnum | ctype_base::upper | ctype_base::lower;
270 if (r & (ctype_base::lower | ctype_base::upper))
271 r |= ctype_base::alpha;
279 __match_any_but_newline<char>::__exec(__state& __s) const
281 if (__s.__current_ != __s.__last_)
283 switch (*__s.__current_)
287 __s.__do_ = __state::__reject;
288 __s.__node_ = nullptr;
291 __s.__do_ = __state::__accept_and_consume;
293 __s.__node_ = this->first();
299 __s.__do_ = __state::__reject;
300 __s.__node_ = nullptr;
306 __match_any_but_newline<wchar_t>::__exec(__state& __s) const
308 if (__s.__current_ != __s.__last_)
310 switch (*__s.__current_)
316 __s.__do_ = __state::__reject;
317 __s.__node_ = nullptr;
320 __s.__do_ = __state::__accept_and_consume;
322 __s.__node_ = this->first();
328 __s.__do_ = __state::__reject;
329 __s.__node_ = nullptr;
333 _LIBCPP_END_NAMESPACE_STD