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;
128 _CharT _M_char = _CharT();
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
224 if _GLIBCXX17_CONSTEXPR (__icase)
225 return _M_traits.translate_nocase(__ch);
226 else if _GLIBCXX17_CONSTEXPR (__collate)
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
288 if _GLIBCXX17_CONSTEXPR (!__icase)
289 return __first <= __ch && __ch <= __last;
291 return this->_M_in_range_icase(__first, __last, __ch);
295 template<
typename _CharType>
296 class _RegexTranslator<
std::regex_traits<_CharType>, true, true>
297 :
public _RegexTranslatorBase<std::regex_traits<_CharType>, true, true>
300 typedef _RegexTranslatorBase<std::regex_traits<_CharType>,
true,
true>
302 typedef typename _Base::_CharT _CharT;
303 typedef typename _Base::_StrTransT _StrTransT;
308 _M_match_range(
const _StrTransT& __first,
const _StrTransT& __last,
309 const _StrTransT& __str)
const
311 __glibcxx_assert(__first.size() == 1);
312 __glibcxx_assert(__last.size() == 1);
313 __glibcxx_assert(__str.size() == 1);
314 return this->_M_in_range_icase(__first[0], __last[0], __str[0]);
318 template<
typename _TraitsT>
319 class _RegexTranslator<_TraitsT, false, false>
322 typedef typename _TraitsT::char_type _CharT;
323 typedef _CharT _StrTransT;
326 _RegexTranslator(
const _TraitsT&)
330 _M_translate(_CharT __ch)
const
334 _M_transform(_CharT __ch)
const
338 _M_match_range(_CharT __first, _CharT __last, _CharT __ch)
const
339 {
return __first <= __ch && __ch <= __last; }
342 template<
typename _TraitsT,
bool __is_ecma,
bool __icase,
bool __collate>
345 template<
typename _TraitsT,
bool __icase,
bool __collate>
346 struct _AnyMatcher<_TraitsT, false, __icase, __collate>
348 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
349 typedef typename _TransT::_CharT _CharT;
352 _AnyMatcher(
const _TraitsT& __traits)
353 : _M_translator(__traits)
357 operator()(_CharT __ch)
const
359 static auto __nul = _M_translator._M_translate(
'\0');
360 return _M_translator._M_translate(__ch) != __nul;
363 _TransT _M_translator;
366 template<
typename _TraitsT,
bool __icase,
bool __collate>
367 struct _AnyMatcher<_TraitsT, true, __icase, __collate>
369 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
370 typedef typename _TransT::_CharT _CharT;
373 _AnyMatcher(
const _TraitsT& __traits)
374 : _M_translator(__traits)
378 operator()(_CharT __ch)
const
379 {
return _M_apply(__ch,
typename is_same<_CharT, char>::type()); }
384 auto __c = _M_translator._M_translate(__ch);
385 auto __n = _M_translator._M_translate(
'\n');
386 auto __r = _M_translator._M_translate(
'\r');
387 return __c != __n && __c != __r;
393 auto __c = _M_translator._M_translate(__ch);
394 auto __n = _M_translator._M_translate(
'\n');
395 auto __r = _M_translator._M_translate(
'\r');
396 auto __u2028 = _M_translator._M_translate(u
'\u2028');
397 auto __u2029 = _M_translator._M_translate(u
'\u2029');
398 return __c != __n && __c != __r && __c != __u2028 && __c != __u2029;
401 _TransT _M_translator;
404 template<
typename _TraitsT,
bool __icase,
bool __collate>
407 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
408 typedef typename _TransT::_CharT _CharT;
410 _CharMatcher(_CharT __ch,
const _TraitsT& __traits)
411 : _M_translator(__traits), _M_ch(_M_translator._M_translate(__ch))
415 operator()(_CharT __ch)
const
416 {
return _M_ch == _M_translator._M_translate(__ch); }
418 _TransT _M_translator;
423 template<
typename _TraitsT,
bool __icase,
bool __collate>
427 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
428 typedef typename _TransT::_CharT _CharT;
429 typedef typename _TransT::_StrTransT _StrTransT;
430 typedef typename _TraitsT::string_type _StringT;
431 typedef typename _TraitsT::char_class_type _CharClassT;
435 const _TraitsT& __traits)
436 : _M_class_set(0), _M_translator(__traits), _M_traits(__traits),
437 _M_is_non_matching(__is_non_matching)
441 operator()(_CharT __ch)
const
443 _GLIBCXX_DEBUG_ASSERT(_M_is_ready);
444 return _M_apply(__ch, _UseCache());
448 _M_add_char(_CharT __c)
450 _M_char_set.
push_back(_M_translator._M_translate(__c));
451 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
455 _M_add_collate_element(
const _StringT& __s)
457 auto __st = _M_traits.lookup_collatename(__s.data(),
458 __s.data() + __s.size());
461 "Invalid collate element.");
462 _M_char_set.
push_back(_M_translator._M_translate(__st[0]));
463 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
468 _M_add_equivalence_class(
const _StringT& __s)
470 auto __st = _M_traits.lookup_collatename(__s.data(),
471 __s.data() + __s.size());
474 "Invalid equivalence class.");
475 __st = _M_traits.transform_primary(__st.data(),
476 __st.data() + __st.size());
478 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
483 _M_add_character_class(
const _StringT& __s,
bool __neg)
485 auto __mask = _M_traits.lookup_classname(__s.data(),
486 __s.data() + __s.size(),
490 "Invalid character class.");
492 _M_class_set |= __mask;
495 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
499 _M_make_range(_CharT __l, _CharT __r)
503 "Invalid range in bracket expression.");
504 _M_range_set.push_back(make_pair(_M_translator._M_transform(__l),
505 _M_translator._M_transform(__r)));
506 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
512 std::sort(_M_char_set.
begin(), _M_char_set.
end());
513 auto __end = std::unique(_M_char_set.
begin(), _M_char_set.
end());
514 _M_char_set.
erase(__end, _M_char_set.
end());
515 _M_make_cache(_UseCache());
516 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
true);
523 static constexpr size_t
525 1ul << (
sizeof(_CharT) * __CHAR_BIT__ *
int(_UseCache::value));
528 using _CacheT = std::__conditional_t<_UseCache::value,
531 using _UnsignedCharT =
typename std::make_unsigned<_CharT>::type;
538 {
return _M_cache[
static_cast<_UnsignedCharT
>(__ch)]; }
543 for (
unsigned __i = 0; __i < _M_cache.size(); __i++)
544 _M_cache[__i] = _M_apply(
static_cast<_CharT
>(__i),
false_type());
552 _GLIBCXX_STD_C::vector<_CharT> _M_char_set;
553 _GLIBCXX_STD_C::vector<_StringT> _M_equiv_set;
554 _GLIBCXX_STD_C::vector<pair<_StrTransT, _StrTransT>> _M_range_set;
555 _GLIBCXX_STD_C::vector<_CharClassT> _M_neg_class_set;
556 _CharClassT _M_class_set;
557 _TransT _M_translator;
558 const _TraitsT& _M_traits;
559 bool _M_is_non_matching;
562 bool _M_is_ready =
false;
568_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.
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.
constexpr void push_back(const value_type &__x)
Add data to the end of the vector.
constexpr iterator end() noexcept
constexpr iterator begin() noexcept
constexpr iterator erase(const_iterator __position)
Remove element at given position.