[cfe-commits] [libcxx] r109126 - in /libcxx/trunk: include/regex test/re/re.alg/re.alg.search/extended.pass.cpp
Howard Hinnant
hhinnant at apple.com
Thu Jul 22 10:53:24 PDT 2010
Author: hhinnant
Date: Thu Jul 22 12:53:24 2010
New Revision: 109126
URL: http://llvm.org/viewvc/llvm-project?rev=109126&view=rev
Log:
I believe posix extended expr is feature complete. Getting started on ecma exprs.
Modified:
libcxx/trunk/include/regex
libcxx/trunk/test/re/re.alg/re.alg.search/extended.pass.cpp
Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=109126&r1=109125&r2=109126&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Thu Jul 22 12:53:24 2010
@@ -2504,6 +2504,24 @@
template <class _ForwardIterator>
_ForwardIterator
__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
+ template <class _ForwardIterator>
+ _ForwardIterator
+ __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
+ template <class _ForwardIterator>
+ _ForwardIterator
+ __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
+ template <class _ForwardIterator>
+ _ForwardIterator
+ __parse_term(_ForwardIterator __first, _ForwardIterator __last);
+ template <class _ForwardIterator>
+ _ForwardIterator
+ __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
+ template <class _ForwardIterator>
+ _ForwardIterator
+ __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
+ template <class _ForwardIterator>
+ _ForwardIterator
+ __parse_quantifier(_ForwardIterator __first, _ForwardIterator __last) {} // temp!
void __push_l_anchor() {__left_anchor_ = true;}
void __push_r_anchor();
@@ -2522,6 +2540,12 @@
__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 <class _Allocator>
bool
@@ -2619,6 +2643,7 @@
switch (__flags_ & 0x3F0)
{
case ECMAScript:
+ __parse_ecma_exp(__first, __last);
break;
case basic:
__parse_basic_reg_exp(__first, __last);
@@ -3464,6 +3489,141 @@
}
template <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_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 <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_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 <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_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 <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_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 <class _CharT, class _Traits>
+template <class _ForwardIterator>
+_ForwardIterator
+basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
+ _ForwardIterator __last)
+{
+ return __first; // temp!
+}
+
+template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
__owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
@@ -3540,6 +3700,14 @@
template <class _CharT, class _Traits>
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 <class _CharT, class _Traits>
+void
basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
{
if (flags() & icase)
Modified: libcxx/trunk/test/re/re.alg/re.alg.search/extended.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.alg/re.alg.search/extended.pass.cpp?rev=109126&r1=109125&r2=109126&view=diff
==============================================================================
--- libcxx/trunk/test/re/re.alg/re.alg.search/extended.pass.cpp (original)
+++ libcxx/trunk/test/re/re.alg/re.alg.search/extended.pass.cpp Thu Jul 22 12:53:24 2010
@@ -477,4 +477,1029 @@
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<char>::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<char>::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<char>::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<char>::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<char>::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<char>::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<char>::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<char>::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<char>::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<char>::length(r);
+ typedef forward_iterator<const char*> FI;
+ typedef bidirectional_iterator<const char*> BI;
+ std::regex regex(FI(r), FI(r+sr), std::regex_constants::extended);
+ std::match_results<BI> m;
+ const char s[] = "-40C";
+ std::ptrdiff_t ss = std::char_traits<char>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::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<wchar_t>::length(r);
+ typedef forward_iterator<const wchar_t*> FI;
+ typedef bidirectional_iterator<const wchar_t*> BI;
+ std::wregex regex(FI(r), FI(r+sr), std::regex_constants::extended);
+ std::match_results<BI> m;
+ const wchar_t s[] = L"-40C";
+ std::ptrdiff_t ss = std::char_traits<wchar_t>::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);
+ }
}
More information about the cfe-commits
mailing list