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() {}
78 const collationnames collatenames[] =
110 {"apostrophe", 0x27},
116 {"carriage-return", 0x0d},
117 {"circumflex", 0x5e},
118 {"circumflex-accent", 0x5e},
121 {"commercial-at", 0x40},
123 {"dollar-sign", 0x24},
126 {"equals-sign", 0x3d},
127 {"exclamation-mark", 0x21},
134 {"grave-accent", 0x60},
135 {"greater-than-sign", 0x3e},
138 {"hyphen-minus", 0x2d},
143 {"left-brace", 0x7b},
144 {"left-curly-bracket", 0x7b},
145 {"left-parenthesis", 0x28},
146 {"left-square-bracket", 0x5b},
147 {"less-than-sign", 0x3c},
153 {"number-sign", 0x23},
157 {"percent-sign", 0x25},
161 {"question-mark", 0x3f},
162 {"quotation-mark", 0x22},
164 {"reverse-solidus", 0x5c},
165 {"right-brace", 0x7d},
166 {"right-curly-bracket", 0x7d},
167 {"right-parenthesis", 0x29},
168 {"right-square-bracket", 0x5d},
182 {"underscore", 0x5f},
184 {"vertical-line", 0x7c},
185 {"vertical-tab", 0x0b},
196 regex_traits<char>::char_class_type mask_;
199 const classnames ClassNames[] =
201 {"alnum", ctype_base::alnum},
202 {"alpha", ctype_base::alpha},
203 {"blank", ctype_base::blank},
204 {"cntrl", ctype_base::cntrl},
205 {"d", ctype_base::digit},
206 {"digit", ctype_base::digit},
207 {"graph", ctype_base::graph},
208 {"lower", ctype_base::lower},
209 {"print", ctype_base::print},
210 {"punct", ctype_base::punct},
211 {"s", ctype_base::space},
212 {"space", ctype_base::space},
213 {"upper", ctype_base::upper},
214 {"w", regex_traits<char>::__regex_word},
215 {"xdigit", ctype_base::xdigit}
220 bool operator()(const collationnames& x, const char* y)
221 {return strcmp(x.elem_, y) < 0;}
222 bool operator()(const classnames& x, const char* y)
223 {return strcmp(x.elem_, y) < 0;}
229 __get_collation_name(const char* s)
231 const collationnames* i =
232 _VSTD::lower_bound(begin(collatenames), end(collatenames), s, use_strcmp());
234 if (i != end(collatenames) && strcmp(s, i->elem_) == 0)
239 regex_traits<char>::char_class_type
240 __get_classname(const char* s, bool __icase)
242 const classnames* i =
243 _VSTD::lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp());
244 regex_traits<char>::char_class_type r = 0;
245 if (i != end(ClassNames) && strcmp(s, i->elem_) == 0)
248 if (r == regex_traits<char>::__regex_word)
249 r |= ctype_base::alnum | ctype_base::upper | ctype_base::lower;
252 if (r & (ctype_base::lower | ctype_base::upper))
253 r |= ctype_base::alpha;
261 __match_any_but_newline<char>::__exec(__state& __s) const
263 if (__s.__current_ != __s.__last_)
265 switch (*__s.__current_)
269 __s.__do_ = __state::__reject;
270 __s.__node_ = nullptr;
273 __s.__do_ = __state::__accept_and_consume;
275 __s.__node_ = this->first();
281 __s.__do_ = __state::__reject;
282 __s.__node_ = nullptr;
288 __match_any_but_newline<wchar_t>::__exec(__state& __s) const
290 if (__s.__current_ != __s.__last_)
292 switch (*__s.__current_)
298 __s.__do_ = __state::__reject;
299 __s.__node_ = nullptr;
302 __s.__do_ = __state::__accept_and_consume;
304 __s.__node_ = this->first();
310 __s.__do_ = __state::__reject;
311 __s.__node_ = nullptr;
315 _LIBCPP_END_NAMESPACE_STD