| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-timeout-factor 2 } |
| 3 | |
| 4 | // |
| 5 | // 2014-01-07 Tim Shen <[email protected]> |
| 6 | // |
| 7 | // Copyright (C) 2010-2025 Free Software Foundation, Inc. |
| 8 | // |
| 9 | // This file is part of the GNU ISO C++ Library. This library is free |
| 10 | // software; you can redistribute it and/or modify it under the |
| 11 | // terms of the GNU General Public License as published by the |
| 12 | // Free Software Foundation; either version 3, or (at your option) |
| 13 | // any later version. |
| 14 | // |
| 15 | // This library is distributed in the hope that it will be useful, |
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | // GNU General Public License for more details. |
| 19 | // |
| 20 | // You should have received a copy of the GNU General Public License along |
| 21 | // with this library; see the file COPYING3. If not see |
| 22 | // <http://www.gnu.org/licenses/>. |
| 23 | |
| 24 | // 28.3 Requirements [re.req] |
| 25 | // 28.2 (4) Table 127 - Regular expression traits class requirements |
| 26 | // 28.7 Class template regex_traits [re.traits] |
| 27 | |
| 28 | #include <regex> |
| 29 | #include <string> |
| 30 | #include <testsuite_hooks.h> |
| 31 | |
| 32 | using namespace std; |
| 33 | |
| 34 | bool called_transform = false; |
| 35 | bool called_nocase = false; |
| 36 | |
| 37 | template<typename CharT> |
| 38 | class MyRegexTraits |
| 39 | : public regex_traits<CharT> |
| 40 | { |
| 41 | public: |
| 42 | CharT |
| 43 | translate(CharT c) const |
| 44 | { |
| 45 | return c+1; |
| 46 | } |
| 47 | |
| 48 | CharT |
| 49 | translate_nocase(CharT c) const |
| 50 | { |
| 51 | called_nocase = true; |
| 52 | return regex_traits<CharT>::translate_nocase(c); |
| 53 | } |
| 54 | |
| 55 | template<typename FwdIt> |
| 56 | basic_string<CharT> |
| 57 | transform(FwdIt begin, FwdIt end) const |
| 58 | { |
| 59 | called_transform = true; |
| 60 | return regex_traits<CharT>::transform(begin, end); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | void |
| 65 | test01() |
| 66 | { |
| 67 | { |
| 68 | basic_regex<char, MyRegexTraits<char>> re("."); |
| 69 | VERIFY(!regex_match("\n", re)); |
| 70 | VERIFY(!regex_match("\r", re)); |
| 71 | } |
| 72 | { |
| 73 | VERIFY(!called_transform); |
| 74 | basic_regex<char, MyRegexTraits<char>> re("[a]", regex::collate); |
| 75 | VERIFY(regex_match("a", re)); |
| 76 | VERIFY(called_transform); |
| 77 | called_transform = false; |
| 78 | } |
| 79 | { |
| 80 | VERIFY(!called_nocase); |
| 81 | basic_regex<char, MyRegexTraits<char>> re("[a]", regex::icase); |
| 82 | VERIFY(regex_match("A", re)); |
| 83 | VERIFY(called_nocase); |
| 84 | called_nocase = false; |
| 85 | } |
| 86 | { |
| 87 | basic_regex<char, MyRegexTraits<char>> re("[T-f]", regex::icase); |
| 88 | VERIFY(regex_match("A", re)); |
| 89 | VERIFY(regex_match("F", re)); |
| 90 | VERIFY(regex_match("a", re)); |
| 91 | VERIFY(regex_match("f", re)); |
| 92 | |
| 93 | VERIFY(!regex_match("G", re)); |
| 94 | VERIFY(!regex_match("S", re)); |
| 95 | VERIFY(!regex_match("g", re)); |
| 96 | VERIFY(!regex_match("s", re)); |
| 97 | |
| 98 | VERIFY(regex_match("T", re)); |
| 99 | VERIFY(regex_match("Z", re)); |
| 100 | VERIFY(regex_match("t", re)); |
| 101 | VERIFY(regex_match("z", re)); |
| 102 | } |
| 103 | // icase doesn't participate with the presence of collate and user-defined traits. |
| 104 | { |
| 105 | basic_regex<char, MyRegexTraits<char>> re("[T-f]", regex::icase | regex::collate); |
| 106 | VERIFY(!regex_match("A", re)); |
| 107 | VERIFY(!regex_match("S", re)); |
| 108 | VERIFY(regex_match("T", re)); |
| 109 | VERIFY(regex_match("Z", re)); |
| 110 | VERIFY(regex_match("a", re)); |
| 111 | VERIFY(regex_match("f", re)); |
| 112 | VERIFY(!regex_match("g", re)); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | int main() |
| 117 | { |
| 118 | test01(); |
| 119 | return 0; |
| 120 | } |