1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <regex>
11 
12 // template <class charT> struct regex_traits;
13 
14 // template <class ForwardIterator>
15 //   char_class_type
16 //   lookup_classname(ForwardIterator first, ForwardIterator last,
17 //                    bool icase = false) const;
18 
19 #include <regex>
20 #include <cassert>
21 #include "test_iterators.h"
22 
23 template <class char_type>
24 void
test(const char_type * A,std::ctype_base::mask expected,bool icase=false)25 test(const char_type* A, std::ctype_base::mask expected, bool icase = false)
26 {
27     std::regex_traits<char_type> t;
28     typedef forward_iterator<const char_type*> F;
29     assert(t.lookup_classname(F(A), F(A + t.length(A)), icase) == expected);
30 }
31 
main()32 int main()
33 {
34     test("d", std::ctype_base::digit);
35     test("D", std::ctype_base::digit);
36     test("d", std::ctype_base::digit, true);
37     test("D", std::ctype_base::digit, true);
38 
39     test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
40                       | std::ctype_base::upper | std::ctype_base::lower);
41     test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
42                       | std::ctype_base::upper | std::ctype_base::lower);
43     test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
44                       | std::ctype_base::upper | std::ctype_base::lower, true);
45     test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
46                       | std::ctype_base::upper | std::ctype_base::lower, true);
47 
48     test("s", std::ctype_base::space);
49     test("S", std::ctype_base::space);
50     test("s", std::ctype_base::space, true);
51     test("S", std::ctype_base::space, true);
52 
53     test("alnum", std::ctype_base::alnum);
54     test("AlNum", std::ctype_base::alnum);
55     test("alnum", std::ctype_base::alnum, true);
56     test("AlNum", std::ctype_base::alnum, true);
57 
58     test("alpha", std::ctype_base::alpha);
59     test("Alpha", std::ctype_base::alpha);
60     test("alpha", std::ctype_base::alpha, true);
61     test("Alpha", std::ctype_base::alpha, true);
62 
63     test("blank", std::ctype_base::blank);
64     test("Blank", std::ctype_base::blank);
65     test("blank", std::ctype_base::blank, true);
66     test("Blank", std::ctype_base::blank, true);
67 
68     test("cntrl", std::ctype_base::cntrl);
69     test("Cntrl", std::ctype_base::cntrl);
70     test("cntrl", std::ctype_base::cntrl, true);
71     test("Cntrl", std::ctype_base::cntrl, true);
72 
73     test("digit", std::ctype_base::digit);
74     test("Digit", std::ctype_base::digit);
75     test("digit", std::ctype_base::digit, true);
76     test("Digit", std::ctype_base::digit, true);
77 
78     test("digit", std::ctype_base::digit);
79     test("DIGIT", std::ctype_base::digit);
80     test("digit", std::ctype_base::digit, true);
81     test("Digit", std::ctype_base::digit, true);
82 
83     test("graph", std::ctype_base::graph);
84     test("GRAPH", std::ctype_base::graph);
85     test("graph", std::ctype_base::graph, true);
86     test("Graph", std::ctype_base::graph, true);
87 
88     test("lower", std::ctype_base::lower);
89     test("LOWER", std::ctype_base::lower);
90     test("lower", std::ctype_base::lower | std::ctype_base::alpha, true);
91     test("Lower", std::ctype_base::lower | std::ctype_base::alpha, true);
92 
93     test("print", std::ctype_base::print);
94     test("PRINT", std::ctype_base::print);
95     test("print", std::ctype_base::print, true);
96     test("Print", std::ctype_base::print, true);
97 
98     test("punct", std::ctype_base::punct);
99     test("PUNCT", std::ctype_base::punct);
100     test("punct", std::ctype_base::punct, true);
101     test("Punct", std::ctype_base::punct, true);
102 
103     test("space", std::ctype_base::space);
104     test("SPACE", std::ctype_base::space);
105     test("space", std::ctype_base::space, true);
106     test("Space", std::ctype_base::space, true);
107 
108     test("upper", std::ctype_base::upper);
109     test("UPPER", std::ctype_base::upper);
110     test("upper", std::ctype_base::upper | std::ctype_base::alpha, true);
111     test("Upper", std::ctype_base::upper | std::ctype_base::alpha, true);
112 
113     test("xdigit", std::ctype_base::xdigit);
114     test("XDIGIT", std::ctype_base::xdigit);
115     test("xdigit", std::ctype_base::xdigit, true);
116     test("Xdigit", std::ctype_base::xdigit, true);
117 
118     test("dig", std::ctype_base::mask());
119     test("", std::ctype_base::mask());
120     test("digits", std::ctype_base::mask());
121 
122     test(L"d", std::ctype_base::digit);
123     test(L"D", std::ctype_base::digit);
124     test(L"d", std::ctype_base::digit, true);
125     test(L"D", std::ctype_base::digit, true);
126 
127     test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
128                       | std::ctype_base::upper | std::ctype_base::lower);
129     test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
130                       | std::ctype_base::upper | std::ctype_base::lower);
131     test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
132                       | std::ctype_base::upper | std::ctype_base::lower, true);
133     test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
134                       | std::ctype_base::upper | std::ctype_base::lower, true);
135 
136     test(L"s", std::ctype_base::space);
137     test(L"S", std::ctype_base::space);
138     test(L"s", std::ctype_base::space, true);
139     test(L"S", std::ctype_base::space, true);
140 
141     test(L"alnum", std::ctype_base::alnum);
142     test(L"AlNum", std::ctype_base::alnum);
143     test(L"alnum", std::ctype_base::alnum, true);
144     test(L"AlNum", std::ctype_base::alnum, true);
145 
146     test(L"alpha", std::ctype_base::alpha);
147     test(L"Alpha", std::ctype_base::alpha);
148     test(L"alpha", std::ctype_base::alpha, true);
149     test(L"Alpha", std::ctype_base::alpha, true);
150 
151     test(L"blank", std::ctype_base::blank);
152     test(L"Blank", std::ctype_base::blank);
153     test(L"blank", std::ctype_base::blank, true);
154     test(L"Blank", std::ctype_base::blank, true);
155 
156     test(L"cntrl", std::ctype_base::cntrl);
157     test(L"Cntrl", std::ctype_base::cntrl);
158     test(L"cntrl", std::ctype_base::cntrl, true);
159     test(L"Cntrl", std::ctype_base::cntrl, true);
160 
161     test(L"digit", std::ctype_base::digit);
162     test(L"Digit", std::ctype_base::digit);
163     test(L"digit", std::ctype_base::digit, true);
164     test(L"Digit", std::ctype_base::digit, true);
165 
166     test(L"digit", std::ctype_base::digit);
167     test(L"DIGIT", std::ctype_base::digit);
168     test(L"digit", std::ctype_base::digit, true);
169     test(L"Digit", std::ctype_base::digit, true);
170 
171     test(L"graph", std::ctype_base::graph);
172     test(L"GRAPH", std::ctype_base::graph);
173     test(L"graph", std::ctype_base::graph, true);
174     test(L"Graph", std::ctype_base::graph, true);
175 
176     test(L"lower", std::ctype_base::lower);
177     test(L"LOWER", std::ctype_base::lower);
178     test(L"lower", std::ctype_base::lower | std::ctype_base::alpha, true);
179     test(L"Lower", std::ctype_base::lower | std::ctype_base::alpha, true);
180 
181     test(L"print", std::ctype_base::print);
182     test(L"PRINT", std::ctype_base::print);
183     test(L"print", std::ctype_base::print, true);
184     test(L"Print", std::ctype_base::print, true);
185 
186     test(L"punct", std::ctype_base::punct);
187     test(L"PUNCT", std::ctype_base::punct);
188     test(L"punct", std::ctype_base::punct, true);
189     test(L"Punct", std::ctype_base::punct, true);
190 
191     test(L"space", std::ctype_base::space);
192     test(L"SPACE", std::ctype_base::space);
193     test(L"space", std::ctype_base::space, true);
194     test(L"Space", std::ctype_base::space, true);
195 
196     test(L"upper", std::ctype_base::upper);
197     test(L"UPPER", std::ctype_base::upper);
198     test(L"upper", std::ctype_base::upper | std::ctype_base::alpha, true);
199     test(L"Upper", std::ctype_base::upper | std::ctype_base::alpha, true);
200 
201     test(L"xdigit", std::ctype_base::xdigit);
202     test(L"XDIGIT", std::ctype_base::xdigit);
203     test(L"xdigit", std::ctype_base::xdigit, true);
204     test(L"Xdigit", std::ctype_base::xdigit, true);
205 
206     test(L"dig", std::ctype_base::mask());
207     test(L"", std::ctype_base::mask());
208     test(L"digits", std::ctype_base::mask());
209 }
210