]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/28_regex/traits/char/user_defined.cc
d23e4c65c111f5a225dd81afac5f695ffb22641c
1 // { dg-do run { target c++11 } }
4 // 2014-01-07 Tim Shen <timshen91@gmail.com>
6 // Copyright (C) 2010-2019 Free Software Foundation, Inc.
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)
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.
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/>.
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]
29 #include <testsuite_hooks.h>
33 bool called_transform
= false;
34 bool called_nocase
= false;
36 template<typename CharT
>
38 : public regex_traits
<CharT
>
42 translate(CharT c
) const
48 translate_nocase(CharT c
) const
51 return regex_traits
<CharT
>::translate_nocase(c
);
54 template<typename FwdIt
>
56 transform(FwdIt begin
, FwdIt end
) const
58 called_transform
= true;
59 return regex_traits
<CharT
>::transform(begin
, end
);
67 basic_regex
<char, MyRegexTraits
<char>> re(".");
68 VERIFY(!regex_match("\n", re
));
69 VERIFY(!regex_match("\r", re
));
72 VERIFY(!called_transform
);
73 basic_regex
<char, MyRegexTraits
<char>> re("[a]", regex::collate
);
74 VERIFY(regex_match("a", re
));
75 VERIFY(called_transform
);
76 called_transform
= false;
79 VERIFY(!called_nocase
);
80 basic_regex
<char, MyRegexTraits
<char>> re("[a]", regex::icase
);
81 VERIFY(regex_match("A", re
));
82 VERIFY(called_nocase
);
83 called_nocase
= false;
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
));
92 VERIFY(!regex_match("G", re
));
93 VERIFY(!regex_match("S", re
));
94 VERIFY(!regex_match("g", re
));
95 VERIFY(!regex_match("s", re
));
97 VERIFY(regex_match("T", re
));
98 VERIFY(regex_match("Z", re
));
99 VERIFY(regex_match("t", re
));
100 VERIFY(regex_match("z", re
));
102 // icase doesn't participate with the presence of collate and user-defined traits.
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
));