49 namespace std _GLIBCXX_VISIBILITY(default)
53 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 template<
typename _CharT>
57 _Scanner(
typename _Scanner::_IterT __begin,
58 typename _Scanner::_IterT __end,
60 : _ScannerBase(__flags),
61 _M_current(__begin), _M_end(__end),
63 _M_eat_escape(_M_is_ecma()
64 ? &_Scanner::_M_eat_escape_ecma
65 : &_Scanner::_M_eat_escape_posix)
68 template<
typename _CharT>
73 if (_M_current == _M_end)
75 _M_token = _S_token_eof;
79 if (_M_state == _S_state_normal)
81 else if (_M_state == _S_state_in_bracket)
83 else if (_M_state == _S_state_in_brace)
87 __glibcxx_assert(
false);
94 template<
typename _CharT>
99 auto __c = *_M_current++;
101 if (std::strchr(_M_spec_char, _M_ctype.
narrow(__c,
' ')) ==
nullptr)
103 _M_token = _S_token_ord_char;
109 if (_M_current == _M_end)
112 "Unexpected end of regex when escaping.");
115 || (*_M_current !=
'(' 116 && *_M_current !=
')' 117 && *_M_current !=
'{'))
119 (this->*_M_eat_escape)();
126 if (_M_is_ecma() && *_M_current ==
'?')
128 if (++_M_current == _M_end)
131 "Unexpected end of regex when in an open parenthesis.");
133 if (*_M_current ==
':')
136 _M_token = _S_token_subexpr_no_group_begin;
138 else if (*_M_current ==
'=')
141 _M_token = _S_token_subexpr_lookahead_begin;
144 else if (*_M_current ==
'!')
147 _M_token = _S_token_subexpr_lookahead_begin;
153 "Invalid special open parenthesis.");
156 _M_token = _S_token_subexpr_no_group_begin;
158 _M_token = _S_token_subexpr_begin;
161 _M_token = _S_token_subexpr_end;
164 _M_state = _S_state_in_bracket;
165 _M_at_bracket_start =
true;
166 if (_M_current != _M_end && *_M_current ==
'^')
168 _M_token = _S_token_bracket_neg_begin;
172 _M_token = _S_token_bracket_begin;
176 _M_state = _S_state_in_brace;
177 _M_token = _S_token_interval_begin;
179 else if (__c !=
']' && __c !=
'}')
181 auto __it = _M_token_tbl;
182 auto __narrowc = _M_ctype.
narrow(__c,
'\0');
183 for (; __it->first !=
'\0'; ++__it)
184 if (__it->first == __narrowc)
186 _M_token = __it->second;
189 __glibcxx_assert(
false);
193 _M_token = _S_token_ord_char;
201 template<
typename _CharT>
206 if (_M_current == _M_end)
209 "Unexpected end of regex when in bracket expression.");
211 auto __c = *_M_current++;
215 if (_M_current == _M_end)
217 "Unexpected character class open bracket.");
219 if (*_M_current ==
'.')
221 _M_token = _S_token_collsymbol;
222 _M_eat_class(*_M_current++);
224 else if (*_M_current ==
':')
226 _M_token = _S_token_char_class_name;
227 _M_eat_class(*_M_current++);
229 else if (*_M_current ==
'=')
231 _M_token = _S_token_equiv_class_name;
232 _M_eat_class(*_M_current++);
236 _M_token = _S_token_ord_char;
243 else if (__c ==
']' && (_M_is_ecma() || !_M_at_bracket_start))
245 _M_token = _S_token_bracket_end;
246 _M_state = _S_state_normal;
249 else if (__c ==
'\\' && (_M_is_ecma() || _M_is_awk()))
250 (this->*_M_eat_escape)();
253 _M_token = _S_token_ord_char;
256 _M_at_bracket_start =
false;
261 template<
typename _CharT>
266 if (_M_current == _M_end)
269 "Unexpected end of regex when in brace expression.");
271 auto __c = *_M_current++;
273 if (_M_ctype.
is(_CtypeT::digit, __c))
275 _M_token = _S_token_dup_count;
277 while (_M_current != _M_end
278 && _M_ctype.
is(_CtypeT::digit, *_M_current))
279 _M_value += *_M_current++;
282 _M_token = _S_token_comma;
284 else if (_M_is_basic())
286 if (__c ==
'\\' && _M_current != _M_end && *_M_current ==
'}')
288 _M_state = _S_state_normal;
289 _M_token = _S_token_interval_end;
294 "Unexpected character in brace expression.");
298 _M_state = _S_state_normal;
299 _M_token = _S_token_interval_end;
303 "Unexpected character in brace expression.");
306 template<
typename _CharT>
311 if (_M_current == _M_end)
313 "Unexpected end of regex when escaping.");
315 auto __c = *_M_current++;
316 auto __pos = _M_find_escape(_M_ctype.
narrow(__c,
'\0'));
318 if (__pos !=
nullptr && (__c !=
'b' || _M_state == _S_state_in_bracket))
320 _M_token = _S_token_ord_char;
321 _M_value.
assign(1, *__pos);
325 _M_token = _S_token_word_bound;
330 _M_token = _S_token_word_bound;
341 _M_token = _S_token_quoted_class;
346 if (_M_current == _M_end)
349 "Unexpected end of regex when reading control code.");
350 _M_token = _S_token_ord_char;
351 _M_value.
assign(1, *_M_current++);
353 else if (__c ==
'x' || __c ==
'u')
356 for (
int __i = 0; __i < (__c ==
'x' ? 2 : 4); __i++)
358 if (_M_current == _M_end
359 || !_M_ctype.
is(_CtypeT::xdigit, *_M_current))
362 "Unexpected end of regex when ascii character.");
363 _M_value += *_M_current++;
365 _M_token = _S_token_hex_num;
368 else if (_M_ctype.
is(_CtypeT::digit, __c))
371 while (_M_current != _M_end
372 && _M_ctype.
is(_CtypeT::digit, *_M_current))
373 _M_value += *_M_current++;
374 _M_token = _S_token_backref;
378 _M_token = _S_token_ord_char;
385 template<
typename _CharT>
388 _M_eat_escape_posix()
390 if (_M_current == _M_end)
392 "Unexpected end of regex when escaping.");
394 auto __c = *_M_current;
395 auto __pos = std::strchr(_M_spec_char, _M_ctype.
narrow(__c,
'\0'));
397 if (__pos !=
nullptr && *__pos !=
'\0')
399 _M_token = _S_token_ord_char;
403 else if (_M_is_awk())
408 else if (_M_is_basic() && _M_ctype.
is(_CtypeT::digit, __c) && __c !=
'0')
410 _M_token = _S_token_backref;
415 #ifdef __STRICT_ANSI__ 418 "Unexpected escape character.");
420 _M_token = _S_token_ord_char;
427 template<
typename _CharT>
432 auto __c = *_M_current++;
433 auto __pos = _M_find_escape(_M_ctype.
narrow(__c,
'\0'));
435 if (__pos !=
nullptr)
437 _M_token = _S_token_ord_char;
438 _M_value.
assign(1, *__pos);
441 else if (_M_ctype.
is(_CtypeT::digit, __c)
448 && _M_current != _M_end
449 && _M_ctype.
is(_CtypeT::digit, *_M_current)
450 && *_M_current !=
'8' 451 && *_M_current !=
'9';
453 _M_value += *_M_current++;
454 _M_token = _S_token_oct_num;
459 "Unexpected escape character.");
465 template<
typename _CharT>
468 _M_eat_class(
char __ch)
470 for (_M_value.
clear(); _M_current != _M_end && *_M_current != __ch;)
471 _M_value += *_M_current++;
472 if (_M_current == _M_end
473 || *_M_current++ != __ch
474 || _M_current == _M_end
475 || *_M_current++ !=
']')
479 "Unexpected end of character class.");
482 "Unexpected end of character class.");
486 #ifdef _GLIBCXX_DEBUG 487 template<
typename _CharT>
494 case _S_token_anychar:
495 ostr <<
"any-character\n";
497 case _S_token_backref:
500 case _S_token_bracket_begin:
501 ostr <<
"bracket-begin\n";
503 case _S_token_bracket_neg_begin:
504 ostr <<
"bracket-neg-begin\n";
506 case _S_token_bracket_end:
507 ostr <<
"bracket-end\n";
509 case _S_token_char_class_name:
510 ostr <<
"char-class-name \"" << _M_value <<
"\"\n";
512 case _S_token_closure0:
513 ostr <<
"closure0\n";
515 case _S_token_closure1:
516 ostr <<
"closure1\n";
518 case _S_token_collsymbol:
519 ostr <<
"collsymbol \"" << _M_value <<
"\"\n";
524 case _S_token_dup_count:
525 ostr <<
"dup count: " << _M_value <<
"\n";
530 case _S_token_equiv_class_name:
531 ostr <<
"equiv-class-name \"" << _M_value <<
"\"\n";
533 case _S_token_interval_begin:
534 ostr <<
"interval begin\n";
536 case _S_token_interval_end:
537 ostr <<
"interval end\n";
539 case _S_token_line_begin:
540 ostr <<
"line begin\n";
542 case _S_token_line_end:
543 ostr <<
"line end\n";
551 case _S_token_ord_char:
552 ostr <<
"ordinary character: \"" << _M_value <<
"\"\n";
554 case _S_token_subexpr_begin:
555 ostr <<
"subexpr begin\n";
557 case _S_token_subexpr_no_group_begin:
558 ostr <<
"no grouping subexpr begin\n";
560 case _S_token_subexpr_lookahead_begin:
561 ostr <<
"lookahead subexpr begin\n";
563 case _S_token_subexpr_end:
564 ostr <<
"subexpr end\n";
566 case _S_token_unknown:
567 ostr <<
"-- unknown token --\n";
569 case _S_token_oct_num:
570 ostr <<
"oct number " << _M_value <<
"\n";
572 case _S_token_hex_num:
573 ostr <<
"hex number " << _M_value <<
"\n";
575 case _S_token_quoted_class:
576 ostr <<
"quoted class " <<
"\\" << _M_value <<
"\n";
579 _GLIBCXX_DEBUG_ASSERT(
false);
585 _GLIBCXX_END_NAMESPACE_VERSION
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
constexpr error_type error_ctype(_S_error_ctype)
constexpr error_type error_paren(_S_error_paren)
constexpr syntax_option_type nosubs
bool is(mask __m, char_type __c) const
Test char_type classification.
constexpr error_type error_escape(_S_error_escape)
constexpr error_type error_brace(_S_error_brace)
constexpr error_type error_badbrace(_S_error_badbrace)
char narrow(char_type __c, char __dfault) const
Narrow char_type to char.
const _Facet & use_facet(const locale &__loc)
Return a facet.use_facet looks for and returns a reference to a facet of type Facet where Facet is th...
Container class for localization functionality.The locale class is first a class wrapper for C librar...
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
constexpr error_type error_brack(_S_error_brack)
constexpr error_type error_collate(_S_error_collate)
ISO C++ entities toplevel namespace is std.