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 // REQUIRES: locale.cs_CZ.ISO8859-2
11 
12 // <regex>
13 
14 // template <class charT> struct regex_traits;
15 
16 // template <class ForwardIterator>
17 //   string_type
18 //   lookup_collatename(ForwardIterator first, ForwardIterator last) const;
19 
20 #include <regex>
21 #include <iterator>
22 #include <cassert>
23 #include "test_iterators.h"
24 
25 template <class char_type>
26 void
test(const char_type * A,const std::basic_string<char_type> & expected)27 test(const char_type* A, const std::basic_string<char_type>& expected)
28 {
29     std::regex_traits<char_type> t;
30     typedef forward_iterator<const char_type*> F;
31     assert(t.lookup_collatename(F(A), F(A + t.length(A))) == expected);
32 }
33 
main()34 int main()
35 {
36     test("NUL", std::string("\x00", 1));
37     test("alert", std::string("\x07"));
38     test("backspace", std::string("\x08"));
39     test("tab", std::string("\x09"));
40     test("carriage-return", std::string("\x0D"));
41     test("newline", std::string("\x0A"));
42     test("vertical-tab", std::string("\x0B"));
43     test("form-feed", std::string("\x0C"));
44     test("space", std::string(" "));
45     test("exclamation-mark", std::string("!"));
46     test("quotation-mark", std::string("\""));
47     test("number-sign", std::string("#"));
48     test("dollar-sign", std::string("$"));
49     test("percent-sign", std::string("%"));
50     test("ampersand", std::string("&"));
51     test("apostrophe", std::string("\'"));
52     test("left-parenthesis", std::string("("));
53     test("right-parenthesis", std::string(")"));
54     test("asterisk", std::string("*"));
55     test("plus-sign", std::string("+"));
56     test("comma", std::string(","));
57     test("hyphen-minus", std::string("-"));
58     test("hyphen", std::string("-"));
59     test("full-stop", std::string("."));
60     test("period", std::string("."));
61     test("slash", std::string("/"));
62     test("solidus", std::string("/"));
63     test("zero", std::string("0"));
64     test("one", std::string("1"));
65     test("two", std::string("2"));
66     test("three", std::string("3"));
67     test("four", std::string("4"));
68     test("five", std::string("5"));
69     test("six", std::string("6"));
70     test("seven", std::string("7"));
71     test("eight", std::string("8"));
72     test("nine", std::string("9"));
73     test("colon", std::string(":"));
74     test("semicolon", std::string(";"));
75     test("less-than-sign", std::string("<"));
76     test("equals-sign", std::string("="));
77     test("greater-than-sign", std::string(">"));
78     test("question-mark", std::string("?"));
79     test("commercial-at", std::string("@"));
80     for (char c = 'A'; c <= 'Z'; ++c)
81     {
82         const char a[2] = {c};
83         test(a, std::string(a));
84     }
85     test("left-square-bracket", std::string("["));
86     test("backslash", std::string("\\"));
87     test("reverse-solidus", std::string("\\"));
88     test("right-square-bracket", std::string("]"));
89     test("circumflex-accent", std::string("^"));
90     test("circumflex", std::string("^"));
91     test("low-line", std::string("_"));
92     test("underscore", std::string("_"));
93     test("grave-accent", std::string("`"));
94     for (char c = 'a'; c <= 'z'; ++c)
95     {
96         const char a[2] = {c};
97         test(a, std::string(a));
98     }
99     test("left-brace", std::string("{"));
100     test("left-curly-bracket", std::string("{"));
101     test("vertical-line", std::string("|"));
102     test("right-brace", std::string("}"));
103     test("right-curly-bracket", std::string("}"));
104     test("tilde", std::string("~"));
105 
106     test("tild", std::string(""));
107     test("ch", std::string(""));
108     std::locale::global(std::locale("cs_CZ.ISO8859-2"));
109     test("ch", std::string("ch"));
110     std::locale::global(std::locale("C"));
111 
112     test(L"NUL", std::wstring(L"\x00", 1));
113     test(L"alert", std::wstring(L"\x07"));
114     test(L"backspace", std::wstring(L"\x08"));
115     test(L"tab", std::wstring(L"\x09"));
116     test(L"carriage-return", std::wstring(L"\x0D"));
117     test(L"newline", std::wstring(L"\x0A"));
118     test(L"vertical-tab", std::wstring(L"\x0B"));
119     test(L"form-feed", std::wstring(L"\x0C"));
120     test(L"space", std::wstring(L" "));
121     test(L"exclamation-mark", std::wstring(L"!"));
122     test(L"quotation-mark", std::wstring(L"\""));
123     test(L"number-sign", std::wstring(L"#"));
124     test(L"dollar-sign", std::wstring(L"$"));
125     test(L"percent-sign", std::wstring(L"%"));
126     test(L"ampersand", std::wstring(L"&"));
127     test(L"apostrophe", std::wstring(L"\'"));
128     test(L"left-parenthesis", std::wstring(L"("));
129     test(L"right-parenthesis", std::wstring(L")"));
130     test(L"asterisk", std::wstring(L"*"));
131     test(L"plus-sign", std::wstring(L"+"));
132     test(L"comma", std::wstring(L","));
133     test(L"hyphen-minus", std::wstring(L"-"));
134     test(L"hyphen", std::wstring(L"-"));
135     test(L"full-stop", std::wstring(L"."));
136     test(L"period", std::wstring(L"."));
137     test(L"slash", std::wstring(L"/"));
138     test(L"solidus", std::wstring(L"/"));
139     test(L"zero", std::wstring(L"0"));
140     test(L"one", std::wstring(L"1"));
141     test(L"two", std::wstring(L"2"));
142     test(L"three", std::wstring(L"3"));
143     test(L"four", std::wstring(L"4"));
144     test(L"five", std::wstring(L"5"));
145     test(L"six", std::wstring(L"6"));
146     test(L"seven", std::wstring(L"7"));
147     test(L"eight", std::wstring(L"8"));
148     test(L"nine", std::wstring(L"9"));
149     test(L"colon", std::wstring(L":"));
150     test(L"semicolon", std::wstring(L";"));
151     test(L"less-than-sign", std::wstring(L"<"));
152     test(L"equals-sign", std::wstring(L"="));
153     test(L"greater-than-sign", std::wstring(L">"));
154     test(L"question-mark", std::wstring(L"?"));
155     test(L"commercial-at", std::wstring(L"@"));
156     for (wchar_t c = L'A'; c <= L'Z'; ++c)
157     {
158         const wchar_t a[2] = {c};
159         test(a, std::wstring(a));
160     }
161     test(L"left-square-bracket", std::wstring(L"["));
162     test(L"backslash", std::wstring(L"\\"));
163     test(L"reverse-solidus", std::wstring(L"\\"));
164     test(L"right-square-bracket", std::wstring(L"]"));
165     test(L"circumflex-accent", std::wstring(L"^"));
166     test(L"circumflex", std::wstring(L"^"));
167     test(L"low-line", std::wstring(L"_"));
168     test(L"underscore", std::wstring(L"_"));
169     test(L"grave-accent", std::wstring(L"`"));
170     for (wchar_t c = L'a'; c <= L'z'; ++c)
171     {
172         const wchar_t a[2] = {c};
173         test(a, std::wstring(a));
174     }
175     test(L"left-brace", std::wstring(L"{"));
176     test(L"left-curly-bracket", std::wstring(L"{"));
177     test(L"vertical-line", std::wstring(L"|"));
178     test(L"right-brace", std::wstring(L"}"));
179     test(L"right-curly-bracket", std::wstring(L"}"));
180     test(L"tilde", std::wstring(L"~"));
181 
182     test(L"tild", std::wstring(L""));
183     test(L"ch", std::wstring(L""));
184     std::locale::global(std::locale("cs_CZ.ISO8859-2"));
185     test(L"ch", std::wstring(L"ch"));
186     std::locale::global(std::locale("C"));
187 }
188