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)
86 _GLIBCXX_DEBUG_ASSERT(
false);
92 template<
typename _CharT>
97 auto __c = *_M_current++;
100 if (std::strchr(_M_spec_char, _M_ctype.narrow(__c,
'\0')) ==
nullptr)
102 _M_token = _S_token_ord_char;
103 _M_value.assign(1, __c);
108 if (_M_current == _M_end)
112 || (*_M_current !=
'('
113 && *_M_current !=
')'
114 && *_M_current !=
'{'))
116 (this->*_M_eat_escape)();
123 if (_M_is_ecma() && *_M_current ==
'?')
125 if (++_M_current == _M_end)
128 if (*_M_current ==
':')
131 _M_token = _S_token_subexpr_no_group_begin;
133 else if (*_M_current ==
'=')
136 _M_token = _S_token_subexpr_lookahead_begin;
137 _M_value.assign(1,
'p');
139 else if (*_M_current ==
'!')
142 _M_token = _S_token_subexpr_lookahead_begin;
143 _M_value.assign(1,
'n');
149 _M_token = _S_token_subexpr_no_group_begin;
151 _M_token = _S_token_subexpr_begin;
154 _M_token = _S_token_subexpr_end;
157 _M_state = _S_state_in_bracket;
158 _M_at_bracket_start =
true;
159 if (_M_current != _M_end && *_M_current ==
'^')
161 _M_token = _S_token_bracket_neg_begin;
165 _M_token = _S_token_bracket_begin;
169 _M_state = _S_state_in_brace;
170 _M_token = _S_token_interval_begin;
172 else if (((__pos = std::strchr(_M_spec_char, _M_ctype.narrow(__c,
'\0')))
177 || (_M_is_grep() && __c ==
'\n'))
179 auto __it = _M_token_tbl;
180 auto __narrowc = _M_ctype.narrow(__c,
'\0');
181 for (; __it->first !=
'\0'; ++__it)
182 if (__it->first == __narrowc)
184 _M_token = __it->second;
187 _GLIBCXX_DEBUG_ASSERT(
false);
191 _M_token = _S_token_ord_char;
192 _M_value.assign(1, __c);
199 template<
typename _CharT>
204 if (_M_current == _M_end)
207 auto __c = *_M_current++;
211 if (_M_current == _M_end)
214 if (*_M_current ==
'.')
216 _M_token = _S_token_collsymbol;
217 _M_eat_class(*_M_current++);
219 else if (*_M_current ==
':')
221 _M_token = _S_token_char_class_name;
222 _M_eat_class(*_M_current++);
224 else if (*_M_current ==
'=')
226 _M_token = _S_token_equiv_class_name;
227 _M_eat_class(*_M_current++);
231 _M_token = _S_token_ord_char;
232 _M_value.assign(1, __c);
238 else if (__c ==
']' && (_M_is_ecma() || !_M_at_bracket_start))
240 _M_token = _S_token_bracket_end;
241 _M_state = _S_state_normal;
244 else if (__c ==
'\\' && (_M_is_ecma() || _M_is_awk()))
245 (this->*_M_eat_escape)();
248 _M_token = _S_token_ord_char;
249 _M_value.assign(1, __c);
251 _M_at_bracket_start =
false;
256 template<
typename _CharT>
261 if (_M_current == _M_end)
264 auto __c = *_M_current++;
266 if (_M_ctype.is(_CtypeT::digit, __c))
268 _M_token = _S_token_dup_count;
269 _M_value.assign(1, __c);
270 while (_M_current != _M_end
271 && _M_ctype.is(_CtypeT::digit, *_M_current))
272 _M_value += *_M_current++;
275 _M_token = _S_token_comma;
277 else if (_M_is_basic())
279 if (__c ==
'\\' && _M_current != _M_end && *_M_current ==
'}')
281 _M_state = _S_state_normal;
282 _M_token = _S_token_interval_end;
290 _M_state = _S_state_normal;
291 _M_token = _S_token_interval_end;
297 template<
typename _CharT>
302 if (_M_current == _M_end)
305 auto __c = *_M_current++;
306 auto __pos = _M_find_escape(_M_ctype.narrow(__c,
'\0'));
308 if (__pos !=
nullptr && (__c !=
'b' || _M_state == _S_state_in_bracket))
310 _M_token = _S_token_ord_char;
311 _M_value.assign(1, *__pos);
315 _M_token = _S_token_word_bound;
316 _M_value.assign(1,
'p');
320 _M_token = _S_token_word_bound;
321 _M_value.assign(1,
'n');
331 _M_token = _S_token_quoted_class;
332 _M_value.assign(1, __c);
336 if (_M_current == _M_end)
338 _M_token = _S_token_ord_char;
339 _M_value.assign(1, *_M_current++);
341 else if (__c ==
'x' || __c ==
'u')
344 for (
int i = 0; i < (__c ==
'x' ? 2 : 4); i++)
346 if (_M_current == _M_end
347 || !_M_ctype.is(_CtypeT::xdigit, *_M_current))
349 _M_value += *_M_current++;
351 _M_token = _S_token_hex_num;
354 else if (_M_ctype.is(_CtypeT::digit, __c))
356 _M_value.assign(1, __c);
357 while (_M_current != _M_end
358 && _M_ctype.is(_CtypeT::digit, *_M_current))
359 _M_value += *_M_current++;
360 _M_token = _S_token_backref;
364 _M_token = _S_token_ord_char;
365 _M_value.assign(1, __c);
371 template<
typename _CharT>
374 _M_eat_escape_posix()
376 if (_M_current == _M_end)
379 auto __c = *_M_current;
380 auto __pos = std::strchr(_M_spec_char, _M_ctype.narrow(__c,
'\0'));
382 if (__pos !=
nullptr && *__pos !=
'\0')
384 _M_token = _S_token_ord_char;
385 _M_value.assign(1, __c);
388 else if (_M_is_awk())
393 else if (_M_is_basic() && _M_ctype.is(_CtypeT::digit, __c) && __c !=
'0')
395 _M_token = _S_token_backref;
396 _M_value.assign(1, __c);
400 #ifdef __STRICT_ANSI__
403 _M_token = _S_token_ord_char;
404 _M_value.assign(1, __c);
410 template<
typename _CharT>
415 auto __c = *_M_current++;
416 auto __pos = _M_find_escape(_M_ctype.narrow(__c,
'\0'));
418 if (__pos !=
nullptr)
420 _M_token = _S_token_ord_char;
421 _M_value.assign(1, *__pos);
424 else if (_M_ctype.is(_CtypeT::digit, __c)
428 _M_value.assign(1, __c);
431 && _M_current != _M_end
432 && _M_ctype.is(_CtypeT::digit, *_M_current)
433 && *_M_current !=
'8'
434 && *_M_current !=
'9';
436 _M_value += *_M_current++;
437 _M_token = _S_token_oct_num;
447 template<
typename _CharT>
450 _M_eat_class(
char __ch)
452 for (_M_value.clear(); _M_current != _M_end && *_M_current != __ch;)
453 _M_value += *_M_current++;
454 if (_M_current == _M_end
455 || *_M_current++ != __ch
456 || _M_current == _M_end
457 || *_M_current++ !=
']')
466 #ifdef _GLIBCXX_DEBUG
467 template<
typename _CharT>
474 case _S_token_anychar:
475 ostr <<
"any-character\n";
477 case _S_token_backref:
480 case _S_token_bracket_begin:
481 ostr <<
"bracket-begin\n";
483 case _S_token_bracket_neg_begin:
484 ostr <<
"bracket-neg-begin\n";
486 case _S_token_bracket_end:
487 ostr <<
"bracket-end\n";
489 case _S_token_char_class_name:
490 ostr <<
"char-class-name \"" << _M_value <<
"\"\n";
492 case _S_token_closure0:
493 ostr <<
"closure0\n";
495 case _S_token_closure1:
496 ostr <<
"closure1\n";
498 case _S_token_collsymbol:
499 ostr <<
"collsymbol \"" << _M_value <<
"\"\n";
504 case _S_token_dup_count:
505 ostr <<
"dup count: " << _M_value <<
"\n";
510 case _S_token_equiv_class_name:
511 ostr <<
"equiv-class-name \"" << _M_value <<
"\"\n";
513 case _S_token_interval_begin:
514 ostr <<
"interval begin\n";
516 case _S_token_interval_end:
517 ostr <<
"interval end\n";
519 case _S_token_line_begin:
520 ostr <<
"line begin\n";
522 case _S_token_line_end:
523 ostr <<
"line end\n";
531 case _S_token_ord_char:
532 ostr <<
"ordinary character: \"" << _M_value <<
"\"\n";
534 case _S_token_subexpr_begin:
535 ostr <<
"subexpr begin\n";
537 case _S_token_subexpr_no_group_begin:
538 ostr <<
"no grouping subexpr begin\n";
540 case _S_token_subexpr_lookahead_begin:
541 ostr <<
"lookahead subexpr begin\n";
543 case _S_token_subexpr_end:
544 ostr <<
"subexpr end\n";
546 case _S_token_unknown:
547 ostr <<
"-- unknown token --\n";
549 case _S_token_oct_num:
550 ostr <<
"oct number " << _M_value <<
"\n";
552 case _S_token_hex_num:
553 ostr <<
"hex number " << _M_value <<
"\n";
555 case _S_token_quoted_class:
556 ostr <<
"quoted class " <<
"\\" << _M_value <<
"\n";
559 _GLIBCXX_DEBUG_ASSERT(
false);
565 _GLIBCXX_END_NAMESPACE_VERSION
constexpr error_type error_escape(_S_error_escape)
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...
constexpr error_type error_ctype(_S_error_ctype)
constexpr error_type error_collate(_S_error_collate)
constexpr error_type error_brack(_S_error_brack)
constexpr error_type error_brace(_S_error_brace)
constexpr error_type error_badbrace(_S_error_badbrace)
Container class for localization functionality.The locale class is first a class wrapper for C librar...
constexpr error_type error_paren(_S_error_paren)