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