31 namespace std _GLIBCXX_VISIBILITY(default)
33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
34 _GLIBCXX_BEGIN_NAMESPACE_CXX11
39 _GLIBCXX_END_NAMESPACE_CXX11
40 _GLIBCXX_END_NAMESPACE_VERSION
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 template<
typename,
bool,
bool>
59 template<
typename _TraitsT>
63 typedef typename _TraitsT::char_type _CharT;
64 typedef const _CharT* _IterT;
65 typedef _NFA<_TraitsT> _RegexT;
69 const typename _TraitsT::locale_type& __traits, _FlagT __flags);
73 {
return std::move(_M_nfa); }
77 typedef typename _TraitsT::string_type _StringT;
78 typedef typename _ScannerT::_TokenT _TokenT;
85 _M_match_token(_TokenT __token);
106 _M_bracket_expression();
108 template<
bool __icase,
bool __collate>
110 _M_insert_any_matcher_ecma();
112 template<
bool __icase,
bool __collate>
114 _M_insert_any_matcher_posix();
116 template<
bool __icase,
bool __collate>
118 _M_insert_char_matcher();
120 template<
bool __icase,
bool __collate>
122 _M_insert_character_class_matcher();
124 template<
bool __icase,
bool __collate>
126 _M_insert_bracket_matcher(
bool __neg);
130 template<
bool __icase,
bool __collate>
137 _M_cur_int_value(
int __radix);
145 auto ret = _M_stack.
top();
151 _ScannerT _M_scanner;
155 const _TraitsT& _M_traits;
156 const _CtypeT& _M_ctype;
159 template<
typename _Tp>
162 template<
typename _Ch,
typename _Tr,
typename _Alloc>
163 struct __has_contiguous_iter<std::
basic_string<_Ch, _Tr, _Alloc>>
167 template<
typename _Tp,
typename _Alloc>
168 struct __has_contiguous_iter<std::
vector<_Tp, _Alloc>>
172 template<
typename _Tp>
175 template<
typename _CharT>
178 template<
typename _Tp,
typename _Cont>
180 __is_contiguous_normal_iter<__gnu_cxx::__normal_iterator<_Tp, _Cont>>
184 template<
typename _Iter,
typename _TraitsT>
185 using __enable_if_contiguous_normal_iter
186 =
typename enable_if< __is_contiguous_normal_iter<_Iter>::value,
189 template<
typename _Iter,
typename _TraitsT>
190 using __disable_if_contiguous_normal_iter
191 =
typename enable_if< !__is_contiguous_normal_iter<_Iter>::value,
194 template<
typename _FwdIter,
typename _TraitsT>
195 inline __enable_if_contiguous_normal_iter<_FwdIter, _TraitsT>
196 __compile_nfa(_FwdIter __first, _FwdIter __last,
197 const typename _TraitsT::locale_type& __loc,
200 size_t __len = __last - __first;
203 return _Cmplr(__cfirst, __cfirst + __len, __loc, __flags)._M_get_nfa();
206 template<
typename _FwdIter,
typename _TraitsT>
207 inline __disable_if_contiguous_normal_iter<_FwdIter, _TraitsT>
208 __compile_nfa(_FwdIter __first, _FwdIter __last,
209 const typename _TraitsT::locale_type& __loc,
213 return __compile_nfa(__str.
data(), __str.
data() + __str.
size(), __loc,
218 template<
typename _TraitsT,
bool __icase,
bool __collate>
219 class _RegexTranslatorBase
222 typedef typename _TraitsT::char_type _CharT;
223 typedef typename _TraitsT::string_type _StringT;
224 typedef _StringT _StrTransT;
227 _RegexTranslatorBase(
const _TraitsT& __traits)
228 : _M_traits(__traits)
232 _M_translate(_CharT __ch)
const 235 return _M_traits.translate_nocase(__ch);
237 return _M_traits.translate(__ch);
243 _M_transform(_CharT __ch)
const 245 _StrTransT __str(1, __ch);
246 return _M_traits.transform(__str.begin(), __str.end());
253 _M_match_range(
const _StrTransT& __first,
const _StrTransT& __last,
254 const _StrTransT& __s)
const 255 {
return __first <= __s && __s <= __last; }
258 bool _M_in_range_icase(_CharT __first, _CharT __last, _CharT __ch)
const 261 const auto& __fctyp = use_facet<__ctype_type>(this->_M_traits.getloc());
262 auto __lower = __fctyp.
tolower(__ch);
263 auto __upper = __fctyp.toupper(__ch);
264 return (__first <= __lower && __lower <= __last)
265 || (__first <= __upper && __upper <= __last);
268 const _TraitsT& _M_traits;
271 template<
typename _TraitsT,
bool __icase,
bool __collate>
272 class _RegexTranslator
273 :
public _RegexTranslatorBase<_TraitsT, __icase, __collate>
276 typedef _RegexTranslatorBase<_TraitsT, __icase, __collate> _Base;
280 template<
typename _TraitsT,
bool __icase>
281 class _RegexTranslator<_TraitsT, __icase, false>
282 :
public _RegexTranslatorBase<_TraitsT, __icase, false>
285 typedef _RegexTranslatorBase<_TraitsT, __icase, false> _Base;
286 typedef typename _Base::_CharT _CharT;
287 typedef _CharT _StrTransT;
292 _M_transform(_CharT __ch)
const 296 _M_match_range(_CharT __first, _CharT __last, _CharT __ch)
const 299 return __first <= __ch && __ch <= __last;
300 return this->_M_in_range_icase(__first, __last, __ch);
304 template<
typename _CharType>
305 class _RegexTranslator<std::
regex_traits<_CharType>, true, true>
306 :
public _RegexTranslatorBase<std::regex_traits<_CharType>, true, true>
309 typedef _RegexTranslatorBase<std::regex_traits<_CharType>,
true,
true>
311 typedef typename _Base::_CharT _CharT;
312 typedef typename _Base::_StrTransT _StrTransT;
317 _M_match_range(
const _StrTransT& __first,
const _StrTransT& __last,
318 const _StrTransT& __str)
const 320 __glibcxx_assert(__first.size() == 1);
321 __glibcxx_assert(__last.size() == 1);
322 __glibcxx_assert(__str.size() == 1);
323 return this->_M_in_range_icase(__first[0], __last[0], __str[0]);
327 template<
typename _TraitsT>
328 class _RegexTranslator<_TraitsT, false, false>
331 typedef typename _TraitsT::char_type _CharT;
332 typedef _CharT _StrTransT;
335 _RegexTranslator(
const _TraitsT&)
339 _M_translate(_CharT __ch)
const 343 _M_transform(_CharT __ch)
const 347 _M_match_range(_CharT __first, _CharT __last, _CharT __ch)
const 348 {
return __first <= __ch && __ch <= __last; }
351 template<
typename _TraitsT,
bool __is_ecma,
bool __icase,
bool __collate>
354 template<
typename _TraitsT,
bool __icase,
bool __collate>
355 struct _AnyMatcher<_TraitsT, false, __icase, __collate>
357 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
358 typedef typename _TransT::_CharT _CharT;
361 _AnyMatcher(
const _TraitsT& __traits)
362 : _M_translator(__traits)
366 operator()(_CharT __ch)
const 368 static auto __nul = _M_translator._M_translate(
'\0');
369 return _M_translator._M_translate(__ch) != __nul;
372 _TransT _M_translator;
375 template<
typename _TraitsT,
bool __icase,
bool __collate>
376 struct _AnyMatcher<_TraitsT, true, __icase, __collate>
378 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
379 typedef typename _TransT::_CharT _CharT;
382 _AnyMatcher(
const _TraitsT& __traits)
383 : _M_translator(__traits)
387 operator()(_CharT __ch)
const 388 {
return _M_apply(__ch,
typename is_same<_CharT, char>::type()); }
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 return __c != __n && __c != __r;
402 auto __c = _M_translator._M_translate(__ch);
403 auto __n = _M_translator._M_translate(
'\n');
404 auto __r = _M_translator._M_translate(
'\r');
405 auto __u2028 = _M_translator._M_translate(u
'\u2028');
406 auto __u2029 = _M_translator._M_translate(u
'\u2029');
407 return __c != __n && __c != __r && __c != __u2028 && __c != __u2029;
410 _TransT _M_translator;
413 template<
typename _TraitsT,
bool __icase,
bool __collate>
416 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
417 typedef typename _TransT::_CharT _CharT;
419 _CharMatcher(_CharT __ch,
const _TraitsT& __traits)
420 : _M_translator(__traits), _M_ch(_M_translator._M_translate(__ch))
424 operator()(_CharT __ch)
const 425 {
return _M_ch == _M_translator._M_translate(__ch); }
427 _TransT _M_translator;
432 template<
typename _TraitsT,
bool __icase,
bool __collate>
436 typedef _RegexTranslator<_TraitsT, __icase, __collate> _TransT;
437 typedef typename _TransT::_CharT _CharT;
438 typedef typename _TransT::_StrTransT _StrTransT;
439 typedef typename _TraitsT::string_type _StringT;
440 typedef typename _TraitsT::char_class_type _CharClassT;
444 const _TraitsT& __traits)
445 : _M_class_set(0), _M_translator(__traits), _M_traits(__traits),
446 _M_is_non_matching(__is_non_matching)
450 operator()(_CharT __ch)
const 452 _GLIBCXX_DEBUG_ASSERT(_M_is_ready);
453 return _M_apply(__ch, _UseCache());
457 _M_add_char(_CharT __c)
459 _M_char_set.push_back(_M_translator._M_translate(__c));
460 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
464 _M_add_collate_element(
const _StringT& __s)
466 auto __st = _M_traits.lookup_collatename(__s.data(),
467 __s.data() + __s.size());
470 "Invalid collate element.");
471 _M_char_set.push_back(_M_translator._M_translate(__st[0]));
472 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
477 _M_add_equivalence_class(
const _StringT& __s)
479 auto __st = _M_traits.lookup_collatename(__s.data(),
480 __s.data() + __s.size());
483 "Invalid equivalence class.");
484 __st = _M_traits.transform_primary(__st.data(),
485 __st.data() + __st.size());
486 _M_equiv_set.push_back(__st);
487 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
492 _M_add_character_class(
const _StringT& __s,
bool __neg)
494 auto __mask = _M_traits.lookup_classname(__s.data(),
495 __s.data() + __s.size(),
499 "Invalid character class.");
501 _M_class_set |= __mask;
503 _M_neg_class_set.push_back(__mask);
504 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
508 _M_make_range(_CharT __l, _CharT __r)
512 "Invalid range in bracket expression.");
513 _M_range_set.push_back(
make_pair(_M_translator._M_transform(__l),
514 _M_translator._M_transform(__r)));
515 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
false);
521 std::sort(_M_char_set.begin(), _M_char_set.end());
522 auto __end =
std::unique(_M_char_set.begin(), _M_char_set.end());
523 _M_char_set.erase(__end, _M_char_set.end());
524 _M_make_cache(_UseCache());
525 _GLIBCXX_DEBUG_ONLY(_M_is_ready =
true);
530 typedef typename std::is_same<_CharT, char>::type _UseCache;
532 static constexpr
size_t 535 return 1ul << (
sizeof(_CharT) * __CHAR_BIT__ *
int(_UseCache::value));
539 typedef typename std::conditional<_UseCache::value,
541 _Dummy>::type _CacheT;
542 typedef typename std::make_unsigned<_CharT>::type _UnsignedCharT;
549 {
return _M_cache[
static_cast<_UnsignedCharT
>(__ch)]; }
554 for (
unsigned __i = 0; __i < _M_cache.size(); __i++)
555 _M_cache[__i] = _M_apply(static_cast<_CharT>(__i),
false_type());
567 _CharClassT _M_class_set;
568 _TransT _M_translator;
569 const _TraitsT& _M_traits;
570 bool _M_is_non_matching;
572 #ifdef _GLIBCXX_DEBUG 573 bool _M_is_ready =
false;
578 _GLIBCXX_END_NAMESPACE_VERSION
void pop()
Removes first element.
Describes a sequence of one or more _State, its current start and end(s). This structure contains fra...
Matches a character range (bracket expression)
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
Primary class template ctype facet.This template class defines classification and conversion function...
const _CharT * data() const noexcept
Return const pointer to contents.
Managing sequences of characters and character-like objects.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
A standard container which offers fixed time access to individual elements in any order...
Scans an input range for regex tokens.
_ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __binary_pred)
Remove consecutive values from a sequence using a predicate.
ISO C++ entities toplevel namespace is std.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
Sort the elements of a sequence using a predicate for comparison.
A smart pointer with reference-counted copy semantics.
constexpr error_type error_collate(_S_error_collate)
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Describes aspects of a regular expression.
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
Struct holding two objects of arbitrary type.
constexpr error_type error_range(_S_error_range)
The bitset class represents a fixed-size sequence of bits.(Note that bitset does not meet the formal ...
char_type tolower(char_type __c) const
Convert to lowercase.
Builds an NFA from an input iterator range.