continued regex development...

llvm-svn: 109512
This commit is contained in:
Howard Hinnant 2010-07-27 17:24:17 +00:00
parent 7639967e6c
commit 6afe8b0a23
6 changed files with 203 additions and 145 deletions

View File

@ -747,12 +747,12 @@ enum syntax_option_type
nosubs = 1 << 1, nosubs = 1 << 1,
optimize = 1 << 2, optimize = 1 << 2,
collate = 1 << 3, collate = 1 << 3,
ECMAScript = 1 << 4, ECMAScript = 0,
basic = 1 << 5, basic = 1 << 4,
extended = 1 << 6, extended = 1 << 5,
awk = 1 << 7, awk = 1 << 6,
grep = 1 << 8, grep = 1 << 7,
egrep = 1 << 9 egrep = 1 << 8
}; };
inline inline
@ -907,7 +907,9 @@ enum error_type
error_badrepeat, error_badrepeat,
error_complexity, error_complexity,
error_stack, error_stack,
error_temp __re_err_grammar,
__re_err_empty,
__re_err_unknown
}; };
} // regex_constants } // regex_constants
@ -1538,8 +1540,17 @@ __loop<_CharT>::__exec(__state& __s) const
} }
else else
{ {
if (__max_ > 0) __s.__loop_data_[__loop_id_].first = 0;
bool __do_repeat = 0 < __max_;
bool __do_alt = 0 >= __min_;
if (__do_repeat && __do_alt)
__s.__do_ = __state::__split; __s.__do_ = __state::__split;
else if (__do_repeat)
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
__init_repeat(__s);
}
else else
{ {
__s.__do_ = __state::__accept_but_not_consume; __s.__do_ = __state::__accept_but_not_consume;
@ -2727,7 +2738,6 @@ private:
bool bool
__match_at_start(const _CharT* __first, const _CharT* __last, __match_at_start(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m, match_results<const _CharT*, _Allocator>& __m,
vector<size_t>& __lc,
regex_constants::match_flag_type __flags) const; regex_constants::match_flag_type __flags) const;
template <class _Allocator> template <class _Allocator>
bool bool
@ -2738,13 +2748,11 @@ private:
bool bool
__match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m, match_results<const _CharT*, _Allocator>& __m,
vector<size_t>& __lc,
regex_constants::match_flag_type __flags) const; regex_constants::match_flag_type __flags) const;
template <class _Allocator> template <class _Allocator>
bool bool
__match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m, match_results<const _CharT*, _Allocator>& __m,
vector<size_t>& __lc,
regex_constants::match_flag_type __flags) const; regex_constants::match_flag_type __flags) const;
template <class _B, class _A, class _C, class _T> template <class _B, class _A, class _C, class _T>
@ -2810,7 +2818,7 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
__h.release(); __h.release();
__end_ = __start_.get(); __end_ = __start_.get();
} }
switch (__flags_ & 0x3F0) switch (__flags_ & 0x1F0)
{ {
case ECMAScript: case ECMAScript:
__parse_ecma_exp(__first, __last); __parse_ecma_exp(__first, __last);
@ -2828,7 +2836,7 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
case egrep: case egrep:
break; break;
default: default:
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_grammar);
} }
} }
@ -2859,7 +2867,7 @@ basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
} }
} }
if (__first != __last) if (__first != __last)
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_empty);
} }
return __first; return __first;
} }
@ -2873,14 +2881,14 @@ basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
__owns_one_state<_CharT>* __sa = __end_; __owns_one_state<_CharT>* __sa = __end_;
_ForwardIterator __temp = __parse_ERE_branch(__first, __last); _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
if (__temp == __first) if (__temp == __first)
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_empty);
__first = __temp; __first = __temp;
while (__first != __last && *__first == '|') while (__first != __last && *__first == '|')
{ {
__owns_one_state<_CharT>* __sb = __end_; __owns_one_state<_CharT>* __sb = __end_;
__temp = __parse_ERE_branch(++__first, __last); __temp = __parse_ERE_branch(++__first, __last);
if (__temp == __first) if (__temp == __first)
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_empty);
__push_alternation(__sa, __sb); __push_alternation(__sa, __sb);
__first = __temp; __first = __temp;
} }
@ -2895,7 +2903,7 @@ basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
{ {
_ForwardIterator __temp = __parse_ERE_expression(__first, __last); _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
if (__temp == __first) if (__temp == __first)
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_empty);
do do
{ {
__first = __temp; __first = __temp;
@ -4879,7 +4887,7 @@ basic_regex<_CharT, _Traits>::__match_at_start_ecma(
__states.pop_back(); __states.pop_back();
break; break;
default: default:
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_unknown);
break; break;
} }
} while (!__states.empty()); } while (!__states.empty());
@ -4893,7 +4901,6 @@ bool
basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
const _CharT* __first, const _CharT* __last, const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m, match_results<const _CharT*, _Allocator>& __m,
vector<size_t>& __lc,
regex_constants::match_flag_type __flags) const regex_constants::match_flag_type __flags) const
{ {
deque<__state> __states; deque<__state> __states;
@ -4919,11 +4926,9 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
switch (__s.__do_) switch (__s.__do_)
{ {
case __state::__end_state: case __state::__end_state:
if (__highest_j < __s.__current_ - __s.__first_) if (!__matched || __highest_j < __s.__current_ - __s.__first_)
{
__highest_j = __s.__current_ - __s.__first_; __highest_j = __s.__current_ - __s.__first_;
__matched = true; __matched = true;
}
if (__highest_j == _N) if (__highest_j == _N)
__states.clear(); __states.clear();
else else
@ -4950,7 +4955,7 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
__states.pop_back(); __states.pop_back();
break; break;
default: default:
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_unknown);
break; break;
} }
} while (!__states.empty()); } while (!__states.empty());
@ -4971,7 +4976,6 @@ bool
basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
const _CharT* __first, const _CharT* __last, const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m, match_results<const _CharT*, _Allocator>& __m,
vector<size_t>& __lc,
regex_constants::match_flag_type __flags) const regex_constants::match_flag_type __flags) const
{ {
vector<__state> __states; vector<__state> __states;
@ -5001,16 +5005,16 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
switch (__s.__do_) switch (__s.__do_)
{ {
case __state::__end_state: case __state::__end_state:
if (__j == 0 || __highest_j < __j) if (!__matched || __highest_j < __s.__current_ - __s.__first_)
{ {
__matched = true; __highest_j = __s.__current_ - __s.__first_;
__highest_j = __j;
__best_state = __s; __best_state = __s;
if (__highest_j == _N || __highest_j == 0)
__states.clear();
else
__states.pop_back();
} }
__matched = true;
if (__highest_j == _N)
__states.clear();
else
__states.pop_back();
break; break;
case __state::__accept_and_consume: case __state::__accept_and_consume:
__j += __s.__current_ - __current; __j += __s.__current_ - __current;
@ -5031,7 +5035,7 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
__states.pop_back(); __states.pop_back();
break; break;
default: default:
throw regex_error(regex_constants::error_temp); throw regex_error(regex_constants::__re_err_unknown);
break; break;
} }
} while (!__states.empty()); } while (!__states.empty());
@ -5054,14 +5058,13 @@ bool
basic_regex<_CharT, _Traits>::__match_at_start( basic_regex<_CharT, _Traits>::__match_at_start(
const _CharT* __first, const _CharT* __last, const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m, match_results<const _CharT*, _Allocator>& __m,
vector<size_t>& __lc,
regex_constants::match_flag_type __flags) const regex_constants::match_flag_type __flags) const
{ {
if (__flags_ & ECMAScript) if ((__flags_ & 0x1F0) == ECMAScript)
return __match_at_start_ecma(__first, __last, __m, __flags); return __match_at_start_ecma(__first, __last, __m, __flags);
if (mark_count() == 0) if (mark_count() == 0)
return __match_at_start_posix_nosubs(__first, __last, __m, __lc, __flags); return __match_at_start_posix_nosubs(__first, __last, __m, __flags);
return __match_at_start_posix_subs(__first, __last, __m, __lc, __flags); return __match_at_start_posix_subs(__first, __last, __m, __flags);
} }
template <class _CharT, class _Traits> template <class _CharT, class _Traits>
@ -5075,8 +5078,7 @@ basic_regex<_CharT, _Traits>::__search(
if (__left_anchor_) if (__left_anchor_)
__flags |= regex_constants::match_continuous; __flags |= regex_constants::match_continuous;
__m.__init(1 + mark_count(), __first, __last); __m.__init(1 + mark_count(), __first, __last);
vector<size_t> __lc(__loop_count()); if (__match_at_start(__first, __last, __m, __flags))
if (__match_at_start(__first, __last, __m, __lc, __flags))
{ {
__m.__prefix_.second = __m[0].first; __m.__prefix_.second = __m[0].first;
__m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
@ -5089,7 +5091,7 @@ basic_regex<_CharT, _Traits>::__search(
__m.__matches_.assign(__m.size(), __m.__unmatched_); __m.__matches_.assign(__m.size(), __m.__unmatched_);
for (++__first; __first != __last; ++__first) for (++__first; __first != __last; ++__first)
{ {
if (__match_at_start(__first, __last, __m, __lc, __flags)) if (__match_at_start(__first, __last, __m, __flags))
{ {
__m.__prefix_.second = __m[0].first; __m.__prefix_.second = __m[0].first;
__m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;

View File

@ -50,6 +50,10 @@ make_error_type_string(regex_constants::error_type ecode)
case regex_constants::error_stack: case regex_constants::error_stack:
return "There was insufficient memory to determine whether the regular " return "There was insufficient memory to determine whether the regular "
"expression could match the specified character sequence."; "expression could match the specified character sequence.";
case regex_constants::__re_err_grammar:
return "An invalid regex grammar has been requested.";
case regex_constants::__re_err_empty:
return "An empty regex is not allowed in the POSIX grammar.";
default: default:
break; break;
} }

View File

@ -733,6 +733,22 @@ int main()
assert(std::regex_search(s, m, std::regex("[ace1-9]*", assert(std::regex_search(s, m, std::regex("[ace1-9]*",
std::regex_constants::basic))); std::regex_constants::basic)));
assert(m.size() == 1); 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) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == "");
}
{
std::cmatch m;
const char s[] = "01a45cef9";
assert(std::regex_search(s, m, std::regex("[ace1-9]\\{1,\\}",
std::regex_constants::basic)));
assert(m.size() == 1);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);
@ -1476,6 +1492,22 @@ int main()
assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*", assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*",
std::regex_constants::basic))); std::regex_constants::basic)));
assert(m.size() == 1); 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) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == L"");
}
{
std::wcmatch m;
const wchar_t s[] = L"01a45cef9";
assert(std::regex_search(s, m, std::wregex(L"[ace1-9]\\{1,\\}",
std::regex_constants::basic)));
assert(m.size() == 1);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);

View File

@ -134,8 +134,7 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "abcdefghijk"; const char s[] = "abcdefghijk";
assert(std::regex_search(s, m, std::regex("cd((e)fg)hi", assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
std::regex_constants::extended)));
assert(m.size() == 3); assert(m.size() == 3);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -429,40 +428,38 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "tournament"; const char s[] = "tournament";
assert(std::regex_search(s, m, std::regex("tour|to|tournament", assert(std::regex_search(s, m, std::regex("tour|to|tournament")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched); assert(m.suffix().matched);
assert(m.suffix().first == m[0].second); assert(m.suffix().first == m[0].second);
assert(m.suffix().second == m[0].second); assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == std::char_traits<char>::length(s)); assert(m.length(0) == 4);
assert(m.position(0) == 0); assert(m.position(0) == 0);
assert(m.str(0) == s); assert(m.str(0) == "tour");
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "tournamenttotour"; const char s[] = "tournamenttotour";
assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+", assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+",
std::regex_constants::extended | std::regex_constants::nosubs))); std::regex_constants::nosubs)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched); assert(m.suffix().matched);
assert(m.suffix().first == m[0].second); assert(m.suffix().first == m[0].second);
assert(m.suffix().second == m[0].second); assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == std::char_traits<char>::length(s)); assert(m.length(0) == 4);
assert(m.position(0) == 0); assert(m.position(0) == 0);
assert(m.str(0) == s); assert(m.str(0) == "tour");
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "ttotour"; const char s[] = "ttotour";
assert(std::regex_search(s, m, std::regex("(tour|to|t)+", assert(std::regex_search(s, m, std::regex("(tour|to|t)+")));
std::regex_constants::extended)));
assert(m.size() == 2); assert(m.size() == 2);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -501,8 +498,7 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "a"; const char s[] = "a";
assert(std::regex_search(s, m, std::regex("^[a]$", assert(std::regex_search(s, m, std::regex("^[a]$")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -517,8 +513,7 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "a"; const char s[] = "a";
assert(std::regex_search(s, m, std::regex("^[ab]$", assert(std::regex_search(s, m, std::regex("^[ab]$")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -533,8 +528,7 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "c"; const char s[] = "c";
assert(std::regex_search(s, m, std::regex("^[a-f]$", assert(std::regex_search(s, m, std::regex("^[a-f]$")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -549,15 +543,13 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "g"; const char s[] = "g";
assert(!std::regex_search(s, m, std::regex("^[a-f]$", assert(!std::regex_search(s, m, std::regex("^[a-f]$")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "Iraqi"; const char s[] = "Iraqi";
assert(std::regex_search(s, m, std::regex("q[^u]", assert(std::regex_search(s, m, std::regex("q[^u]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -572,15 +564,13 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "Iraq"; const char s[] = "Iraq";
assert(!std::regex_search(s, m, std::regex("q[^u]", assert(!std::regex_search(s, m, std::regex("q[^u]")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "AmB"; const char s[] = "AmB";
assert(std::regex_search(s, m, std::regex("A[[:lower:]]B", assert(std::regex_search(s, m, std::regex("A[[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -595,15 +585,13 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "AMB"; const char s[] = "AMB";
assert(!std::regex_search(s, m, std::regex("A[[:lower:]]B", assert(!std::regex_search(s, m, std::regex("A[[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "AMB"; const char s[] = "AMB";
assert(std::regex_search(s, m, std::regex("A[^[:lower:]]B", assert(std::regex_search(s, m, std::regex("A[^[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -618,22 +606,19 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "AmB"; const char s[] = "AmB";
assert(!std::regex_search(s, m, std::regex("A[^[:lower:]]B", assert(!std::regex_search(s, m, std::regex("A[^[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "A5B"; const char s[] = "A5B";
assert(!std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B", assert(!std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "A?B"; const char s[] = "A?B";
assert(std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B", assert(std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -648,8 +633,7 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "-"; const char s[] = "-";
assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]", assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -664,8 +648,7 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "z"; const char s[] = "z";
assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]", assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -680,16 +663,14 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "m"; const char s[] = "m";
assert(!std::regex_search(s, m, std::regex("[a[.hyphen.]z]", assert(!std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
std::locale::global(std::locale("cs_CZ.ISO8859-2")); std::locale::global(std::locale("cs_CZ.ISO8859-2"));
{ {
std::cmatch m; std::cmatch m;
const char s[] = "m"; const char s[] = "m";
assert(std::regex_search(s, m, std::regex("[a[=M=]z]", assert(std::regex_search(s, m, std::regex("[a[=M=]z]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -705,7 +686,7 @@ int main()
std::cmatch m; std::cmatch m;
const char s[] = "Ch"; const char s[] = "Ch";
assert(std::regex_search(s, m, std::regex("[a[.ch.]z]", assert(std::regex_search(s, m, std::regex("[a[.ch.]z]",
std::regex_constants::extended | std::regex_constants::icase))); std::regex_constants::icase)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -721,15 +702,28 @@ int main()
{ {
std::cmatch m; std::cmatch m;
const char s[] = "m"; const char s[] = "m";
assert(!std::regex_search(s, m, std::regex("[a[=M=]z]", assert(!std::regex_search(s, m, std::regex("[a[=M=]z]")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::cmatch m; std::cmatch m;
const char s[] = "01a45cef9"; const char s[] = "01a45cef9";
assert(std::regex_search(s, m, std::regex("[ace1-9]*", 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) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == "");
}
{
std::cmatch m;
const char s[] = "01a45cef9";
assert(std::regex_search(s, m, std::regex("[ace1-9]+")));
assert(m.size() == 1); assert(m.size() == 1);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -874,8 +868,7 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"abcdefghijk"; const wchar_t s[] = L"abcdefghijk";
assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi", assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
std::regex_constants::extended)));
assert(m.size() == 3); assert(m.size() == 3);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1169,40 +1162,38 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"tournament"; const wchar_t s[] = L"tournament";
assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament", assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched); assert(m.suffix().matched);
assert(m.suffix().first == m[0].second); assert(m.suffix().first == m[0].second);
assert(m.suffix().second == m[0].second); assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
assert(m.length(0) == std::char_traits<wchar_t>::length(s)); assert(m.length(0) == 4);
assert(m.position(0) == 0); assert(m.position(0) == 0);
assert(m.str(0) == s); assert(m.str(0) == L"tour");
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"tournamenttotour"; const wchar_t s[] = L"tournamenttotour";
assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+", assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+",
std::regex_constants::extended | std::regex_constants::nosubs))); std::regex_constants::nosubs)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched); assert(m.suffix().matched);
assert(m.suffix().first == m[0].second); assert(m.suffix().first == m[0].second);
assert(m.suffix().second == m[0].second); assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
assert(m.length(0) == std::char_traits<wchar_t>::length(s)); assert(m.length(0) == 4);
assert(m.position(0) == 0); assert(m.position(0) == 0);
assert(m.str(0) == s); assert(m.str(0) == L"tour");
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"ttotour"; const wchar_t s[] = L"ttotour";
assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+", assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+")));
std::regex_constants::extended)));
assert(m.size() == 2); assert(m.size() == 2);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1241,8 +1232,7 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"a"; const wchar_t s[] = L"a";
assert(std::regex_search(s, m, std::wregex(L"^[a]$", assert(std::regex_search(s, m, std::wregex(L"^[a]$")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1257,8 +1247,7 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"a"; const wchar_t s[] = L"a";
assert(std::regex_search(s, m, std::wregex(L"^[ab]$", assert(std::regex_search(s, m, std::wregex(L"^[ab]$")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1273,8 +1262,7 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"c"; const wchar_t s[] = L"c";
assert(std::regex_search(s, m, std::wregex(L"^[a-f]$", assert(std::regex_search(s, m, std::wregex(L"^[a-f]$")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1289,15 +1277,13 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"g"; const wchar_t s[] = L"g";
assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$", assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"Iraqi"; const wchar_t s[] = L"Iraqi";
assert(std::regex_search(s, m, std::wregex(L"q[^u]", assert(std::regex_search(s, m, std::wregex(L"q[^u]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1312,15 +1298,13 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"Iraq"; const wchar_t s[] = L"Iraq";
assert(!std::regex_search(s, m, std::wregex(L"q[^u]", assert(!std::regex_search(s, m, std::wregex(L"q[^u]")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"AmB"; const wchar_t s[] = L"AmB";
assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B", assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1335,15 +1319,13 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"AMB"; const wchar_t s[] = L"AMB";
assert(!std::regex_search(s, m, std::wregex(L"A[[:lower:]]B", assert(!std::regex_search(s, m, std::wregex(L"A[[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"AMB"; const wchar_t s[] = L"AMB";
assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1358,22 +1340,19 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"AmB"; const wchar_t s[] = L"AmB";
assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"A5B"; const wchar_t s[] = L"A5B";
assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B", assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"A?B"; const wchar_t s[] = L"A?B";
assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]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.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1388,8 +1367,7 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"-"; const wchar_t s[] = L"-";
assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1404,8 +1382,7 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"z"; const wchar_t s[] = L"z";
assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1420,16 +1397,14 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"m"; const wchar_t s[] = L"m";
assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
std::locale::global(std::locale("cs_CZ.ISO8859-2")); std::locale::global(std::locale("cs_CZ.ISO8859-2"));
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"m"; const wchar_t s[] = L"m";
assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]", assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
std::regex_constants::extended)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1445,7 +1420,7 @@ int main()
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"Ch"; const wchar_t s[] = L"Ch";
assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]", assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]",
std::regex_constants::extended | std::regex_constants::icase))); std::regex_constants::icase)));
assert(m.size() == 1); assert(m.size() == 1);
assert(!m.prefix().matched); assert(!m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
@ -1461,15 +1436,28 @@ int main()
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"m"; const wchar_t s[] = L"m";
assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]", assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
std::regex_constants::extended)));
assert(m.size() == 0); assert(m.size() == 0);
} }
{ {
std::wcmatch m; std::wcmatch m;
const wchar_t s[] = L"01a45cef9"; const wchar_t s[] = L"01a45cef9";
assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*", 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) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == L"");
}
{
std::wcmatch m;
const wchar_t s[] = L"01a45cef9";
assert(std::regex_search(s, m, std::wregex(L"[ace1-9]+")));
assert(m.size() == 1); assert(m.size() == 1);
assert(m.prefix().matched); assert(m.prefix().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);

View File

@ -731,6 +731,22 @@ int main()
assert(std::regex_search(s, m, std::regex("[ace1-9]*", assert(std::regex_search(s, m, std::regex("[ace1-9]*",
std::regex_constants::extended))); std::regex_constants::extended)));
assert(m.size() == 1); 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) == 0);
assert(m.position(0) == 0);
assert(m.str(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().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);
@ -1471,6 +1487,22 @@ int main()
assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*", assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*",
std::regex_constants::extended))); std::regex_constants::extended)));
assert(m.size() == 1); 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) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == L"");
}
{
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().matched);
assert(m.prefix().first == s); assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first); assert(m.prefix().second == m[0].first);

View File

@ -38,7 +38,7 @@ int main()
assert(std::regex_constants::nosubs != 0); assert(std::regex_constants::nosubs != 0);
assert(std::regex_constants::optimize != 0); assert(std::regex_constants::optimize != 0);
assert(std::regex_constants::collate != 0); assert(std::regex_constants::collate != 0);
assert(std::regex_constants::ECMAScript != 0); assert(std::regex_constants::ECMAScript == 0);
assert(std::regex_constants::basic != 0); assert(std::regex_constants::basic != 0);
assert(std::regex_constants::extended != 0); assert(std::regex_constants::extended != 0);
assert(std::regex_constants::awk != 0); assert(std::regex_constants::awk != 0);