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 // <codecvt>
11
12 // template <class Elem, unsigned long Maxcode = 0x10ffff,
13 // codecvt_mode Mode = (codecvt_mode)0>
14 // class codecvt_utf16
15 // : public codecvt<Elem, char, mbstate_t>
16 // {
17 // // unspecified
18 // };
19
20 // int length(stateT& state, const externT* from, const externT* from_end,
21 // size_t max) const;
22
23 #include <codecvt>
24 #include <cassert>
25
main()26 int main()
27 {
28 {
29 typedef std::codecvt_utf16<wchar_t> C;
30 C c;
31 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
32 std::mbstate_t m;
33 int r = c.length(m, n, n+4, 2);
34 assert(r == 4);
35
36 n[0] = char(0x10);
37 n[1] = char(0x05);
38 r = c.length(m, n, n+2, 2);
39 assert(r == 2);
40
41 n[0] = char(0x04);
42 n[1] = char(0x53);
43 r = c.length(m, n, n+2, 2);
44 assert(r == 2);
45
46 n[0] = char(0x00);
47 n[1] = char(0x56);
48 r = c.length(m, n, n+2, 2);
49 assert(r == 2);
50 }
51 {
52 typedef std::codecvt_utf16<wchar_t, 0x1000> C;
53 C c;
54 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
55 std::mbstate_t m;
56 int r = c.length(m, n, n+4, 2);
57 assert(r == 0);
58
59 n[0] = char(0x10);
60 n[1] = char(0x05);
61 r = c.length(m, n, n+2, 2);
62 assert(r == 0);
63
64 n[0] = char(0x04);
65 n[1] = char(0x53);
66 r = c.length(m, n, n+2, 2);
67 assert(r == 2);
68
69 n[0] = char(0x00);
70 n[1] = char(0x56);
71 r = c.length(m, n, n+2, 2);
72 assert(r == 2);
73 }
74 {
75 typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header> C;
76 C c;
77 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
78 std::mbstate_t m;
79 int r = c.length(m, n, n+6, 2);
80 assert(r == 6);
81
82 n[0] = char(0x10);
83 n[1] = char(0x05);
84 r = c.length(m, n, n+2, 2);
85 assert(r == 2);
86
87 n[0] = char(0x04);
88 n[1] = char(0x53);
89 r = c.length(m, n, n+2, 2);
90 assert(r == 2);
91
92 n[0] = char(0x00);
93 n[1] = char(0x56);
94 r = c.length(m, n, n+2, 2);
95 assert(r == 2);
96 }
97 {
98 typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian> C;
99 C c;
100 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
101 std::mbstate_t m;
102 int r = c.length(m, n, n+4, 2);
103 assert(r == 4);
104
105 n[1] = char(0x10);
106 n[0] = char(0x05);
107 r = c.length(m, n, n+2, 2);
108 assert(r == 2);
109
110 n[1] = char(0x04);
111 n[0] = char(0x53);
112 r = c.length(m, n, n+2, 2);
113 assert(r == 2);
114
115 n[1] = char(0x00);
116 n[0] = char(0x56);
117 r = c.length(m, n, n+2, 2);
118 assert(r == 2);
119 }
120 {
121 typedef std::codecvt_utf16<wchar_t, 0x1000, std::little_endian> C;
122 C c;
123 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
124 std::mbstate_t m;
125 int r = c.length(m, n, n+4, 2);
126 assert(r == 0);
127
128 n[1] = char(0x10);
129 n[0] = char(0x05);
130 r = c.length(m, n, n+2, 2);
131 assert(r == 0);
132
133 n[1] = char(0x04);
134 n[0] = char(0x53);
135 r = c.length(m, n, n+2, 2);
136 assert(r == 2);
137
138 n[1] = char(0x00);
139 n[0] = char(0x56);
140 r = c.length(m, n, n+2, 2);
141 assert(r == 2);
142 }
143 {
144 typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::codecvt_mode(
145 std::consume_header |
146 std::little_endian)> C;
147 C c;
148 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
149 std::mbstate_t m;
150 int r = c.length(m, n, n+6, 2);
151 assert(r == 6);
152
153 n[1] = char(0x10);
154 n[0] = char(0x05);
155 r = c.length(m, n, n+2, 2);
156 assert(r == 2);
157
158 n[1] = char(0x04);
159 n[0] = char(0x53);
160 r = c.length(m, n, n+2, 2);
161 assert(r == 2);
162
163 n[1] = char(0x00);
164 n[0] = char(0x56);
165 r = c.length(m, n, n+2, 2);
166 assert(r == 2);
167 }
168 {
169 typedef std::codecvt_utf16<char32_t> C;
170 C c;
171 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
172 std::mbstate_t m;
173 int r = c.length(m, n, n+4, 2);
174 assert(r == 4);
175
176 n[0] = char(0x10);
177 n[1] = char(0x05);
178 r = c.length(m, n, n+2, 2);
179 assert(r == 2);
180
181 n[0] = char(0x04);
182 n[1] = char(0x53);
183 r = c.length(m, n, n+2, 2);
184 assert(r == 2);
185
186 n[0] = char(0x00);
187 n[1] = char(0x56);
188 r = c.length(m, n, n+2, 2);
189 assert(r == 2);
190 }
191 {
192 typedef std::codecvt_utf16<char32_t, 0x1000> C;
193 C c;
194 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
195 std::mbstate_t m;
196 int r = c.length(m, n, n+4, 2);
197 assert(r == 0);
198
199 n[0] = char(0x10);
200 n[1] = char(0x05);
201 r = c.length(m, n, n+2, 2);
202 assert(r == 0);
203
204 n[0] = char(0x04);
205 n[1] = char(0x53);
206 r = c.length(m, n, n+2, 2);
207 assert(r == 2);
208
209 n[0] = char(0x00);
210 n[1] = char(0x56);
211 r = c.length(m, n, n+2, 2);
212 assert(r == 2);
213 }
214 {
215 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::consume_header> C;
216 C c;
217 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
218 std::mbstate_t m;
219 int r = c.length(m, n, n+6, 2);
220 assert(r == 6);
221
222 n[0] = char(0x10);
223 n[1] = char(0x05);
224 r = c.length(m, n, n+2, 2);
225 assert(r == 2);
226
227 n[0] = char(0x04);
228 n[1] = char(0x53);
229 r = c.length(m, n, n+2, 2);
230 assert(r == 2);
231
232 n[0] = char(0x00);
233 n[1] = char(0x56);
234 r = c.length(m, n, n+2, 2);
235 assert(r == 2);
236 }
237 {
238 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::little_endian> C;
239 C c;
240 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
241 std::mbstate_t m;
242 int r = c.length(m, n, n+4, 2);
243 assert(r == 4);
244
245 n[1] = char(0x10);
246 n[0] = char(0x05);
247 r = c.length(m, n, n+2, 2);
248 assert(r == 2);
249
250 n[1] = char(0x04);
251 n[0] = char(0x53);
252 r = c.length(m, n, n+2, 2);
253 assert(r == 2);
254
255 n[1] = char(0x00);
256 n[0] = char(0x56);
257 r = c.length(m, n, n+2, 2);
258 assert(r == 2);
259 }
260 {
261 typedef std::codecvt_utf16<char32_t, 0x1000, std::little_endian> C;
262 C c;
263 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
264 std::mbstate_t m;
265 int r = c.length(m, n, n+4, 2);
266 assert(r == 0);
267
268 n[1] = char(0x10);
269 n[0] = char(0x05);
270 r = c.length(m, n, n+2, 2);
271 assert(r == 0);
272
273 n[1] = char(0x04);
274 n[0] = char(0x53);
275 r = c.length(m, n, n+2, 2);
276 assert(r == 2);
277
278 n[1] = char(0x00);
279 n[0] = char(0x56);
280 r = c.length(m, n, n+2, 2);
281 assert(r == 2);
282 }
283 {
284 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::codecvt_mode(
285 std::consume_header |
286 std::little_endian)> C;
287 C c;
288 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
289 std::mbstate_t m;
290 int r = c.length(m, n, n+6, 2);
291 assert(r == 6);
292
293 n[1] = char(0x10);
294 n[0] = char(0x05);
295 r = c.length(m, n, n+2, 2);
296 assert(r == 2);
297
298 n[1] = char(0x04);
299 n[0] = char(0x53);
300 r = c.length(m, n, n+2, 2);
301 assert(r == 2);
302
303 n[1] = char(0x00);
304 n[0] = char(0x56);
305 r = c.length(m, n, n+2, 2);
306 assert(r == 2);
307 }
308
309 {
310 typedef std::codecvt_utf16<char16_t> C;
311 C c;
312 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
313 std::mbstate_t m;
314 int r = c.length(m, n, n+4, 2);
315 assert(r == 0);
316
317 n[0] = char(0x10);
318 n[1] = char(0x05);
319 r = c.length(m, n, n+2, 2);
320 assert(r == 2);
321
322 n[0] = char(0x04);
323 n[1] = char(0x53);
324 r = c.length(m, n, n+2, 2);
325 assert(r == 2);
326
327 n[0] = char(0x00);
328 n[1] = char(0x56);
329 r = c.length(m, n, n+2, 2);
330 assert(r == 2);
331 }
332 {
333 typedef std::codecvt_utf16<char16_t, 0x1000> C;
334 C c;
335 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
336 std::mbstate_t m;
337 int r = c.length(m, n, n+4, 2);
338 assert(r == 0);
339
340 n[0] = char(0x10);
341 n[1] = char(0x05);
342 r = c.length(m, n, n+2, 2);
343 assert(r == 0);
344
345 n[0] = char(0x04);
346 n[1] = char(0x53);
347 r = c.length(m, n, n+2, 2);
348 assert(r == 2);
349
350 n[0] = char(0x00);
351 n[1] = char(0x56);
352 r = c.length(m, n, n+2, 2);
353 assert(r == 2);
354 }
355 {
356 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::consume_header> C;
357 C c;
358 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
359 std::mbstate_t m;
360 int r = c.length(m, n, n+6, 2);
361 assert(r == 2);
362
363 n[0] = char(0x10);
364 n[1] = char(0x05);
365 r = c.length(m, n, n+2, 2);
366 assert(r == 2);
367
368 n[0] = char(0x04);
369 n[1] = char(0x53);
370 r = c.length(m, n, n+2, 2);
371 assert(r == 2);
372
373 n[0] = char(0x00);
374 n[1] = char(0x56);
375 r = c.length(m, n, n+2, 2);
376 assert(r == 2);
377 }
378 {
379 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::little_endian> C;
380 C c;
381 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
382 std::mbstate_t m;
383 int r = c.length(m, n, n+4, 2);
384 assert(r == 0);
385
386 n[1] = char(0x10);
387 n[0] = char(0x05);
388 r = c.length(m, n, n+2, 2);
389 assert(r == 2);
390
391 n[1] = char(0x04);
392 n[0] = char(0x53);
393 r = c.length(m, n, n+2, 2);
394 assert(r == 2);
395
396 n[1] = char(0x00);
397 n[0] = char(0x56);
398 r = c.length(m, n, n+2, 2);
399 assert(r == 2);
400 }
401 {
402 typedef std::codecvt_utf16<char16_t, 0x1000, std::little_endian> C;
403 C c;
404 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
405 std::mbstate_t m;
406 int r = c.length(m, n, n+4, 2);
407 assert(r == 0);
408
409 n[1] = char(0x10);
410 n[0] = char(0x05);
411 r = c.length(m, n, n+2, 2);
412 assert(r == 0);
413
414 n[1] = char(0x04);
415 n[0] = char(0x53);
416 r = c.length(m, n, n+2, 2);
417 assert(r == 2);
418
419 n[1] = char(0x00);
420 n[0] = char(0x56);
421 r = c.length(m, n, n+2, 2);
422 assert(r == 2);
423 }
424 {
425 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::codecvt_mode(
426 std::consume_header |
427 std::little_endian)> C;
428 C c;
429 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
430 std::mbstate_t m;
431 int r = c.length(m, n, n+6, 2);
432 assert(r == 2);
433
434 n[1] = char(0x10);
435 n[0] = char(0x05);
436 r = c.length(m, n, n+2, 2);
437 assert(r == 2);
438
439 n[1] = char(0x04);
440 n[0] = char(0x53);
441 r = c.length(m, n, n+2, 2);
442 assert(r == 2);
443
444 n[1] = char(0x00);
445 n[0] = char(0x56);
446 r = c.length(m, n, n+2, 2);
447 assert(r == 2);
448 }
449 }
450