31namespace std _GLIBCXX_VISIBILITY(default)
33_GLIBCXX_BEGIN_NAMESPACE_VERSION
34_GLIBCXX_BEGIN_NAMESPACE_CXX11
39_GLIBCXX_END_NAMESPACE_CXX11
48 template<
typename,
bool,
bool>
49 struct _BracketMatcher;
56 template<
typename _TraitsT>
60 typedef typename _TraitsT::char_type _CharT;
61 typedef _NFA<_TraitsT> _RegexT;
64 _Compiler(
const _CharT* __b,
const _CharT* __e,
65 const typename _TraitsT::locale_type& __traits,
_FlagT __flags);
73 typedef typename _TraitsT::string_type _StringT;
74 typedef typename _ScannerT::_TokenT _TokenT;
81 _M_match_token(_TokenT __token);
102 _M_bracket_expression();
104 template<
bool __icase,
bool __collate>
106 _M_insert_any_matcher_ecma();
108 template<
bool __icase,
bool __collate>
110 _M_insert_any_matcher_posix();
112 template<
bool __icase,
bool __collate>
114 _M_insert_char_matcher();
116 template<
bool __icase,
bool __collate>
118 _M_insert_character_class_matcher();
120 template<
bool __icase,
bool __collate>
122 _M_insert_bracket_matcher(
bool __neg);
127 enum class _Type :
char { _None, _Char, _Class } _M_type = _Type::_None;
131 set(_CharT __c)
noexcept { _M_type = _Type::_Char; _M_char = __c; }
133 _GLIBCXX_NODISCARD _CharT
134 get()
const noexcept {
return _M_char; }
137 reset(_Type __t = _Type::_None)
noexcept { _M_type = __t; }
139 explicit operator bool()
const noexcept
140 {
return _M_type != _Type::_None; }
143 _GLIBCXX_NODISCARD
bool
144 _M_is_char()
const noexcept {
return _M_type == _Type::_Char; }
148 _GLIBCXX_NODISCARD
bool
149 _M_is_class()
const noexcept {
return _M_type == _Type::_Class; }
152 template<
bool __icase,
bool __collate>
159 template<
bool __icase,
bool __collate>
161 _M_expression_term(_BracketState& __last_char,
165 _M_cur_int_value(
int __radix);
173 auto ret = _M_stack.
top();
181 using namespace regex_constants;
182 switch (__f & (ECMAScript|basic|extended|awk|grep|egrep))
192 return __f | ECMAScript;
194 std::__throw_regex_error(_S_grammar,
"conflicting grammar options");
199 _ScannerT _M_scanner;
203 const _TraitsT& _M_traits;
208 template<
typename _TraitsT,
bool __icase,
bool __collate>
209 class _RegexTranslatorBase
212 typedef typename _TraitsT::char_type _CharT;
213 typedef typename _TraitsT::string_type _StringT;
214 typedef _StringT _StrTransT;
217 _RegexTranslatorBase(
const _TraitsT& __traits)
218 : _M_traits(__traits)
222 _M_translate(_CharT __ch)
const
225 return _M_traits.translate_nocase(__ch);
227 return _M_traits.translate(__ch);
233 _M_transform(_CharT __ch)
const
235 _StrTransT __str(1, __ch);
236 return _M_traits.transform(__str.begin(), __str.end());
243 _M_match_range(
const _StrTransT& __first,
const _StrTransT& __last,
244 const _StrTransT& __s)
const
245 {
return __first <= __s && __s <= __last; }
248 bool _M_in_range_icase(_CharT __first, _CharT __last, _CharT __ch)
const
251 const auto& __fctyp = use_facet<__ctype_type>(this->_M_traits.getloc());
252 auto __lower = __fctyp.tolower(__ch);
253 auto __upper = __fctyp.toupper(__ch);
254 return (__first <= __lower && __lower <= __last)
255 || (__first <= __upper && __upper <= __last);
258 const _TraitsT& _M_traits;
261 template<
typename _TraitsT,
bool __icase,
bool __collate>
262 class _RegexTranslator
263 :
public _RegexTranslatorBase<_TraitsT, __icase, __collate>
266 typedef _RegexTranslatorBase<_TraitsT, __icase, __collate> _Base;
270 template<
typename _TraitsT,
bool __icase>
271 class _RegexTranslator<_TraitsT, __icase, false>
272 :
public _RegexTranslatorBase<_TraitsT, __icase, false>
275 typedef _RegexTranslatorBase<_TraitsT, __icase, false> _Base;
276 typedef typename _Base::_CharT _CharT;
277 typedef _CharT _StrTransT;
282 _M_transform(_CharT __ch)
const
286 _M_match_range(_CharT __first, _CharT __last, _CharT __ch)
const
289 return __first <= __ch && __ch <= __last;
290 return this->_M_in_range_icase(__first, __last, __ch);
294 template<
typename _CharType>
295 class _RegexTranslator<
std::regex_traits<_CharType>, true, true>
296 :
public _RegexTranslatorBase<std::regex_traits<_CharType>, true, true>
299 typedef _RegexTranslatorBase<std::regex_traits<_CharType>,
true,
true>
301 typedef typename _Base::_CharT _CharT;
302 typedef typename _Base::_StrTransT _StrTransT;
307 _M_match_range(
const _StrTransT& __first,
const _StrTransT& __last,
308 const _StrTransT& __str)
const
310 __glibcxx_assert(__first.size() == 1);
311 __glibcxx_assert(__last.size() == 1);
312 __glibcxx_assert(__str.size() == 1);
313 return this->_M_in_range_icase(__first[0], __last[0], __str[0]);
317 template<
typename _TraitsT>
318 class _RegexTranslator<_TraitsT, false, false>
321 typedef typename _TraitsT::char_type _CharT;
322 typedef _CharT _StrTransT;
325 _RegexTranslator(
const _TraitsT&)
329 _M_translate(_CharT __ch)
const
333 _M_transform(_CharT __ch)
const
337 _M_match_range(_CharT __first, _CharT __last, _CharT __ch)
const
338 {
return __first <= __ch && __ch <= __last; }
341 template<
typename _TraitsT,
bool __is_ecma,
bool __icase,
bool __collate>
344 template<
typename _TraitsT,
bool __icase,
bool __collate>
345 struct _AnyMatcher<_TraitsT, false, __icase, __collate>
347 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
348 typedef typename _TransT::_CharT _CharT;
351 _AnyMatcher(
const _TraitsT& __traits)
352 : _M_translator(__traits)
356 operator()(_CharT __ch)
const
358 static auto __nul = _M_translator._M_translate(
'\0');
359 return _M_translator._M_translate(__ch) != __nul;
362 _TransT _M_translator;
365 template<
typename _TraitsT,
bool __icase,
bool __collate>
366 struct _AnyMatcher<_TraitsT, true, __icase, __collate>
368 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
369 typedef typename _TransT::_CharT _CharT;
372 _AnyMatcher(
const _TraitsT& __traits)
373 : _M_translator(__traits)
377 operator()(_CharT __ch)
const
378 {
return _M_apply(__ch,
typename is_same<_CharT, char>::type()); }
383 auto __c = _M_translator._M_translate(__ch);
384 auto __n = _M_translator._M_translate(
'\n');
385 auto __r = _M_translator._M_translate(
'\r');
386 return __c != __n && __c != __r;
392 auto __c = _M_translator._M_translate(__ch);
393 auto __n = _M_translator._M_translate(
'\n');
394 auto __r = _M_translator._M_translate(
'\r');
395 auto __u2028 = _M_translator._M_translate(u
'\u2028');
396 auto __u2029 = _M_translator._M_translate(u
'\u2029');
397 return __c != __n && __c != __r && __c != __u2028 && __c != __u2029;
400 _TransT _M_translator;
403 template<
typename _TraitsT,
bool __icase,
bool __collate>
406 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
407 typedef typename _TransT::_CharT _CharT;
409 _CharMatcher(_CharT __ch,
const _TraitsT& __traits)
410 : _M_translator(__traits), _M_ch(_M_translator._M_translate(__ch))
414 operator()(_CharT __ch)
const
415 {
return _M_ch == _M_translator._M_translate(__ch); }
417 _TransT _M_translator;
422 template<
typename _TraitsT,
bool __icase,
bool __collate>
426 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
427 typedef typename _TransT::_CharT _CharT;
428 typedef typename _TransT::_StrTransT _StrTransT;
429 typedef typename _TraitsT::string_type _StringT;
430 typedef typename _TraitsT::char_class_type _CharClassT;
434 const _TraitsT& __traits)
435 : _M_class_set(0), _M_translator(__traits), _M_traits(__traits),
436 _M_is_non_matching(__is_non_matching)
440 operator()(_CharT __ch)
const
442 _GLIBCXX_DEBUG_ASSERT(_M_is_ready);
447 _M_add_char(_CharT __c)
449 _M_char_set.
push_back(_M_translator._M_translate(__c));
450 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
454 _M_add_collate_element(
const _StringT& __s)
456 auto __st = _M_traits.lookup_collatename(__s.data(),
457 __s.data() + __s.size());
460 "Invalid collate element.");
461 _M_char_set.
push_back(_M_translator._M_translate(__st[0]));
462 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
467 _M_add_equivalence_class(
const _StringT& __s)
469 auto __st = _M_traits.lookup_collatename(__s.data(),
470 __s.data() + __s.size());
473 "Invalid equivalence class.");
474 __st = _M_traits.transform_primary(__st.data(),
475 __st.data() + __st.size());
477 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
482 _M_add_character_class(
const _StringT& __s,
bool __neg)
484 auto __mask = _M_traits.lookup_classname(__s.data(),
485 __s.data() + __s.size(),
489 "Invalid character class.");
491 _M_class_set |= __mask;
494 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
498 _M_make_range(_CharT __l, _CharT __r)
502 "Invalid range in bracket expression.");
503 _M_range_set.push_back(make_pair(_M_translator._M_transform(__l),
504 _M_translator._M_transform(__r)));
505 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
511 std::sort(_M_char_set.
begin(), _M_char_set.
end());
512 auto __end = std::unique(_M_char_set.
begin(), _M_char_set.
end());
513 _M_char_set.
erase(__end, _M_char_set.
end());
515 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
true);
522 static constexpr size_t
524 1ul << (
sizeof(_CharT) * __CHAR_BIT__ *
int(_UseCache::value));
530 typedef typename std::make_unsigned<_CharT>::type _UnsignedCharT;
537 {
return _M_cache[
static_cast<_UnsignedCharT
>(__ch)]; }
542 for (
unsigned __i = 0; __i < _M_cache.
size(); __i++)
543 _M_cache[__i] = _M_apply(
static_cast<_CharT
>(__i),
false_type());
555 _CharClassT _M_class_set;
556 _TransT _M_translator;
557 const _TraitsT& _M_traits;
558 bool _M_is_non_matching;
561 bool _M_is_ready =
false;
567_GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
ISO C++ entities toplevel namespace is std.
constexpr error_type error_range(_S_error_range)
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
constexpr error_type error_collate(_S_error_collate)
The bitset class represents a fixed-size sequence of bits.
constexpr size_t size() const noexcept
Returns the total number of bits.
Define a member typedef type to one of two argument types.
Primary class template ctype facet.
Describes a sequence of one or more _State, its current start and end(s). This structure contains fra...
Matches a character range (bracket expression)
Builds an NFA from an input iterator range.
Scans an input range for regex tokens.
A smart pointer with reference-counted copy semantics.
A standard container made up of unique keys, which can be retrieved in logarithmic time.
A standard container giving FILO behavior.
void pop()
Removes first element.
A standard container which offers fixed time access to individual elements in any order.
iterator erase(const_iterator __position)
Remove element at given position.
void push_back(const value_type &__x)
Add data to the end of the vector.
iterator begin() noexcept