From f7109438ea0f742fc39a6d7ba4dfa8ae7336b174 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 22 Jul 2010 17:53:24 +0000 Subject: [PATCH] I believe posix extended expr is feature complete. Getting started on ecma exprs. llvm-svn: 109126 --- libcxx/include/regex | 168 +++ .../re/re.alg/re.alg.search/extended.pass.cpp | 1025 +++++++++++++++++ 2 files changed, 1193 insertions(+) diff --git a/libcxx/include/regex b/libcxx/include/regex index fef35949c034..c2d6a51ade12 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -2504,6 +2504,24 @@ private: template _ForwardIterator __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); + template + _ForwardIterator + __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); + template + _ForwardIterator + __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); + template + _ForwardIterator + __parse_term(_ForwardIterator __first, _ForwardIterator __last); + template + _ForwardIterator + __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); + template + _ForwardIterator + __parse_atom(_ForwardIterator __first, _ForwardIterator __last); + template + _ForwardIterator + __parse_quantifier(_ForwardIterator __first, _ForwardIterator __last) {} // temp! void __push_l_anchor() {__left_anchor_ = true;} void __push_r_anchor(); @@ -2522,6 +2540,12 @@ private: __owns_one_state<_CharT>* __sb); void __push_begin_marked_subexpression(); void __push_end_marked_subexpression(unsigned); + void __push_empty(); + void __push_word_boundary(bool) {} + void __push_start_pos_lookahead() {} + void __push_end_pos_lookahead() {} + void __push_start_neg_lookahead() {} + void __push_end_neg_lookahead() {} template bool @@ -2619,6 +2643,7 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, switch (__flags_ & 0x3F0) { case ECMAScript: + __parse_ecma_exp(__first, __last); break; case basic: __parse_basic_reg_exp(__first, __last); @@ -3463,6 +3488,141 @@ basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, return __first; } +template +template +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, + _ForwardIterator __last) +{ + __owns_one_state<_CharT>* __sa = __end_; + _ForwardIterator __temp = __parse_alternative(__first, __last); + if (__temp == __first) + __push_empty(); + __first = __temp; + while (__first != __last && *__first == '|') + { + __owns_one_state<_CharT>* __sb = __end_; + __temp = __parse_alternative(++__first, __last); + if (__temp == __first) + __push_empty(); + __push_alternation(__sa, __sb); + __first = __temp; + } + return __first; +} + +template +template +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, + _ForwardIterator __last) +{ + while (true) + { + _ForwardIterator __temp = __parse_term(__first, __last); + if (__temp == __first) + break; + __first = __temp; + } + return __first; +} + +template +template +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, + _ForwardIterator __last) +{ + _ForwardIterator __temp = __parse_assertion(__first, __last); + if (__temp == __first) + { + __temp = __parse_atom(__first, __last); + if (__temp != __first) + __first = __parse_quantifier(__temp, __last); + } + return __first; +} + +template +template +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, + _ForwardIterator __last) +{ + if (__first != __last) + { + switch (*__first) + { + case '^': + __push_l_anchor(); + ++__first; + break; + case '$': + __push_r_anchor(); + ++__first; + break; + case '\\': + { + _ForwardIterator __temp = _STD::next(__first); + if (__temp != __last) + { + if (*__temp == 'b') + { + __push_word_boundary(true); + __first = ++__temp; + } + else if (*__temp == 'B') + { + __push_word_boundary(false); + __first = ++__temp; + } + } + } + break; + case '(': + { + _ForwardIterator __temp = _STD::next(__first); + if (__temp != __last && *__temp == '?') + { + if (++__temp != __last) + { + switch (*__temp) + { + case '=': + __push_start_pos_lookahead(); + __temp = __parse_ecma_exp(++__temp, __last); + if (__temp == __last || *__temp != ')') + throw regex_error(regex_constants::error_paren); + __push_end_pos_lookahead(); + __first = ++__temp; + break; + case '!': + __push_start_neg_lookahead(); + __temp = __parse_ecma_exp(++__temp, __last); + if (__temp == __last || *__temp != ')') + throw regex_error(regex_constants::error_paren); + __push_end_neg_lookahead(); + __first = ++__temp; + break; + } + } + } + } + break; + } + } + return __first; +} + +template +template +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, + _ForwardIterator __last) +{ + return __first; // temp! +} + template void basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, @@ -3538,6 +3698,14 @@ basic_regex<_CharT, _Traits>::__push_match_any() __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); } +template +void +basic_regex<_CharT, _Traits>::__push_empty() +{ + __end_->first() = new __empty_state<_CharT>(__end_->first()); + __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); +} + template void basic_regex<_CharT, _Traits>::__push_back_ref(int __i) diff --git a/libcxx/test/re/re.alg/re.alg.search/extended.pass.cpp b/libcxx/test/re/re.alg/re.alg.search/extended.pass.cpp index 4829b711bf26..a5a3ccef4c40 100644 --- a/libcxx/test/re/re.alg/re.alg.search/extended.pass.cpp +++ b/libcxx/test/re/re.alg/re.alg.search/extended.pass.cpp @@ -477,4 +477,1029 @@ int main() assert(m.position(1) == 3); assert(m.str(1) == "tour"); } + { + std::cmatch m; + const char s[] = "-ab,ab-"; + assert(!std::regex_search(s, m, std::regex("-(.*),\1-", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "-ab,ab-"; + assert(std::regex_search(s, m, std::regex("-.*,.*-", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "a"; + assert(std::regex_search(s, m, std::regex("^[a]$", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 1); + assert(m.position(0) == 0); + assert(m.str(0) == "a"); + } + { + std::cmatch m; + const char s[] = "a"; + assert(std::regex_search(s, m, std::regex("^[ab]$", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 1); + assert(m.position(0) == 0); + assert(m.str(0) == "a"); + } + { + std::cmatch m; + const char s[] = "c"; + assert(std::regex_search(s, m, std::regex("^[a-f]$", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 1); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "g"; + assert(!std::regex_search(s, m, std::regex("^[a-f]$", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "Iraqi"; + assert(std::regex_search(s, m, std::regex("q[^u]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 2); + assert(m.position(0) == 3); + assert(m.str(0) == "qi"); + } + { + std::cmatch m; + const char s[] = "Iraq"; + assert(!std::regex_search(s, m, std::regex("q[^u]", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "AmB"; + assert(std::regex_search(s, m, std::regex("A[[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "AMB"; + assert(!std::regex_search(s, m, std::regex("A[[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "AMB"; + assert(std::regex_search(s, m, std::regex("A[^[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "AmB"; + assert(!std::regex_search(s, m, std::regex("A[^[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "A5B"; + assert(!std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "A?B"; + assert(std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "-"; + assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "z"; + assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "m"; + assert(!std::regex_search(s, m, std::regex("[a[.hyphen.]z]", + std::regex_constants::extended))); + assert(m.size() == 0); + } + std::locale::global(std::locale("cs_CZ.ISO8859-2")); + { + std::cmatch m; + const char s[] = "m"; + assert(std::regex_search(s, m, std::regex("[a[=M=]z]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::cmatch m; + const char s[] = "Ch"; + assert(std::regex_search(s, m, std::regex("[a[.ch.]z]", + std::regex_constants::extended | std::regex_constants::icase))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + std::locale::global(std::locale("C")); + { + std::cmatch m; + const char s[] = "m"; + assert(!std::regex_search(s, m, std::regex("[a[=M=]z]", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "01a45cef9"; + assert(std::regex_search(s, m, std::regex("[ace1-9]*", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s + std::char_traits::length(s)); + assert(m.length(0) == 6); + assert(m.position(0) == 1); + assert(m.str(0) == "1a45ce"); + } + { + const char r[] = "^[-+]?[0-9]+[CF]$"; + std::ptrdiff_t sr = std::char_traits::length(r); + typedef forward_iterator FI; + typedef bidirectional_iterator BI; + std::regex regex(FI(r), FI(r+sr), std::regex_constants::extended); + std::match_results m; + const char s[] = "-40C"; + std::ptrdiff_t ss = std::char_traits::length(s); + assert(std::regex_search(BI(s), BI(s+ss), m, regex)); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == BI(s)); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 4); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + + { + std::wcmatch m; + const wchar_t s[] = L"a"; + assert(std::regex_search(s, m, std::wregex(L"a", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.empty()); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+1); + assert(m.length(0) == 1); + assert(m.position(0) == 0); + assert(m.str(0) == L"a"); + } + { + std::wcmatch m; + const wchar_t s[] = L"ab"; + assert(std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+2); + assert(m.length(0) == 2); + assert(m.position(0) == 0); + assert(m.str(0) == L"ab"); + } + { + std::wcmatch m; + const wchar_t s[] = L"ab"; + assert(!std::regex_search(s, m, std::wregex(L"ba", std::regex_constants::extended))); + assert(m.size() == 0); + assert(m.empty()); + } + { + std::wcmatch m; + const wchar_t s[] = L"aab"; + assert(std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::extended))); + assert(m.size() == 1); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+3); + assert(m.length(0) == 2); + assert(m.position(0) == 1); + assert(m.str(0) == L"ab"); + } + { + std::wcmatch m; + const wchar_t s[] = L"aab"; + assert(!std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::extended), + std::regex_constants::match_continuous)); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"abcd"; + assert(std::regex_search(s, m, std::wregex(L"bc", std::regex_constants::extended))); + assert(m.size() == 1); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+4); + assert(m.length(0) == 2); + assert(m.position(0) == 1); + assert(m.str(0) == L"bc"); + } + { + std::wcmatch m; + const wchar_t s[] = L"abbc"; + assert(std::regex_search(s, m, std::wregex(L"ab*c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+4); + assert(m.length(0) == 4); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"ababc"; + assert(std::regex_search(s, m, std::wregex(L"(ab)*c", std::regex_constants::extended))); + assert(m.size() == 2); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+5); + assert(m.length(0) == 5); + assert(m.position(0) == 0); + assert(m.str(0) == s); + assert(m.length(1) == 2); + assert(m.position(1) == 2); + assert(m.str(1) == L"ab"); + } + { + std::wcmatch m; + const wchar_t s[] = L"abcdefghijk"; + assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi", + std::regex_constants::extended))); + assert(m.size() == 3); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+std::regex_traits::length(s)); + assert(m.length(0) == 7); + assert(m.position(0) == 2); + assert(m.str(0) == L"cdefghi"); + assert(m.length(1) == 3); + assert(m.position(1) == 4); + assert(m.str(1) == L"efg"); + assert(m.length(2) == 1); + assert(m.position(2) == 4); + assert(m.str(2) == L"e"); + } + { + std::wcmatch m; + const wchar_t s[] = L"abc"; + assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+3); + assert(m.length(0) == 3); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"abcd"; + assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+4); + assert(m.length(0) == 3); + assert(m.position(0) == 0); + assert(m.str(0) == L"abc"); + } + { + std::wcmatch m; + const wchar_t s[] = L"aabc"; + assert(!std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"abc"; + assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+3); + assert(m.length(0) == 3); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"efabc"; + assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::extended))); + assert(m.size() == 1); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+5); + assert(m.length(0) == 3); + assert(m.position(0) == 2); + assert(m.str(0) == s+2); + } + { + std::wcmatch m; + const wchar_t s[] = L"efabcg"; + assert(!std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"abc"; + assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+3); + assert(m.length(0) == 3); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"acc"; + assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+3); + assert(m.length(0) == 3); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"acc"; + assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+3); + assert(m.length(0) == 3); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"abcdef"; + assert(std::regex_search(s, m, std::wregex(L"(.*).*", std::regex_constants::extended))); + assert(m.size() == 2); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+6); + assert(m.length(0) == 6); + assert(m.position(0) == 0); + assert(m.str(0) == s); + assert(m.length(1) == 6); + assert(m.position(1) == 0); + assert(m.str(1) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"bc"; + assert(std::regex_search(s, m, std::wregex(L"(a*)*", std::regex_constants::extended))); + assert(m.size() == 2); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s+2); + assert(m.length(0) == 0); + assert(m.position(0) == 0); + assert(m.str(0) == L""); + assert(m.length(1) == 0); + assert(m.position(1) == 0); + assert(m.str(1) == L""); + } + { + std::wcmatch m; + const wchar_t s[] = L"abbc"; + assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"abbbc"; + assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"abbbbc"; + assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"abbbbbc"; + assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"adefc"; + assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"abbbbbbc"; + assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"adec"; + assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"adefc"; + assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"adefgc"; + assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"adefghc"; + assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"adefghic"; + assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"tournament"; + assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"tournamenttotour"; + assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+", + std::regex_constants::extended | std::regex_constants::nosubs))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"ttotour"; + assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+", + std::regex_constants::extended))); + assert(m.size() == 2); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + assert(m.length(1) == 4); + assert(m.position(1) == 3); + assert(m.str(1) == L"tour"); + } + { + std::wcmatch m; + const wchar_t s[] = L"-ab,ab-"; + assert(!std::regex_search(s, m, std::wregex(L"-(.*),\1-", std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"-ab,ab-"; + assert(std::regex_search(s, m, std::wregex(L"-.*,.*-", std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"a"; + assert(std::regex_search(s, m, std::wregex(L"^[a]$", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 1); + assert(m.position(0) == 0); + assert(m.str(0) == L"a"); + } + { + std::wcmatch m; + const wchar_t s[] = L"a"; + assert(std::regex_search(s, m, std::wregex(L"^[ab]$", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 1); + assert(m.position(0) == 0); + assert(m.str(0) == L"a"); + } + { + std::wcmatch m; + const wchar_t s[] = L"c"; + assert(std::regex_search(s, m, std::wregex(L"^[a-f]$", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 1); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"g"; + assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"Iraqi"; + assert(std::regex_search(s, m, std::wregex(L"q[^u]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 2); + assert(m.position(0) == 3); + assert(m.str(0) == L"qi"); + } + { + std::wcmatch m; + const wchar_t s[] = L"Iraq"; + assert(!std::regex_search(s, m, std::wregex(L"q[^u]", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"AmB"; + assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"AMB"; + assert(!std::regex_search(s, m, std::wregex(L"A[[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"AMB"; + assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"AmB"; + assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"A5B"; + assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"A?B"; + assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"-"; + assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"z"; + assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"m"; + assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", + std::regex_constants::extended))); + assert(m.size() == 0); + } + std::locale::global(std::locale("cs_CZ.ISO8859-2")); + { + std::wcmatch m; + const wchar_t s[] = L"m"; + assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + { + std::wcmatch m; + const wchar_t s[] = L"Ch"; + assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]", + std::regex_constants::extended | std::regex_constants::icase))); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } + std::locale::global(std::locale("C")); + { + std::wcmatch m; + const wchar_t s[] = L"m"; + assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]", + std::regex_constants::extended))); + assert(m.size() == 0); + } + { + std::wcmatch m; + const wchar_t s[] = L"01a45cef9"; + assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*", + std::regex_constants::extended))); + assert(m.size() == 1); + assert(m.prefix().matched); + assert(m.prefix().first == s); + assert(m.prefix().second == m[0].first); + assert(m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == s + std::char_traits::length(s)); + assert(m.length(0) == 6); + assert(m.position(0) == 1); + assert(m.str(0) == L"1a45ce"); + } + { + const wchar_t r[] = L"^[-+]?[0-9]+[CF]$"; + std::ptrdiff_t sr = std::char_traits::length(r); + typedef forward_iterator FI; + typedef bidirectional_iterator BI; + std::wregex regex(FI(r), FI(r+sr), std::regex_constants::extended); + std::match_results m; + const wchar_t s[] = L"-40C"; + std::ptrdiff_t ss = std::char_traits::length(s); + assert(std::regex_search(BI(s), BI(s+ss), m, regex)); + assert(m.size() == 1); + assert(!m.prefix().matched); + assert(m.prefix().first == BI(s)); + assert(m.prefix().second == m[0].first); + assert(!m.suffix().matched); + assert(m.suffix().first == m[0].second); + assert(m.suffix().second == m[0].second); + assert(m.length(0) == 4); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } }