diff --git a/include/regex b/include/regex index 14a0e4bc..0bafbcf6 100644 --- a/include/regex +++ b/include/regex @@ -2194,10 +2194,12 @@ class __bracket_expression _Traits __traits_; vector<_CharT> __chars_; + vector<_CharT> __neg_chars_; vector > __ranges_; vector > __digraphs_; vector __equivalences_; ctype_base::mask __mask_; + ctype_base::mask __neg_mask_; bool __negate_; bool __icase_; bool __collate_; @@ -2210,12 +2212,14 @@ public: __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, bool __negate, bool __icase, bool __collate) - : base(__s), __traits_(__traits), __mask_(), __negate_(__negate), - __icase_(__icase), __collate_(__collate), + : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), + __negate_(__negate), __icase_(__icase), __collate_(__collate), __might_have_digraph_(__traits_.getloc().name() != "C") {} virtual void __exec(__state&) const; + bool __negated() const {return __negate_;} + void __add_char(_CharT __c) { if (__icase_) @@ -2225,6 +2229,15 @@ public: else __chars_.push_back(__c); } + void __add_neg_char(_CharT __c) + { + if (__icase_) + __neg_chars_.push_back(__traits_.translate_nocase(__c)); + else if (__collate_) + __neg_chars_.push_back(__traits_.translate(__c)); + else + __neg_chars_.push_back(__c); + } void __add_range(string_type __b, string_type __e) { if (__collate_) @@ -2274,6 +2287,8 @@ public: {__equivalences_.push_back(__s);} void __add_class(ctype_base::mask __mask) {__mask_ |= __mask;} + void __add_neg_class(ctype_base::mask __mask) + {__neg_mask_ |= __mask;} virtual string speak() const { @@ -2353,6 +2368,12 @@ __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const __found = true; goto __exit; } + if (!__traits_.isctype(__ch2.first, __neg_mask_) && + !__traits_.isctype(__ch2.second, __neg_mask_)) + { + __found = true; + goto __exit; + } goto __exit; } } @@ -2371,6 +2392,17 @@ __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const goto __exit; } } + if (!__neg_chars_.empty()) + { + for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) + { + if (__ch == __neg_chars_[__i]) + goto __is_neg_char; + } + __found = true; + goto __exit; + } +__is_neg_char: if (!__ranges_.empty()) { string_type __s2 = __collate_ ? @@ -2398,7 +2430,15 @@ __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const } } if (__traits_.isctype(__ch, __mask_)) + { __found = true; + goto __exit; + } + if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) + { + __found = true; + goto __exit; + } } else __found = __negate_; // force reject @@ -2644,7 +2684,8 @@ private: __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); template _ForwardIterator - __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last); + __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, + basic_string<_CharT>* __str = nullptr); template _ForwardIterator __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); @@ -2654,6 +2695,15 @@ private: template _ForwardIterator __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); + template + _ForwardIterator + __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, + basic_string<_CharT>& __str, + __bracket_expression<_CharT, _Traits>* __ml); + template + _ForwardIterator + __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, + basic_string<_CharT>* __str = nullptr); void __push_l_anchor() {__left_anchor_ = true;} void __push_r_anchor(); @@ -2834,9 +2884,8 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, __first = __parse_basic_reg_exp(__first, __last); break; case extended: - __first = __parse_extended_reg_exp(__first, __last); - break; case awk: + __first = __parse_extended_reg_exp(__first, __last); break; case grep: __first = __parse_grep(__first, __last); @@ -3289,6 +3338,10 @@ basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, __push_char(*__temp); __first = ++__temp; break; + default: + if ((__flags_ & 0x1F0) == awk) + __first = __parse_awk_escape(++__first, __last); + break; } } } @@ -3488,7 +3541,7 @@ basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __firs // __ml owned by *this if (__first == __last) throw regex_error(regex_constants::error_brack); - if (*__first == ']') + if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') { __ml->__add_char(']'); ++__first; @@ -3538,7 +3591,6 @@ basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, { if (__first != __last && *__first != ']') { - bool __parsed_one = false; _ForwardIterator __temp = next(__first); basic_string<_CharT> __start_range; if (__temp != __last && *__first == '[') @@ -3548,15 +3600,23 @@ basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, else if (*__temp == ':') return __parse_character_class(++__temp, __last, __ml); else if (*__temp == '.') - { __first = __parse_collating_symbol(++__temp, __last, __start_range); - __parsed_one = true; - } } - if (!__parsed_one) + unsigned __grammar = __flags_ & 0x1F0; + if (__start_range.empty()) { - __start_range = *__first; - ++__first; + if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') + { + if (__grammar == ECMAScript) + __first = __parse_class_escape(++__first, __last, __start_range, __ml); + else + __first = __parse_awk_escape(++__first, __last, &__start_range); + } + else + { + __start_range = *__first; + ++__first; + } } if (__first != __last && *__first != ']') { @@ -3571,8 +3631,20 @@ basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, __first = __parse_collating_symbol(++__temp, __last, __end_range); else { - __end_range = *__first; - ++__first; + if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') + { + if (__grammar == ECMAScript) + __first = __parse_class_escape(++__first, __last, + __end_range, __ml); + else + __first = __parse_awk_escape(++__first, __last, + &__end_range); + } + else + { + __end_range = *__first; + ++__first; + } } __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range)); } @@ -3595,6 +3667,130 @@ basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, return __first; } +template +template +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, + _ForwardIterator __last, + basic_string<_CharT>& __str, + __bracket_expression<_CharT, _Traits>* __ml) +{ + if (__first == __last) + throw regex_error(regex_constants::error_escape); + switch (*__first) + { + case 0: + __str = *__first; + return ++__first; + case 'b': + __str = _CharT(8); + return ++__first; + case 'd': + __ml->__add_class(ctype_base::digit); + return ++__first; + case 'D': + __ml->__add_neg_class(ctype_base::digit); + return ++__first; + case 's': + __ml->__add_class(ctype_base::space); + return ++__first; + case 'S': + __ml->__add_neg_class(ctype_base::space); + return ++__first; + case 'w': + __ml->__add_class(ctype_base::alnum); + __ml->__add_char('_'); + return ++__first; + case 'W': + __ml->__add_neg_class(ctype_base::alnum); + __ml->__add_neg_char('_'); + return ++__first; + } + __first = __parse_character_escape(__first, __last, &__str); + return __first; +} + +template +template +_ForwardIterator +basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, + _ForwardIterator __last, + basic_string<_CharT>* __str) +{ + if (__first == __last) + throw regex_error(regex_constants::error_escape); + switch (*__first) + { + case '\\': + case '"': + case '/': + if (__str) + *__str = *__first; + else + __push_char(*__first); + return ++__first; + case 'a': + if (__str) + *__str = _CharT(7); + else + __push_char(_CharT(7)); + return ++__first; + case 'b': + if (__str) + *__str = _CharT(8); + else + __push_char(_CharT(8)); + return ++__first; + case 'f': + if (__str) + *__str = _CharT(0xC); + else + __push_char(_CharT(0xC)); + return ++__first; + case 'n': + if (__str) + *__str = _CharT(0xA); + else + __push_char(_CharT(0xA)); + return ++__first; + case 'r': + if (__str) + *__str = _CharT(0xD); + else + __push_char(_CharT(0xD)); + return ++__first; + case 't': + if (__str) + *__str = _CharT(0x9); + else + __push_char(_CharT(0x9)); + return ++__first; + case 'v': + if (__str) + *__str = _CharT(0xB); + else + __push_char(_CharT(0xB)); + return ++__first; + } + if ('0' <= *__first && *__first <= '7') + { + unsigned __val = *__first - '0'; + if (++__first != __last && ('0' <= *__first && *__first <= '7')) + { + __val = 8 * __val + *__first - '0'; + if (++__first != __last && ('0' <= *__first && *__first <= '7')) + __val = 8 * __val + *__first - '0'; + } + if (__str) + *__str = _CharT(__val); + else + __push_char(_CharT(__val)); + } + else + throw regex_error(regex_constants::error_escape); + return __first; +} + template template _ForwardIterator @@ -4013,7 +4209,8 @@ template template _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, - _ForwardIterator __last) + _ForwardIterator __last, + basic_string<_CharT>* __str) { if (__first != __last) { @@ -4023,23 +4220,38 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, switch (*__first) { case 'f': - __push_char(_CharT(0xC)); + if (__str) + *__str = _CharT(0xC); + else + __push_char(_CharT(0xC)); ++__first; break; case 'n': - __push_char(_CharT(0xA)); + if (__str) + *__str = _CharT(0xA); + else + __push_char(_CharT(0xA)); ++__first; break; case 'r': - __push_char(_CharT(0xD)); + if (__str) + *__str = _CharT(0xD); + else + __push_char(_CharT(0xD)); ++__first; break; case 't': - __push_char(_CharT(0x9)); + if (__str) + *__str = _CharT(0x9); + else + __push_char(_CharT(0x9)); ++__first; break; case 'v': - __push_char(_CharT(0xB)); + if (__str) + *__str = _CharT(0xB); + else + __push_char(_CharT(0xB)); ++__first; break; case 'c': @@ -4047,7 +4259,10 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, { if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z') { - __push_char(_CharT(*__t % 32)); + if (__str) + *__str = _CharT(*__t % 32); + else + __push_char(_CharT(*__t % 32)); __first = ++__t; } } @@ -4079,15 +4294,23 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, if (__hd == -1) throw regex_error(regex_constants::error_escape); __sum = 16 * __sum + __hd; - __push_char(_CharT(__sum)); + if (__str) + *__str = _CharT(__sum); + else + __push_char(_CharT(__sum)); ++__first; break; default: if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) { - __push_char(*__first); + if (__str) + *__str = *__first; + else + __push_char(*__first); ++__first; } + else if (__str) + throw regex_error(regex_constants::error_escape); break; } } diff --git a/test/re/re.alg/re.alg.search/awk.pass.cpp b/test/re/re.alg/re.alg.search/awk.pass.cpp new file mode 100644 index 00000000..a99fc615 --- /dev/null +++ b/test/re/re.alg/re.alg.search/awk.pass.cpp @@ -0,0 +1,1568 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool +// regex_search(BidirectionalIterator first, BidirectionalIterator last, +// match_results& m, +// const basic_regex& e, +// regex_constants::match_flag_type flags = regex_constants::match_default); + +#include +#include + +#include "../../iterators.h" + +int main() +{ + { + std::cmatch m; + const char s[] = "a"; + assert(std::regex_search(s, m, std::regex("a", std::regex_constants::awk))); + 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) == "a"); + } + { + std::cmatch m; + const char s[] = "ab"; + assert(std::regex_search(s, m, std::regex("ab", std::regex_constants::awk))); + 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) == "ab"); + } + { + std::cmatch m; + const char s[] = "ab"; + assert(!std::regex_search(s, m, std::regex("ba", std::regex_constants::awk))); + assert(m.size() == 0); + assert(m.empty()); + } + { + std::cmatch m; + const char s[] = "aab"; + assert(std::regex_search(s, m, std::regex("ab", std::regex_constants::awk))); + 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) == "ab"); + } + { + std::cmatch m; + const char s[] = "aab"; + assert(!std::regex_search(s, m, std::regex("ab", std::regex_constants::awk), + std::regex_constants::match_continuous)); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "abcd"; + assert(std::regex_search(s, m, std::regex("bc", std::regex_constants::awk))); + 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) == "bc"); + } + { + std::cmatch m; + const char s[] = "abbc"; + assert(std::regex_search(s, m, std::regex("ab*c", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "ababc"; + assert(std::regex_search(s, m, std::regex("(ab)*c", std::regex_constants::awk))); + 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) == "ab"); + } + { + std::cmatch m; + const char s[] = "abcdefghijk"; + assert(std::regex_search(s, m, std::regex("cd((e)fg)hi", + std::regex_constants::awk))); + 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) == "cdefghi"); + assert(m.length(1) == 3); + assert(m.position(1) == 4); + assert(m.str(1) == "efg"); + assert(m.length(2) == 1); + assert(m.position(2) == 4); + assert(m.str(2) == "e"); + } + { + std::cmatch m; + const char s[] = "abc"; + assert(std::regex_search(s, m, std::regex("^abc", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "abcd"; + assert(std::regex_search(s, m, std::regex("^abc", std::regex_constants::awk))); + 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) == "abc"); + } + { + std::cmatch m; + const char s[] = "aabc"; + assert(!std::regex_search(s, m, std::regex("^abc", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "abc"; + assert(std::regex_search(s, m, std::regex("abc$", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "efabc"; + assert(std::regex_search(s, m, std::regex("abc$", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "efabcg"; + assert(!std::regex_search(s, m, std::regex("abc$", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "abc"; + assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "acc"; + assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "acc"; + assert(std::regex_search(s, m, std::regex("a.c", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "abcdef"; + assert(std::regex_search(s, m, std::regex("(.*).*", std::regex_constants::awk))); + 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::cmatch m; + const char s[] = "bc"; + assert(std::regex_search(s, m, std::regex("(a*)*", std::regex_constants::awk))); + 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) == ""); + assert(m.length(1) == 0); + assert(m.position(1) == 0); + assert(m.str(1) == ""); + } + { + std::cmatch m; + const char s[] = "abbc"; + assert(!std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "abbbc"; + assert(std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); + 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[] = "abbbbc"; + assert(std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); + 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[] = "abbbbbc"; + assert(std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); + 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[] = "adefc"; + assert(!std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "abbbbbbc"; + assert(!std::regex_search(s, m, std::regex("ab{3,5}c", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "adec"; + assert(!std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "adefc"; + assert(std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); + 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[] = "adefgc"; + assert(std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); + 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[] = "adefghc"; + assert(std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); + 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[] = "adefghic"; + assert(!std::regex_search(s, m, std::regex("a.{3,5}c", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "tournament"; + assert(std::regex_search(s, m, std::regex("tour|to|tournament", + std::regex_constants::awk))); + 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[] = "tournamenttotour"; + assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+", + std::regex_constants::awk | 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::cmatch m; + const char s[] = "ttotour"; + assert(std::regex_search(s, m, std::regex("(tour|to|t)+", + std::regex_constants::awk))); + 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) == "tour"); + } + { + std::cmatch m; + const char s[] = "-ab,ab-"; + assert(!std::regex_search(s, m, std::regex("-(.*),\1-", std::regex_constants::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "-ab,ab-"; + assert(std::regex_search(s, m, std::regex("-.*,.*-", std::regex_constants::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "Iraqi"; + assert(std::regex_search(s, m, std::regex("q[^u]", + std::regex_constants::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk | 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::awk))); + assert(m.size() == 0); + } + { + std::cmatch m; + const char s[] = "01a45cef9"; + assert(std::regex_search(s, m, std::regex("[ace1-9]*", + std::regex_constants::awk))); + 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) == 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::awk))); + 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::awk); + 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::cmatch m; + const char s[] = "\n\n\n"; + assert(std::regex_search(s, m, std::regex("[\\n]+", + std::regex_constants::awk))); + 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) == 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk), + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk | 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk))); + 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::awk | 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::awk))); + 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::awk))); + 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) == 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::awk))); + 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::awk); + 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); + } + { + std::wcmatch m; + const wchar_t s[] = L"\n\n\n"; + assert(std::regex_search(s, m, std::wregex(L"[\\n]+", + std::regex_constants::awk))); + 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) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } +} diff --git a/test/re/re.alg/re.alg.search/ecma.pass.cpp b/test/re/re.alg/re.alg.search/ecma.pass.cpp index ed8f54a9..927c37af 100644 --- a/test/re/re.alg/re.alg.search/ecma.pass.cpp +++ b/test/re/re.alg/re.alg.search/ecma.pass.cpp @@ -788,6 +788,21 @@ int main() assert(m.position(0) == 6); assert(m.str(0) == "Jeff"); } + { + std::cmatch m; + const char s[] = "5%k"; + assert(std::regex_search(s, m, std::regex("\\d[\\W]k"))); + 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) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } { std::wcmatch m; @@ -1552,4 +1567,19 @@ int main() assert(m.position(0) == 6); assert(m.str(0) == L"Jeff"); } + { + std::wcmatch m; + const wchar_t s[] = L"5%k"; + assert(std::regex_search(s, m, std::wregex(L"\\d[\\W]k"))); + 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) == std::char_traits::length(s)); + assert(m.position(0) == 0); + assert(m.str(0) == s); + } }