diff options
author | Tim Shen <timshen@google.com> | 2016-12-01 03:03:55 +0000 |
---|---|---|
committer | Tim Shen <timshen@gcc.gnu.org> | 2016-12-01 03:03:55 +0000 |
commit | 974afa584b18a3713eb4ada1b5d657ca0f94f498 (patch) | |
tree | 99b6e42fe5cfb1174faef0662f47640649cba2a5 /libstdc++-v3/testsuite/28_regex/traits | |
parent | 0f09127808018c479214478d3f79e0ac40a3c55b (diff) | |
download | gcc-974afa584b18a3713eb4ada1b5d657ca0f94f498.tar.gz |
re PR libstdc++/71500 (regex::icase only works on first character in a range)
PR libstdc++/71500
* include/bits/regex.h (basic_regex::basic_regex): Use ECMAScript
when the syntax is not specified.
* include/bits/regex_compiler.h (_RegexTranslator,
_RegexTranslatorBase): Partially support icase in ranges.
* include/bits/regex_compiler.tcc (_BracketMatcher::_M_apply):
Refactor _M_apply to make the control flow easier to follow, and
call _M_translator._M_match_range as added previously.
* testsuite/28_regex/traits/char/icase.cc: Add new tests.
* testsuite/28_regex/traits/char/user_defined.cc: Add new tests.
From-SVN: r243093
Diffstat (limited to 'libstdc++-v3/testsuite/28_regex/traits')
-rw-r--r-- | libstdc++-v3/testsuite/28_regex/traits/char/icase.cc | 74 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/28_regex/traits/char/user_defined.cc | 66 |
2 files changed, 137 insertions, 3 deletions
diff --git a/libstdc++-v3/testsuite/28_regex/traits/char/icase.cc b/libstdc++-v3/testsuite/28_regex/traits/char/icase.cc new file mode 100644 index 00000000000..97bbd079f51 --- /dev/null +++ b/libstdc++-v3/testsuite/28_regex/traits/char/icase.cc @@ -0,0 +1,74 @@ +// { dg-do run { target c++11 } } + +// +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 28.7 Class template regex_traits [re.traits] + +#include <regex> +#include <testsuite_hooks.h> + +using namespace std; + +void +test01() +{ + { + regex re("[T-f]", regex::icase); + + VERIFY(regex_match("A", re)); + VERIFY(regex_match("F", re)); + VERIFY(regex_match("a", re)); + VERIFY(regex_match("f", re)); + + VERIFY(!regex_match("G", re)); + VERIFY(!regex_match("S", re)); + VERIFY(!regex_match("g", re)); + VERIFY(!regex_match("s", re)); + + VERIFY(regex_match("T", re)); + VERIFY(regex_match("Z", re)); + VERIFY(regex_match("t", re)); + VERIFY(regex_match("z", re)); + } + // icase works with std::regex_traits<>, because we know how it's implemented. + { + regex re("[T-f]", regex::icase | regex::collate); + + VERIFY(regex_match("A", re)); + VERIFY(regex_match("F", re)); + VERIFY(regex_match("a", re)); + VERIFY(regex_match("f", re)); + + VERIFY(!regex_match("G", re)); + VERIFY(!regex_match("S", re)); + VERIFY(!regex_match("g", re)); + VERIFY(!regex_match("s", re)); + + VERIFY(regex_match("T", re)); + VERIFY(regex_match("Z", re)); + VERIFY(regex_match("t", re)); + VERIFY(regex_match("z", re)); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/28_regex/traits/char/user_defined.cc b/libstdc++-v3/testsuite/28_regex/traits/char/user_defined.cc index 4af05634b23..5888ce1b4a0 100644 --- a/libstdc++-v3/testsuite/28_regex/traits/char/user_defined.cc +++ b/libstdc++-v3/testsuite/28_regex/traits/char/user_defined.cc @@ -30,6 +30,9 @@ using namespace std; +bool called_transform = false; +bool called_nocase = false; + template<typename CharT> class MyRegexTraits : public regex_traits<CharT> @@ -40,14 +43,71 @@ template<typename CharT> { return c+1; } + + CharT + translate_nocase(CharT c) const + { + called_nocase = true; + return regex_traits<CharT>::translate_nocase(c); + } + + template<typename FwdIt> + basic_string<CharT> + transform(FwdIt begin, FwdIt end) const + { + called_transform = true; + return regex_traits<CharT>::transform(begin, end); + } }; void test01() { - basic_regex<char, MyRegexTraits<char>> re("."); - VERIFY(!regex_match("\n", re)); - VERIFY(!regex_match("\r", re)); + { + basic_regex<char, MyRegexTraits<char>> re("."); + VERIFY(!regex_match("\n", re)); + VERIFY(!regex_match("\r", re)); + } + { + VERIFY(!called_transform); + basic_regex<char, MyRegexTraits<char>> re("[a]", regex::collate); + VERIFY(regex_match("a", re)); + VERIFY(exchange(called_transform, false)); + } + { + VERIFY(!called_nocase); + basic_regex<char, MyRegexTraits<char>> re("[a]", regex::icase); + VERIFY(regex_match("A", re)); + VERIFY(exchange(called_nocase, false)); + } + { + basic_regex<char, MyRegexTraits<char>> re("[T-f]", regex::icase); + VERIFY(regex_match("A", re)); + VERIFY(regex_match("F", re)); + VERIFY(regex_match("a", re)); + VERIFY(regex_match("f", re)); + + VERIFY(!regex_match("G", re)); + VERIFY(!regex_match("S", re)); + VERIFY(!regex_match("g", re)); + VERIFY(!regex_match("s", re)); + + VERIFY(regex_match("T", re)); + VERIFY(regex_match("Z", re)); + VERIFY(regex_match("t", re)); + VERIFY(regex_match("z", re)); + } + // icase doesn't participate with the presence of collate and user-defined traits. + { + basic_regex<char, MyRegexTraits<char>> re("[T-f]", regex::icase | regex::collate); + VERIFY(!regex_match("A", re)); + VERIFY(!regex_match("S", re)); + VERIFY(regex_match("T", re)); + VERIFY(regex_match("Z", re)); + VERIFY(regex_match("a", re)); + VERIFY(regex_match("f", re)); + VERIFY(!regex_match("g", re)); + } } int main() |