]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/28_regex/traits/char/user_defined.cc
1 // { dg-do run { target c++11 } }
2 // { dg-timeout-factor 2 }
5 // 2014-01-07 Tim Shen <timshen91@gmail.com>
7 // Copyright (C) 2010-2024 Free Software Foundation, Inc.
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)
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.
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/>.
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]
30 #include <testsuite_hooks.h>
34 bool called_transform
= false;
35 bool called_nocase
= false;
37 template<typename CharT
>
39 : public regex_traits
<CharT
>
43 translate(CharT c
) const
49 translate_nocase(CharT c
) const
52 return regex_traits
<CharT
>::translate_nocase(c
);
55 template<typename FwdIt
>
57 transform(FwdIt begin
, FwdIt end
) const
59 called_transform
= true;
60 return regex_traits
<CharT
>::transform(begin
, end
);
68 basic_regex
<char, MyRegexTraits
<char>> re(".");
69 VERIFY(!regex_match("\n", re
));
70 VERIFY(!regex_match("\r", re
));
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;
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;
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
));
93 VERIFY(!regex_match("G", re
));
94 VERIFY(!regex_match("S", re
));
95 VERIFY(!regex_match("g", re
));
96 VERIFY(!regex_match("s", re
));
98 VERIFY(regex_match("T", re
));
99 VERIFY(regex_match("Z", re
));
100 VERIFY(regex_match("t", re
));
101 VERIFY(regex_match("z", re
));
103 // icase doesn't participate with the presence of collate and user-defined traits.
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
));