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 BidirectionalIterator, class Allocator, class charT, class traits>
13 // bool
14 // regex_search(BidirectionalIterator first, BidirectionalIterator last,
15 // match_results<BidirectionalIterator, Allocator>& m,
16 // const basic_regex<charT, traits>& e,
17 // regex_constants::match_flag_type flags = regex_constants::match_default);
18
19 #include <regex>
20 #include <cassert>
21
22 #include "test_iterators.h"
23
main()24 int main()
25 {
26 {
27 std::cmatch m;
28 const char s[] = "a";
29 assert(std::regex_search(s, m, std::regex("a")));
30 assert(m.size() == 1);
31 assert(!m.empty());
32 assert(!m.prefix().matched);
33 assert(m.prefix().first == s);
34 assert(m.prefix().second == m[0].first);
35 assert(!m.suffix().matched);
36 assert(m.suffix().first == m[0].second);
37 assert(m.suffix().second == s+1);
38 assert(m.length(0) == 1);
39 assert(m.position(0) == 0);
40 assert(m.str(0) == "a");
41 }
42 {
43 std::cmatch m;
44 const char s[] = "ab";
45 assert(std::regex_search(s, m, std::regex("ab")));
46 assert(m.size() == 1);
47 assert(!m.prefix().matched);
48 assert(m.prefix().first == s);
49 assert(m.prefix().second == m[0].first);
50 assert(!m.suffix().matched);
51 assert(m.suffix().first == m[0].second);
52 assert(m.suffix().second == s+2);
53 assert(m.length(0) == 2);
54 assert(m.position(0) == 0);
55 assert(m.str(0) == "ab");
56 }
57 {
58 std::cmatch m;
59 const char s[] = "ab";
60 assert(!std::regex_search(s, m, std::regex("ba")));
61 assert(m.size() == 0);
62 assert(m.empty());
63 }
64 {
65 std::cmatch m;
66 const char s[] = "aab";
67 assert(std::regex_search(s, m, std::regex("ab")));
68 assert(m.size() == 1);
69 assert(m.prefix().matched);
70 assert(m.prefix().first == s);
71 assert(m.prefix().second == m[0].first);
72 assert(!m.suffix().matched);
73 assert(m.suffix().first == m[0].second);
74 assert(m.suffix().second == s+3);
75 assert(m.length(0) == 2);
76 assert(m.position(0) == 1);
77 assert(m.str(0) == "ab");
78 }
79 {
80 std::cmatch m;
81 const char s[] = "aab";
82 assert(!std::regex_search(s, m, std::regex("ab"),
83 std::regex_constants::match_continuous));
84 assert(m.size() == 0);
85 }
86 {
87 std::cmatch m;
88 const char s[] = "abcd";
89 assert(std::regex_search(s, m, std::regex("bc")));
90 assert(m.size() == 1);
91 assert(m.prefix().matched);
92 assert(m.prefix().first == s);
93 assert(m.prefix().second == m[0].first);
94 assert(m.suffix().matched);
95 assert(m.suffix().first == m[0].second);
96 assert(m.suffix().second == s+4);
97 assert(m.length(0) == 2);
98 assert(m.position(0) == 1);
99 assert(m.str(0) == "bc");
100 }
101 {
102 std::cmatch m;
103 const char s[] = "abbc";
104 assert(std::regex_search(s, m, std::regex("ab*c")));
105 assert(m.size() == 1);
106 assert(!m.prefix().matched);
107 assert(m.prefix().first == s);
108 assert(m.prefix().second == m[0].first);
109 assert(!m.suffix().matched);
110 assert(m.suffix().first == m[0].second);
111 assert(m.suffix().second == s+4);
112 assert(m.length(0) == 4);
113 assert(m.position(0) == 0);
114 assert(m.str(0) == s);
115 }
116 {
117 std::cmatch m;
118 const char s[] = "ababc";
119 assert(std::regex_search(s, m, std::regex("(ab)*c")));
120 assert(m.size() == 2);
121 assert(!m.prefix().matched);
122 assert(m.prefix().first == s);
123 assert(m.prefix().second == m[0].first);
124 assert(!m.suffix().matched);
125 assert(m.suffix().first == m[0].second);
126 assert(m.suffix().second == s+5);
127 assert(m.length(0) == 5);
128 assert(m.position(0) == 0);
129 assert(m.str(0) == s);
130 assert(m.length(1) == 2);
131 assert(m.position(1) == 2);
132 assert(m.str(1) == "ab");
133 }
134 {
135 std::cmatch m;
136 const char s[] = "abcdefghijk";
137 assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
138 assert(m.size() == 3);
139 assert(m.prefix().matched);
140 assert(m.prefix().first == s);
141 assert(m.prefix().second == m[0].first);
142 assert(m.suffix().matched);
143 assert(m.suffix().first == m[0].second);
144 assert(m.suffix().second == s+std::regex_traits<char>::length(s));
145 assert(m.length(0) == 7);
146 assert(m.position(0) == 2);
147 assert(m.str(0) == "cdefghi");
148 assert(m.length(1) == 3);
149 assert(m.position(1) == 4);
150 assert(m.str(1) == "efg");
151 assert(m.length(2) == 1);
152 assert(m.position(2) == 4);
153 assert(m.str(2) == "e");
154 }
155 {
156 std::cmatch m;
157 const char s[] = "abc";
158 assert(std::regex_search(s, m, std::regex("^abc")));
159 assert(m.size() == 1);
160 assert(!m.prefix().matched);
161 assert(m.prefix().first == s);
162 assert(m.prefix().second == m[0].first);
163 assert(!m.suffix().matched);
164 assert(m.suffix().first == m[0].second);
165 assert(m.suffix().second == s+3);
166 assert(m.length(0) == 3);
167 assert(m.position(0) == 0);
168 assert(m.str(0) == s);
169 }
170 {
171 std::cmatch m;
172 const char s[] = "abcd";
173 assert(std::regex_search(s, m, std::regex("^abc")));
174 assert(m.size() == 1);
175 assert(!m.prefix().matched);
176 assert(m.prefix().first == s);
177 assert(m.prefix().second == m[0].first);
178 assert(m.suffix().matched);
179 assert(m.suffix().first == m[0].second);
180 assert(m.suffix().second == s+4);
181 assert(m.length(0) == 3);
182 assert(m.position(0) == 0);
183 assert(m.str(0) == "abc");
184 }
185 {
186 std::cmatch m;
187 const char s[] = "aabc";
188 assert(!std::regex_search(s, m, std::regex("^abc")));
189 assert(m.size() == 0);
190 }
191 {
192 std::cmatch m;
193 const char s[] = "abc";
194 assert(std::regex_search(s, m, std::regex("abc$")));
195 assert(m.size() == 1);
196 assert(!m.prefix().matched);
197 assert(m.prefix().first == s);
198 assert(m.prefix().second == m[0].first);
199 assert(!m.suffix().matched);
200 assert(m.suffix().first == m[0].second);
201 assert(m.suffix().second == s+3);
202 assert(m.length(0) == 3);
203 assert(m.position(0) == 0);
204 assert(m.str(0) == s);
205 }
206 {
207 std::cmatch m;
208 const char s[] = "efabc";
209 assert(std::regex_search(s, m, std::regex("abc$")));
210 assert(m.size() == 1);
211 assert(m.prefix().matched);
212 assert(m.prefix().first == s);
213 assert(m.prefix().second == m[0].first);
214 assert(!m.suffix().matched);
215 assert(m.suffix().first == m[0].second);
216 assert(m.suffix().second == s+5);
217 assert(m.length(0) == 3);
218 assert(m.position(0) == 2);
219 assert(m.str(0) == s+2);
220 }
221 {
222 std::cmatch m;
223 const char s[] = "efabcg";
224 assert(!std::regex_search(s, m, std::regex("abc$")));
225 assert(m.size() == 0);
226 }
227 {
228 std::cmatch m;
229 const char s[] = "abc";
230 assert(std::regex_search(s, m, std::regex("a.c")));
231 assert(m.size() == 1);
232 assert(!m.prefix().matched);
233 assert(m.prefix().first == s);
234 assert(m.prefix().second == m[0].first);
235 assert(!m.suffix().matched);
236 assert(m.suffix().first == m[0].second);
237 assert(m.suffix().second == s+3);
238 assert(m.length(0) == 3);
239 assert(m.position(0) == 0);
240 assert(m.str(0) == s);
241 }
242 {
243 std::cmatch m;
244 const char s[] = "acc";
245 assert(std::regex_search(s, m, std::regex("a.c")));
246 assert(m.size() == 1);
247 assert(!m.prefix().matched);
248 assert(m.prefix().first == s);
249 assert(m.prefix().second == m[0].first);
250 assert(!m.suffix().matched);
251 assert(m.suffix().first == m[0].second);
252 assert(m.suffix().second == s+3);
253 assert(m.length(0) == 3);
254 assert(m.position(0) == 0);
255 assert(m.str(0) == s);
256 }
257 {
258 std::cmatch m;
259 const char s[] = "acc";
260 assert(std::regex_search(s, m, std::regex("a.c")));
261 assert(m.size() == 1);
262 assert(!m.prefix().matched);
263 assert(m.prefix().first == s);
264 assert(m.prefix().second == m[0].first);
265 assert(!m.suffix().matched);
266 assert(m.suffix().first == m[0].second);
267 assert(m.suffix().second == s+3);
268 assert(m.length(0) == 3);
269 assert(m.position(0) == 0);
270 assert(m.str(0) == s);
271 }
272 {
273 std::cmatch m;
274 const char s[] = "abcdef";
275 assert(std::regex_search(s, m, std::regex("(.*).*")));
276 assert(m.size() == 2);
277 assert(!m.prefix().matched);
278 assert(m.prefix().first == s);
279 assert(m.prefix().second == m[0].first);
280 assert(!m.suffix().matched);
281 assert(m.suffix().first == m[0].second);
282 assert(m.suffix().second == s+6);
283 assert(m.length(0) == 6);
284 assert(m.position(0) == 0);
285 assert(m.str(0) == s);
286 assert(m.length(1) == 6);
287 assert(m.position(1) == 0);
288 assert(m.str(1) == s);
289 }
290 {
291 std::cmatch m;
292 const char s[] = "bc";
293 assert(std::regex_search(s, m, std::regex("(a*)*")));
294 assert(m.size() == 2);
295 assert(!m.prefix().matched);
296 assert(m.prefix().first == s);
297 assert(m.prefix().second == m[0].first);
298 assert(m.suffix().matched);
299 assert(m.suffix().first == m[0].second);
300 assert(m.suffix().second == s+2);
301 assert(m.length(0) == 0);
302 assert(m.position(0) == 0);
303 assert(m.str(0) == "");
304 assert(m.length(1) == 0);
305 assert(m.position(1) == 0);
306 assert(m.str(1) == "");
307 }
308 {
309 std::cmatch m;
310 const char s[] = "abbc";
311 assert(!std::regex_search(s, m, std::regex("ab{3,5}c")));
312 assert(m.size() == 0);
313 }
314 {
315 std::cmatch m;
316 const char s[] = "abbbc";
317 assert(std::regex_search(s, m, std::regex("ab{3,5}c")));
318 assert(m.size() == 1);
319 assert(!m.prefix().matched);
320 assert(m.prefix().first == s);
321 assert(m.prefix().second == m[0].first);
322 assert(!m.suffix().matched);
323 assert(m.suffix().first == m[0].second);
324 assert(m.suffix().second == m[0].second);
325 assert(m.length(0) == std::char_traits<char>::length(s));
326 assert(m.position(0) == 0);
327 assert(m.str(0) == s);
328 }
329 {
330 std::cmatch m;
331 const char s[] = "abbbbc";
332 assert(std::regex_search(s, m, std::regex("ab{3,5}c")));
333 assert(m.size() == 1);
334 assert(!m.prefix().matched);
335 assert(m.prefix().first == s);
336 assert(m.prefix().second == m[0].first);
337 assert(!m.suffix().matched);
338 assert(m.suffix().first == m[0].second);
339 assert(m.suffix().second == m[0].second);
340 assert(m.length(0) == std::char_traits<char>::length(s));
341 assert(m.position(0) == 0);
342 assert(m.str(0) == s);
343 }
344 {
345 std::cmatch m;
346 const char s[] = "abbbbbc";
347 assert(std::regex_search(s, m, std::regex("ab{3,5}c")));
348 assert(m.size() == 1);
349 assert(!m.prefix().matched);
350 assert(m.prefix().first == s);
351 assert(m.prefix().second == m[0].first);
352 assert(!m.suffix().matched);
353 assert(m.suffix().first == m[0].second);
354 assert(m.suffix().second == m[0].second);
355 assert(m.length(0) == std::char_traits<char>::length(s));
356 assert(m.position(0) == 0);
357 assert(m.str(0) == s);
358 }
359 {
360 std::cmatch m;
361 const char s[] = "adefc";
362 assert(!std::regex_search(s, m, std::regex("ab{3,5}c")));
363 assert(m.size() == 0);
364 }
365 {
366 std::cmatch m;
367 const char s[] = "abbbbbbc";
368 assert(!std::regex_search(s, m, std::regex("ab{3,5}c")));
369 assert(m.size() == 0);
370 }
371 {
372 std::cmatch m;
373 const char s[] = "adec";
374 assert(!std::regex_search(s, m, std::regex("a.{3,5}c")));
375 assert(m.size() == 0);
376 }
377 {
378 std::cmatch m;
379 const char s[] = "adefc";
380 assert(std::regex_search(s, m, std::regex("a.{3,5}c")));
381 assert(m.size() == 1);
382 assert(!m.prefix().matched);
383 assert(m.prefix().first == s);
384 assert(m.prefix().second == m[0].first);
385 assert(!m.suffix().matched);
386 assert(m.suffix().first == m[0].second);
387 assert(m.suffix().second == m[0].second);
388 assert(m.length(0) == std::char_traits<char>::length(s));
389 assert(m.position(0) == 0);
390 assert(m.str(0) == s);
391 }
392 {
393 std::cmatch m;
394 const char s[] = "adefgc";
395 assert(std::regex_search(s, m, std::regex("a.{3,5}c")));
396 assert(m.size() == 1);
397 assert(!m.prefix().matched);
398 assert(m.prefix().first == s);
399 assert(m.prefix().second == m[0].first);
400 assert(!m.suffix().matched);
401 assert(m.suffix().first == m[0].second);
402 assert(m.suffix().second == m[0].second);
403 assert(m.length(0) == std::char_traits<char>::length(s));
404 assert(m.position(0) == 0);
405 assert(m.str(0) == s);
406 }
407 {
408 std::cmatch m;
409 const char s[] = "adefghc";
410 assert(std::regex_search(s, m, std::regex("a.{3,5}c")));
411 assert(m.size() == 1);
412 assert(!m.prefix().matched);
413 assert(m.prefix().first == s);
414 assert(m.prefix().second == m[0].first);
415 assert(!m.suffix().matched);
416 assert(m.suffix().first == m[0].second);
417 assert(m.suffix().second == m[0].second);
418 assert(m.length(0) == std::char_traits<char>::length(s));
419 assert(m.position(0) == 0);
420 assert(m.str(0) == s);
421 }
422 {
423 std::cmatch m;
424 const char s[] = "adefghic";
425 assert(!std::regex_search(s, m, std::regex("a.{3,5}c")));
426 assert(m.size() == 0);
427 }
428 {
429 std::cmatch m;
430 const char s[] = "tournament";
431 assert(std::regex_search(s, m, std::regex("tour|to|tournament")));
432 assert(m.size() == 1);
433 assert(!m.prefix().matched);
434 assert(m.prefix().first == s);
435 assert(m.prefix().second == m[0].first);
436 assert(m.suffix().matched);
437 assert(m.suffix().first == m[0].second);
438 assert(m.suffix().second == s + std::char_traits<char>::length(s));
439 assert(m.length(0) == 4);
440 assert(m.position(0) == 0);
441 assert(m.str(0) == "tour");
442 }
443 {
444 std::cmatch m;
445 const char s[] = "tournamenttotour";
446 assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+",
447 std::regex_constants::nosubs)));
448 assert(m.size() == 1);
449 assert(!m.prefix().matched);
450 assert(m.prefix().first == s);
451 assert(m.prefix().second == m[0].first);
452 assert(m.suffix().matched);
453 assert(m.suffix().first == m[0].second);
454 assert(m.suffix().second == s + std::char_traits<char>::length(s));
455 assert(m.length(0) == 4);
456 assert(m.position(0) == 0);
457 assert(m.str(0) == "tour");
458 }
459 {
460 std::cmatch m;
461 const char s[] = "ttotour";
462 assert(std::regex_search(s, m, std::regex("(tour|to|t)+")));
463 assert(m.size() == 2);
464 assert(!m.prefix().matched);
465 assert(m.prefix().first == s);
466 assert(m.prefix().second == m[0].first);
467 assert(!m.suffix().matched);
468 assert(m.suffix().first == m[0].second);
469 assert(m.suffix().second == m[0].second);
470 assert(m.length(0) == std::char_traits<char>::length(s));
471 assert(m.position(0) == 0);
472 assert(m.str(0) == s);
473 assert(m.length(1) == 4);
474 assert(m.position(1) == 3);
475 assert(m.str(1) == "tour");
476 }
477 {
478 std::cmatch m;
479 const char s[] = "-ab,ab-";
480 assert(!std::regex_search(s, m, std::regex("-(.*),\1-")));
481 assert(m.size() == 0);
482 }
483 {
484 std::cmatch m;
485 const char s[] = "-ab,ab-";
486 assert(std::regex_search(s, m, std::regex("-.*,.*-")));
487 assert(m.size() == 1);
488 assert(!m.prefix().matched);
489 assert(m.prefix().first == s);
490 assert(m.prefix().second == m[0].first);
491 assert(!m.suffix().matched);
492 assert(m.suffix().first == m[0].second);
493 assert(m.suffix().second == m[0].second);
494 assert(m.length(0) == std::char_traits<char>::length(s));
495 assert(m.position(0) == 0);
496 assert(m.str(0) == s);
497 }
498 {
499 std::cmatch m;
500 const char s[] = "a";
501 assert(std::regex_search(s, m, std::regex("^[a]$")));
502 assert(m.size() == 1);
503 assert(!m.prefix().matched);
504 assert(m.prefix().first == s);
505 assert(m.prefix().second == m[0].first);
506 assert(!m.suffix().matched);
507 assert(m.suffix().first == m[0].second);
508 assert(m.suffix().second == m[0].second);
509 assert(m.length(0) == 1);
510 assert(m.position(0) == 0);
511 assert(m.str(0) == "a");
512 }
513 {
514 std::cmatch m;
515 const char s[] = "a";
516 assert(std::regex_search(s, m, std::regex("^[ab]$")));
517 assert(m.size() == 1);
518 assert(!m.prefix().matched);
519 assert(m.prefix().first == s);
520 assert(m.prefix().second == m[0].first);
521 assert(!m.suffix().matched);
522 assert(m.suffix().first == m[0].second);
523 assert(m.suffix().second == m[0].second);
524 assert(m.length(0) == 1);
525 assert(m.position(0) == 0);
526 assert(m.str(0) == "a");
527 }
528 {
529 std::cmatch m;
530 const char s[] = "c";
531 assert(std::regex_search(s, m, std::regex("^[a-f]$")));
532 assert(m.size() == 1);
533 assert(!m.prefix().matched);
534 assert(m.prefix().first == s);
535 assert(m.prefix().second == m[0].first);
536 assert(!m.suffix().matched);
537 assert(m.suffix().first == m[0].second);
538 assert(m.suffix().second == m[0].second);
539 assert(m.length(0) == 1);
540 assert(m.position(0) == 0);
541 assert(m.str(0) == s);
542 }
543 {
544 std::cmatch m;
545 const char s[] = "g";
546 assert(!std::regex_search(s, m, std::regex("^[a-f]$")));
547 assert(m.size() == 0);
548 }
549 {
550 std::cmatch m;
551 const char s[] = "Iraqi";
552 assert(std::regex_search(s, m, std::regex("q[^u]")));
553 assert(m.size() == 1);
554 assert(m.prefix().matched);
555 assert(m.prefix().first == s);
556 assert(m.prefix().second == m[0].first);
557 assert(!m.suffix().matched);
558 assert(m.suffix().first == m[0].second);
559 assert(m.suffix().second == m[0].second);
560 assert(m.length(0) == 2);
561 assert(m.position(0) == 3);
562 assert(m.str(0) == "qi");
563 }
564 {
565 std::cmatch m;
566 const char s[] = "Iraq";
567 assert(!std::regex_search(s, m, std::regex("q[^u]")));
568 assert(m.size() == 0);
569 }
570 {
571 std::cmatch m;
572 const char s[] = "AmB";
573 assert(std::regex_search(s, m, std::regex("A[[:lower:]]B")));
574 assert(m.size() == 1);
575 assert(!m.prefix().matched);
576 assert(m.prefix().first == s);
577 assert(m.prefix().second == m[0].first);
578 assert(!m.suffix().matched);
579 assert(m.suffix().first == m[0].second);
580 assert(m.suffix().second == m[0].second);
581 assert(m.length(0) == std::char_traits<char>::length(s));
582 assert(m.position(0) == 0);
583 assert(m.str(0) == s);
584 }
585 {
586 std::cmatch m;
587 const char s[] = "AMB";
588 assert(!std::regex_search(s, m, std::regex("A[[:lower:]]B")));
589 assert(m.size() == 0);
590 }
591 {
592 std::cmatch m;
593 const char s[] = "AMB";
594 assert(std::regex_search(s, m, std::regex("A[^[:lower:]]B")));
595 assert(m.size() == 1);
596 assert(!m.prefix().matched);
597 assert(m.prefix().first == s);
598 assert(m.prefix().second == m[0].first);
599 assert(!m.suffix().matched);
600 assert(m.suffix().first == m[0].second);
601 assert(m.suffix().second == m[0].second);
602 assert(m.length(0) == std::char_traits<char>::length(s));
603 assert(m.position(0) == 0);
604 assert(m.str(0) == s);
605 }
606 {
607 std::cmatch m;
608 const char s[] = "AmB";
609 assert(!std::regex_search(s, m, std::regex("A[^[:lower:]]B")));
610 assert(m.size() == 0);
611 }
612 {
613 std::cmatch m;
614 const char s[] = "A5B";
615 assert(!std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B")));
616 assert(m.size() == 0);
617 }
618 {
619 std::cmatch m;
620 const char s[] = "A?B";
621 assert(std::regex_search(s, m, std::regex("A[^[:lower:]0-9]B")));
622 assert(m.size() == 1);
623 assert(!m.prefix().matched);
624 assert(m.prefix().first == s);
625 assert(m.prefix().second == m[0].first);
626 assert(!m.suffix().matched);
627 assert(m.suffix().first == m[0].second);
628 assert(m.suffix().second == m[0].second);
629 assert(m.length(0) == std::char_traits<char>::length(s));
630 assert(m.position(0) == 0);
631 assert(m.str(0) == s);
632 }
633 {
634 std::cmatch m;
635 const char s[] = "-";
636 assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
637 assert(m.size() == 1);
638 assert(!m.prefix().matched);
639 assert(m.prefix().first == s);
640 assert(m.prefix().second == m[0].first);
641 assert(!m.suffix().matched);
642 assert(m.suffix().first == m[0].second);
643 assert(m.suffix().second == m[0].second);
644 assert(m.length(0) == std::char_traits<char>::length(s));
645 assert(m.position(0) == 0);
646 assert(m.str(0) == s);
647 }
648 {
649 std::cmatch m;
650 const char s[] = "z";
651 assert(std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
652 assert(m.size() == 1);
653 assert(!m.prefix().matched);
654 assert(m.prefix().first == s);
655 assert(m.prefix().second == m[0].first);
656 assert(!m.suffix().matched);
657 assert(m.suffix().first == m[0].second);
658 assert(m.suffix().second == m[0].second);
659 assert(m.length(0) == std::char_traits<char>::length(s));
660 assert(m.position(0) == 0);
661 assert(m.str(0) == s);
662 }
663 {
664 std::cmatch m;
665 const char s[] = "m";
666 assert(!std::regex_search(s, m, std::regex("[a[.hyphen.]z]")));
667 assert(m.size() == 0);
668 }
669 /* Disable locale specific tests on Android because Android's NDK does not
670 * support locales other than "C" and "POSIX".
671 *
672 * https://code.google.com/p/android/issues/detail?id=57313
673 */
674 #if !defined(__ANDROID__)
675 std::locale::global(std::locale("cs_CZ.ISO8859-2"));
676 {
677 std::cmatch m;
678 const char s[] = "m";
679 assert(std::regex_search(s, m, std::regex("[a[=M=]z]")));
680 assert(m.size() == 1);
681 assert(!m.prefix().matched);
682 assert(m.prefix().first == s);
683 assert(m.prefix().second == m[0].first);
684 assert(!m.suffix().matched);
685 assert(m.suffix().first == m[0].second);
686 assert(m.suffix().second == m[0].second);
687 assert(m.length(0) == std::char_traits<char>::length(s));
688 assert(m.position(0) == 0);
689 assert(m.str(0) == s);
690 }
691 {
692 std::cmatch m;
693 const char s[] = "Ch";
694 assert(std::regex_search(s, m, std::regex("[a[.ch.]z]",
695 std::regex_constants::icase)));
696 assert(m.size() == 1);
697 assert(!m.prefix().matched);
698 assert(m.prefix().first == s);
699 assert(m.prefix().second == m[0].first);
700 assert(!m.suffix().matched);
701 assert(m.suffix().first == m[0].second);
702 assert(m.suffix().second == m[0].second);
703 assert(m.length(0) == std::char_traits<char>::length(s));
704 assert(m.position(0) == 0);
705 assert(m.str(0) == s);
706 }
707 std::locale::global(std::locale("C"));
708 #endif
709 {
710 std::cmatch m;
711 const char s[] = "m";
712 assert(!std::regex_search(s, m, std::regex("[a[=M=]z]")));
713 assert(m.size() == 0);
714 }
715 {
716 std::cmatch m;
717 const char s[] = "01a45cef9";
718 assert(std::regex_search(s, m, std::regex("[ace1-9]*")));
719 assert(m.size() == 1);
720 assert(!m.prefix().matched);
721 assert(m.prefix().first == s);
722 assert(m.prefix().second == m[0].first);
723 assert(m.suffix().matched);
724 assert(m.suffix().first == m[0].second);
725 assert(m.suffix().second == s + std::char_traits<char>::length(s));
726 assert(m.length(0) == 0);
727 assert(m.position(0) == 0);
728 assert(m.str(0) == "");
729 }
730 {
731 std::cmatch m;
732 const char s[] = "01a45cef9";
733 assert(std::regex_search(s, m, std::regex("[ace1-9]+")));
734 assert(m.size() == 1);
735 assert(m.prefix().matched);
736 assert(m.prefix().first == s);
737 assert(m.prefix().second == m[0].first);
738 assert(m.suffix().matched);
739 assert(m.suffix().first == m[0].second);
740 assert(m.suffix().second == s + std::char_traits<char>::length(s));
741 assert(m.length(0) == 6);
742 assert(m.position(0) == 1);
743 assert(m.str(0) == "1a45ce");
744 }
745 {
746 const char r[] = "^[-+]?[0-9]+[CF]$";
747 std::ptrdiff_t sr = std::char_traits<char>::length(r);
748 typedef forward_iterator<const char*> FI;
749 typedef bidirectional_iterator<const char*> BI;
750 std::regex regex(FI(r), FI(r+sr));
751 std::match_results<BI> m;
752 const char s[] = "-40C";
753 std::ptrdiff_t ss = std::char_traits<char>::length(s);
754 assert(std::regex_search(BI(s), BI(s+ss), m, regex));
755 assert(m.size() == 1);
756 assert(!m.prefix().matched);
757 assert(m.prefix().first == BI(s));
758 assert(m.prefix().second == m[0].first);
759 assert(!m.suffix().matched);
760 assert(m.suffix().first == m[0].second);
761 assert(m.suffix().second == m[0].second);
762 assert(m.length(0) == 4);
763 assert(m.position(0) == 0);
764 assert(m.str(0) == s);
765 }
766 {
767 std::cmatch m;
768 const char s[] = "Jeff Jeffs ";
769 assert(std::regex_search(s, m, std::regex("Jeff(?=s\\b)")));
770 assert(m.size() == 1);
771 assert(m.prefix().matched);
772 assert(m.prefix().first == s);
773 assert(m.prefix().second == m[0].first);
774 assert(m.suffix().matched);
775 assert(m.suffix().first == m[0].second);
776 assert(m.suffix().second == s + std::char_traits<char>::length(s));
777 assert(m.length(0) == 4);
778 assert(m.position(0) == 5);
779 assert(m.str(0) == "Jeff");
780 }
781 {
782 std::cmatch m;
783 const char s[] = "Jeffs Jeff";
784 assert(std::regex_search(s, m, std::regex("Jeff(?!s\\b)")));
785 assert(m.size() == 1);
786 assert(m.prefix().matched);
787 assert(m.prefix().first == s);
788 assert(m.prefix().second == m[0].first);
789 assert(!m.suffix().matched);
790 assert(m.suffix().first == m[0].second);
791 assert(m.suffix().second == s + std::char_traits<char>::length(s));
792 assert(m.length(0) == 4);
793 assert(m.position(0) == 6);
794 assert(m.str(0) == "Jeff");
795 }
796 {
797 std::cmatch m;
798 const char s[] = "5%k";
799 assert(std::regex_search(s, m, std::regex("\\d[\\W]k")));
800 assert(m.size() == 1);
801 assert(!m.prefix().matched);
802 assert(m.prefix().first == s);
803 assert(m.prefix().second == m[0].first);
804 assert(!m.suffix().matched);
805 assert(m.suffix().first == m[0].second);
806 assert(m.suffix().second == s + std::char_traits<char>::length(s));
807 assert(m.length(0) == std::char_traits<char>::length(s));
808 assert(m.position(0) == 0);
809 assert(m.str(0) == s);
810 }
811
812 {
813 std::wcmatch m;
814 const wchar_t s[] = L"a";
815 assert(std::regex_search(s, m, std::wregex(L"a")));
816 assert(m.size() == 1);
817 assert(!m.empty());
818 assert(!m.prefix().matched);
819 assert(m.prefix().first == s);
820 assert(m.prefix().second == m[0].first);
821 assert(!m.suffix().matched);
822 assert(m.suffix().first == m[0].second);
823 assert(m.suffix().second == s+1);
824 assert(m.length(0) == 1);
825 assert(m.position(0) == 0);
826 assert(m.str(0) == L"a");
827 }
828 {
829 std::wcmatch m;
830 const wchar_t s[] = L"ab";
831 assert(std::regex_search(s, m, std::wregex(L"ab")));
832 assert(m.size() == 1);
833 assert(!m.prefix().matched);
834 assert(m.prefix().first == s);
835 assert(m.prefix().second == m[0].first);
836 assert(!m.suffix().matched);
837 assert(m.suffix().first == m[0].second);
838 assert(m.suffix().second == s+2);
839 assert(m.length(0) == 2);
840 assert(m.position(0) == 0);
841 assert(m.str(0) == L"ab");
842 }
843 {
844 std::wcmatch m;
845 const wchar_t s[] = L"ab";
846 assert(!std::regex_search(s, m, std::wregex(L"ba")));
847 assert(m.size() == 0);
848 assert(m.empty());
849 }
850 {
851 std::wcmatch m;
852 const wchar_t s[] = L"aab";
853 assert(std::regex_search(s, m, std::wregex(L"ab")));
854 assert(m.size() == 1);
855 assert(m.prefix().matched);
856 assert(m.prefix().first == s);
857 assert(m.prefix().second == m[0].first);
858 assert(!m.suffix().matched);
859 assert(m.suffix().first == m[0].second);
860 assert(m.suffix().second == s+3);
861 assert(m.length(0) == 2);
862 assert(m.position(0) == 1);
863 assert(m.str(0) == L"ab");
864 }
865 {
866 std::wcmatch m;
867 const wchar_t s[] = L"aab";
868 assert(!std::regex_search(s, m, std::wregex(L"ab"),
869 std::regex_constants::match_continuous));
870 assert(m.size() == 0);
871 }
872 {
873 std::wcmatch m;
874 const wchar_t s[] = L"abcd";
875 assert(std::regex_search(s, m, std::wregex(L"bc")));
876 assert(m.size() == 1);
877 assert(m.prefix().matched);
878 assert(m.prefix().first == s);
879 assert(m.prefix().second == m[0].first);
880 assert(m.suffix().matched);
881 assert(m.suffix().first == m[0].second);
882 assert(m.suffix().second == s+4);
883 assert(m.length(0) == 2);
884 assert(m.position(0) == 1);
885 assert(m.str(0) == L"bc");
886 }
887 {
888 std::wcmatch m;
889 const wchar_t s[] = L"abbc";
890 assert(std::regex_search(s, m, std::wregex(L"ab*c")));
891 assert(m.size() == 1);
892 assert(!m.prefix().matched);
893 assert(m.prefix().first == s);
894 assert(m.prefix().second == m[0].first);
895 assert(!m.suffix().matched);
896 assert(m.suffix().first == m[0].second);
897 assert(m.suffix().second == s+4);
898 assert(m.length(0) == 4);
899 assert(m.position(0) == 0);
900 assert(m.str(0) == s);
901 }
902 {
903 std::wcmatch m;
904 const wchar_t s[] = L"ababc";
905 assert(std::regex_search(s, m, std::wregex(L"(ab)*c")));
906 assert(m.size() == 2);
907 assert(!m.prefix().matched);
908 assert(m.prefix().first == s);
909 assert(m.prefix().second == m[0].first);
910 assert(!m.suffix().matched);
911 assert(m.suffix().first == m[0].second);
912 assert(m.suffix().second == s+5);
913 assert(m.length(0) == 5);
914 assert(m.position(0) == 0);
915 assert(m.str(0) == s);
916 assert(m.length(1) == 2);
917 assert(m.position(1) == 2);
918 assert(m.str(1) == L"ab");
919 }
920 {
921 std::wcmatch m;
922 const wchar_t s[] = L"abcdefghijk";
923 assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
924 assert(m.size() == 3);
925 assert(m.prefix().matched);
926 assert(m.prefix().first == s);
927 assert(m.prefix().second == m[0].first);
928 assert(m.suffix().matched);
929 assert(m.suffix().first == m[0].second);
930 assert(m.suffix().second == s+std::regex_traits<wchar_t>::length(s));
931 assert(m.length(0) == 7);
932 assert(m.position(0) == 2);
933 assert(m.str(0) == L"cdefghi");
934 assert(m.length(1) == 3);
935 assert(m.position(1) == 4);
936 assert(m.str(1) == L"efg");
937 assert(m.length(2) == 1);
938 assert(m.position(2) == 4);
939 assert(m.str(2) == L"e");
940 }
941 {
942 std::wcmatch m;
943 const wchar_t s[] = L"abc";
944 assert(std::regex_search(s, m, std::wregex(L"^abc")));
945 assert(m.size() == 1);
946 assert(!m.prefix().matched);
947 assert(m.prefix().first == s);
948 assert(m.prefix().second == m[0].first);
949 assert(!m.suffix().matched);
950 assert(m.suffix().first == m[0].second);
951 assert(m.suffix().second == s+3);
952 assert(m.length(0) == 3);
953 assert(m.position(0) == 0);
954 assert(m.str(0) == s);
955 }
956 {
957 std::wcmatch m;
958 const wchar_t s[] = L"abcd";
959 assert(std::regex_search(s, m, std::wregex(L"^abc")));
960 assert(m.size() == 1);
961 assert(!m.prefix().matched);
962 assert(m.prefix().first == s);
963 assert(m.prefix().second == m[0].first);
964 assert(m.suffix().matched);
965 assert(m.suffix().first == m[0].second);
966 assert(m.suffix().second == s+4);
967 assert(m.length(0) == 3);
968 assert(m.position(0) == 0);
969 assert(m.str(0) == L"abc");
970 }
971 {
972 std::wcmatch m;
973 const wchar_t s[] = L"aabc";
974 assert(!std::regex_search(s, m, std::wregex(L"^abc")));
975 assert(m.size() == 0);
976 }
977 {
978 std::wcmatch m;
979 const wchar_t s[] = L"abc";
980 assert(std::regex_search(s, m, std::wregex(L"abc$")));
981 assert(m.size() == 1);
982 assert(!m.prefix().matched);
983 assert(m.prefix().first == s);
984 assert(m.prefix().second == m[0].first);
985 assert(!m.suffix().matched);
986 assert(m.suffix().first == m[0].second);
987 assert(m.suffix().second == s+3);
988 assert(m.length(0) == 3);
989 assert(m.position(0) == 0);
990 assert(m.str(0) == s);
991 }
992 {
993 std::wcmatch m;
994 const wchar_t s[] = L"efabc";
995 assert(std::regex_search(s, m, std::wregex(L"abc$")));
996 assert(m.size() == 1);
997 assert(m.prefix().matched);
998 assert(m.prefix().first == s);
999 assert(m.prefix().second == m[0].first);
1000 assert(!m.suffix().matched);
1001 assert(m.suffix().first == m[0].second);
1002 assert(m.suffix().second == s+5);
1003 assert(m.length(0) == 3);
1004 assert(m.position(0) == 2);
1005 assert(m.str(0) == s+2);
1006 }
1007 {
1008 std::wcmatch m;
1009 const wchar_t s[] = L"efabcg";
1010 assert(!std::regex_search(s, m, std::wregex(L"abc$")));
1011 assert(m.size() == 0);
1012 }
1013 {
1014 std::wcmatch m;
1015 const wchar_t s[] = L"abc";
1016 assert(std::regex_search(s, m, std::wregex(L"a.c")));
1017 assert(m.size() == 1);
1018 assert(!m.prefix().matched);
1019 assert(m.prefix().first == s);
1020 assert(m.prefix().second == m[0].first);
1021 assert(!m.suffix().matched);
1022 assert(m.suffix().first == m[0].second);
1023 assert(m.suffix().second == s+3);
1024 assert(m.length(0) == 3);
1025 assert(m.position(0) == 0);
1026 assert(m.str(0) == s);
1027 }
1028 {
1029 std::wcmatch m;
1030 const wchar_t s[] = L"acc";
1031 assert(std::regex_search(s, m, std::wregex(L"a.c")));
1032 assert(m.size() == 1);
1033 assert(!m.prefix().matched);
1034 assert(m.prefix().first == s);
1035 assert(m.prefix().second == m[0].first);
1036 assert(!m.suffix().matched);
1037 assert(m.suffix().first == m[0].second);
1038 assert(m.suffix().second == s+3);
1039 assert(m.length(0) == 3);
1040 assert(m.position(0) == 0);
1041 assert(m.str(0) == s);
1042 }
1043 {
1044 std::wcmatch m;
1045 const wchar_t s[] = L"acc";
1046 assert(std::regex_search(s, m, std::wregex(L"a.c")));
1047 assert(m.size() == 1);
1048 assert(!m.prefix().matched);
1049 assert(m.prefix().first == s);
1050 assert(m.prefix().second == m[0].first);
1051 assert(!m.suffix().matched);
1052 assert(m.suffix().first == m[0].second);
1053 assert(m.suffix().second == s+3);
1054 assert(m.length(0) == 3);
1055 assert(m.position(0) == 0);
1056 assert(m.str(0) == s);
1057 }
1058 {
1059 std::wcmatch m;
1060 const wchar_t s[] = L"abcdef";
1061 assert(std::regex_search(s, m, std::wregex(L"(.*).*")));
1062 assert(m.size() == 2);
1063 assert(!m.prefix().matched);
1064 assert(m.prefix().first == s);
1065 assert(m.prefix().second == m[0].first);
1066 assert(!m.suffix().matched);
1067 assert(m.suffix().first == m[0].second);
1068 assert(m.suffix().second == s+6);
1069 assert(m.length(0) == 6);
1070 assert(m.position(0) == 0);
1071 assert(m.str(0) == s);
1072 assert(m.length(1) == 6);
1073 assert(m.position(1) == 0);
1074 assert(m.str(1) == s);
1075 }
1076 {
1077 std::wcmatch m;
1078 const wchar_t s[] = L"bc";
1079 assert(std::regex_search(s, m, std::wregex(L"(a*)*")));
1080 assert(m.size() == 2);
1081 assert(!m.prefix().matched);
1082 assert(m.prefix().first == s);
1083 assert(m.prefix().second == m[0].first);
1084 assert(m.suffix().matched);
1085 assert(m.suffix().first == m[0].second);
1086 assert(m.suffix().second == s+2);
1087 assert(m.length(0) == 0);
1088 assert(m.position(0) == 0);
1089 assert(m.str(0) == L"");
1090 assert(m.length(1) == 0);
1091 assert(m.position(1) == 0);
1092 assert(m.str(1) == L"");
1093 }
1094 {
1095 std::wcmatch m;
1096 const wchar_t s[] = L"abbc";
1097 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
1098 assert(m.size() == 0);
1099 }
1100 {
1101 std::wcmatch m;
1102 const wchar_t s[] = L"abbbc";
1103 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
1104 assert(m.size() == 1);
1105 assert(!m.prefix().matched);
1106 assert(m.prefix().first == s);
1107 assert(m.prefix().second == m[0].first);
1108 assert(!m.suffix().matched);
1109 assert(m.suffix().first == m[0].second);
1110 assert(m.suffix().second == m[0].second);
1111 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1112 assert(m.position(0) == 0);
1113 assert(m.str(0) == s);
1114 }
1115 {
1116 std::wcmatch m;
1117 const wchar_t s[] = L"abbbbc";
1118 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
1119 assert(m.size() == 1);
1120 assert(!m.prefix().matched);
1121 assert(m.prefix().first == s);
1122 assert(m.prefix().second == m[0].first);
1123 assert(!m.suffix().matched);
1124 assert(m.suffix().first == m[0].second);
1125 assert(m.suffix().second == m[0].second);
1126 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1127 assert(m.position(0) == 0);
1128 assert(m.str(0) == s);
1129 }
1130 {
1131 std::wcmatch m;
1132 const wchar_t s[] = L"abbbbbc";
1133 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
1134 assert(m.size() == 1);
1135 assert(!m.prefix().matched);
1136 assert(m.prefix().first == s);
1137 assert(m.prefix().second == m[0].first);
1138 assert(!m.suffix().matched);
1139 assert(m.suffix().first == m[0].second);
1140 assert(m.suffix().second == m[0].second);
1141 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1142 assert(m.position(0) == 0);
1143 assert(m.str(0) == s);
1144 }
1145 {
1146 std::wcmatch m;
1147 const wchar_t s[] = L"adefc";
1148 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
1149 assert(m.size() == 0);
1150 }
1151 {
1152 std::wcmatch m;
1153 const wchar_t s[] = L"abbbbbbc";
1154 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c")));
1155 assert(m.size() == 0);
1156 }
1157 {
1158 std::wcmatch m;
1159 const wchar_t s[] = L"adec";
1160 assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
1161 assert(m.size() == 0);
1162 }
1163 {
1164 std::wcmatch m;
1165 const wchar_t s[] = L"adefc";
1166 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
1167 assert(m.size() == 1);
1168 assert(!m.prefix().matched);
1169 assert(m.prefix().first == s);
1170 assert(m.prefix().second == m[0].first);
1171 assert(!m.suffix().matched);
1172 assert(m.suffix().first == m[0].second);
1173 assert(m.suffix().second == m[0].second);
1174 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1175 assert(m.position(0) == 0);
1176 assert(m.str(0) == s);
1177 }
1178 {
1179 std::wcmatch m;
1180 const wchar_t s[] = L"adefgc";
1181 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
1182 assert(m.size() == 1);
1183 assert(!m.prefix().matched);
1184 assert(m.prefix().first == s);
1185 assert(m.prefix().second == m[0].first);
1186 assert(!m.suffix().matched);
1187 assert(m.suffix().first == m[0].second);
1188 assert(m.suffix().second == m[0].second);
1189 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1190 assert(m.position(0) == 0);
1191 assert(m.str(0) == s);
1192 }
1193 {
1194 std::wcmatch m;
1195 const wchar_t s[] = L"adefghc";
1196 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
1197 assert(m.size() == 1);
1198 assert(!m.prefix().matched);
1199 assert(m.prefix().first == s);
1200 assert(m.prefix().second == m[0].first);
1201 assert(!m.suffix().matched);
1202 assert(m.suffix().first == m[0].second);
1203 assert(m.suffix().second == m[0].second);
1204 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1205 assert(m.position(0) == 0);
1206 assert(m.str(0) == s);
1207 }
1208 {
1209 std::wcmatch m;
1210 const wchar_t s[] = L"adefghic";
1211 assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c")));
1212 assert(m.size() == 0);
1213 }
1214 {
1215 std::wcmatch m;
1216 const wchar_t s[] = L"tournament";
1217 assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament")));
1218 assert(m.size() == 1);
1219 assert(!m.prefix().matched);
1220 assert(m.prefix().first == s);
1221 assert(m.prefix().second == m[0].first);
1222 assert(m.suffix().matched);
1223 assert(m.suffix().first == m[0].second);
1224 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1225 assert(m.length(0) == 4);
1226 assert(m.position(0) == 0);
1227 assert(m.str(0) == L"tour");
1228 }
1229 {
1230 std::wcmatch m;
1231 const wchar_t s[] = L"tournamenttotour";
1232 assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+",
1233 std::regex_constants::nosubs)));
1234 assert(m.size() == 1);
1235 assert(!m.prefix().matched);
1236 assert(m.prefix().first == s);
1237 assert(m.prefix().second == m[0].first);
1238 assert(m.suffix().matched);
1239 assert(m.suffix().first == m[0].second);
1240 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1241 assert(m.length(0) == 4);
1242 assert(m.position(0) == 0);
1243 assert(m.str(0) == L"tour");
1244 }
1245 {
1246 std::wcmatch m;
1247 const wchar_t s[] = L"ttotour";
1248 assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+")));
1249 assert(m.size() == 2);
1250 assert(!m.prefix().matched);
1251 assert(m.prefix().first == s);
1252 assert(m.prefix().second == m[0].first);
1253 assert(!m.suffix().matched);
1254 assert(m.suffix().first == m[0].second);
1255 assert(m.suffix().second == m[0].second);
1256 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1257 assert(m.position(0) == 0);
1258 assert(m.str(0) == s);
1259 assert(m.length(1) == 4);
1260 assert(m.position(1) == 3);
1261 assert(m.str(1) == L"tour");
1262 }
1263 {
1264 std::wcmatch m;
1265 const wchar_t s[] = L"-ab,ab-";
1266 assert(!std::regex_search(s, m, std::wregex(L"-(.*),\1-")));
1267 assert(m.size() == 0);
1268 }
1269 {
1270 std::wcmatch m;
1271 const wchar_t s[] = L"-ab,ab-";
1272 assert(std::regex_search(s, m, std::wregex(L"-.*,.*-")));
1273 assert(m.size() == 1);
1274 assert(!m.prefix().matched);
1275 assert(m.prefix().first == s);
1276 assert(m.prefix().second == m[0].first);
1277 assert(!m.suffix().matched);
1278 assert(m.suffix().first == m[0].second);
1279 assert(m.suffix().second == m[0].second);
1280 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1281 assert(m.position(0) == 0);
1282 assert(m.str(0) == s);
1283 }
1284 {
1285 std::wcmatch m;
1286 const wchar_t s[] = L"a";
1287 assert(std::regex_search(s, m, std::wregex(L"^[a]$")));
1288 assert(m.size() == 1);
1289 assert(!m.prefix().matched);
1290 assert(m.prefix().first == s);
1291 assert(m.prefix().second == m[0].first);
1292 assert(!m.suffix().matched);
1293 assert(m.suffix().first == m[0].second);
1294 assert(m.suffix().second == m[0].second);
1295 assert(m.length(0) == 1);
1296 assert(m.position(0) == 0);
1297 assert(m.str(0) == L"a");
1298 }
1299 {
1300 std::wcmatch m;
1301 const wchar_t s[] = L"a";
1302 assert(std::regex_search(s, m, std::wregex(L"^[ab]$")));
1303 assert(m.size() == 1);
1304 assert(!m.prefix().matched);
1305 assert(m.prefix().first == s);
1306 assert(m.prefix().second == m[0].first);
1307 assert(!m.suffix().matched);
1308 assert(m.suffix().first == m[0].second);
1309 assert(m.suffix().second == m[0].second);
1310 assert(m.length(0) == 1);
1311 assert(m.position(0) == 0);
1312 assert(m.str(0) == L"a");
1313 }
1314 {
1315 std::wcmatch m;
1316 const wchar_t s[] = L"c";
1317 assert(std::regex_search(s, m, std::wregex(L"^[a-f]$")));
1318 assert(m.size() == 1);
1319 assert(!m.prefix().matched);
1320 assert(m.prefix().first == s);
1321 assert(m.prefix().second == m[0].first);
1322 assert(!m.suffix().matched);
1323 assert(m.suffix().first == m[0].second);
1324 assert(m.suffix().second == m[0].second);
1325 assert(m.length(0) == 1);
1326 assert(m.position(0) == 0);
1327 assert(m.str(0) == s);
1328 }
1329 {
1330 std::wcmatch m;
1331 const wchar_t s[] = L"g";
1332 assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$")));
1333 assert(m.size() == 0);
1334 }
1335 {
1336 std::wcmatch m;
1337 const wchar_t s[] = L"Iraqi";
1338 assert(std::regex_search(s, m, std::wregex(L"q[^u]")));
1339 assert(m.size() == 1);
1340 assert(m.prefix().matched);
1341 assert(m.prefix().first == s);
1342 assert(m.prefix().second == m[0].first);
1343 assert(!m.suffix().matched);
1344 assert(m.suffix().first == m[0].second);
1345 assert(m.suffix().second == m[0].second);
1346 assert(m.length(0) == 2);
1347 assert(m.position(0) == 3);
1348 assert(m.str(0) == L"qi");
1349 }
1350 {
1351 std::wcmatch m;
1352 const wchar_t s[] = L"Iraq";
1353 assert(!std::regex_search(s, m, std::wregex(L"q[^u]")));
1354 assert(m.size() == 0);
1355 }
1356 {
1357 std::wcmatch m;
1358 const wchar_t s[] = L"AmB";
1359 assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B")));
1360 assert(m.size() == 1);
1361 assert(!m.prefix().matched);
1362 assert(m.prefix().first == s);
1363 assert(m.prefix().second == m[0].first);
1364 assert(!m.suffix().matched);
1365 assert(m.suffix().first == m[0].second);
1366 assert(m.suffix().second == m[0].second);
1367 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1368 assert(m.position(0) == 0);
1369 assert(m.str(0) == s);
1370 }
1371 {
1372 std::wcmatch m;
1373 const wchar_t s[] = L"AMB";
1374 assert(!std::regex_search(s, m, std::wregex(L"A[[:lower:]]B")));
1375 assert(m.size() == 0);
1376 }
1377 {
1378 std::wcmatch m;
1379 const wchar_t s[] = L"AMB";
1380 assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B")));
1381 assert(m.size() == 1);
1382 assert(!m.prefix().matched);
1383 assert(m.prefix().first == s);
1384 assert(m.prefix().second == m[0].first);
1385 assert(!m.suffix().matched);
1386 assert(m.suffix().first == m[0].second);
1387 assert(m.suffix().second == m[0].second);
1388 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1389 assert(m.position(0) == 0);
1390 assert(m.str(0) == s);
1391 }
1392 {
1393 std::wcmatch m;
1394 const wchar_t s[] = L"AmB";
1395 assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B")));
1396 assert(m.size() == 0);
1397 }
1398 {
1399 std::wcmatch m;
1400 const wchar_t s[] = L"A5B";
1401 assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
1402 assert(m.size() == 0);
1403 }
1404 {
1405 std::wcmatch m;
1406 const wchar_t s[] = L"A?B";
1407 assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
1408 assert(m.size() == 1);
1409 assert(!m.prefix().matched);
1410 assert(m.prefix().first == s);
1411 assert(m.prefix().second == m[0].first);
1412 assert(!m.suffix().matched);
1413 assert(m.suffix().first == m[0].second);
1414 assert(m.suffix().second == m[0].second);
1415 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1416 assert(m.position(0) == 0);
1417 assert(m.str(0) == s);
1418 }
1419 {
1420 std::wcmatch m;
1421 const wchar_t s[] = L"-";
1422 assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
1423 assert(m.size() == 1);
1424 assert(!m.prefix().matched);
1425 assert(m.prefix().first == s);
1426 assert(m.prefix().second == m[0].first);
1427 assert(!m.suffix().matched);
1428 assert(m.suffix().first == m[0].second);
1429 assert(m.suffix().second == m[0].second);
1430 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1431 assert(m.position(0) == 0);
1432 assert(m.str(0) == s);
1433 }
1434 {
1435 std::wcmatch m;
1436 const wchar_t s[] = L"z";
1437 assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
1438 assert(m.size() == 1);
1439 assert(!m.prefix().matched);
1440 assert(m.prefix().first == s);
1441 assert(m.prefix().second == m[0].first);
1442 assert(!m.suffix().matched);
1443 assert(m.suffix().first == m[0].second);
1444 assert(m.suffix().second == m[0].second);
1445 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1446 assert(m.position(0) == 0);
1447 assert(m.str(0) == s);
1448 }
1449 {
1450 std::wcmatch m;
1451 const wchar_t s[] = L"m";
1452 assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]")));
1453 assert(m.size() == 0);
1454 }
1455 /* Disable locale specific tests on Android because Android's NDK does not
1456 * support locales other than "C" and "POSIX".
1457 *
1458 * https://code.google.com/p/android/issues/detail?id=57313
1459 */
1460 #if !defined(__ANDROID__)
1461 std::locale::global(std::locale("cs_CZ.ISO8859-2"));
1462 {
1463 std::wcmatch m;
1464 const wchar_t s[] = L"m";
1465 assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
1466 assert(m.size() == 1);
1467 assert(!m.prefix().matched);
1468 assert(m.prefix().first == s);
1469 assert(m.prefix().second == m[0].first);
1470 assert(!m.suffix().matched);
1471 assert(m.suffix().first == m[0].second);
1472 assert(m.suffix().second == m[0].second);
1473 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1474 assert(m.position(0) == 0);
1475 assert(m.str(0) == s);
1476 }
1477 {
1478 std::wcmatch m;
1479 const wchar_t s[] = L"Ch";
1480 assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]",
1481 std::regex_constants::icase)));
1482 assert(m.size() == 1);
1483 assert(!m.prefix().matched);
1484 assert(m.prefix().first == s);
1485 assert(m.prefix().second == m[0].first);
1486 assert(!m.suffix().matched);
1487 assert(m.suffix().first == m[0].second);
1488 assert(m.suffix().second == m[0].second);
1489 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1490 assert(m.position(0) == 0);
1491 assert(m.str(0) == s);
1492 }
1493 std::locale::global(std::locale("C"));
1494 #endif
1495 {
1496 std::wcmatch m;
1497 const wchar_t s[] = L"m";
1498 assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
1499 assert(m.size() == 0);
1500 }
1501 {
1502 std::wcmatch m;
1503 const wchar_t s[] = L"01a45cef9";
1504 assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*")));
1505 assert(m.size() == 1);
1506 assert(!m.prefix().matched);
1507 assert(m.prefix().first == s);
1508 assert(m.prefix().second == m[0].first);
1509 assert(m.suffix().matched);
1510 assert(m.suffix().first == m[0].second);
1511 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1512 assert(m.length(0) == 0);
1513 assert(m.position(0) == 0);
1514 assert(m.str(0) == L"");
1515 }
1516 {
1517 std::wcmatch m;
1518 const wchar_t s[] = L"01a45cef9";
1519 assert(std::regex_search(s, m, std::wregex(L"[ace1-9]+")));
1520 assert(m.size() == 1);
1521 assert(m.prefix().matched);
1522 assert(m.prefix().first == s);
1523 assert(m.prefix().second == m[0].first);
1524 assert(m.suffix().matched);
1525 assert(m.suffix().first == m[0].second);
1526 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1527 assert(m.length(0) == 6);
1528 assert(m.position(0) == 1);
1529 assert(m.str(0) == L"1a45ce");
1530 }
1531 {
1532 const wchar_t r[] = L"^[-+]?[0-9]+[CF]$";
1533 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r);
1534 typedef forward_iterator<const wchar_t*> FI;
1535 typedef bidirectional_iterator<const wchar_t*> BI;
1536 std::wregex regex(FI(r), FI(r+sr));
1537 std::match_results<BI> m;
1538 const wchar_t s[] = L"-40C";
1539 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s);
1540 assert(std::regex_search(BI(s), BI(s+ss), m, regex));
1541 assert(m.size() == 1);
1542 assert(!m.prefix().matched);
1543 assert(m.prefix().first == BI(s));
1544 assert(m.prefix().second == m[0].first);
1545 assert(!m.suffix().matched);
1546 assert(m.suffix().first == m[0].second);
1547 assert(m.suffix().second == m[0].second);
1548 assert(m.length(0) == 4);
1549 assert(m.position(0) == 0);
1550 assert(m.str(0) == s);
1551 }
1552 {
1553 std::wcmatch m;
1554 const wchar_t s[] = L"Jeff Jeffs ";
1555 assert(std::regex_search(s, m, std::wregex(L"Jeff(?=s\\b)")));
1556 assert(m.size() == 1);
1557 assert(m.prefix().matched);
1558 assert(m.prefix().first == s);
1559 assert(m.prefix().second == m[0].first);
1560 assert(m.suffix().matched);
1561 assert(m.suffix().first == m[0].second);
1562 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1563 assert(m.length(0) == 4);
1564 assert(m.position(0) == 5);
1565 assert(m.str(0) == L"Jeff");
1566 }
1567 {
1568 std::wcmatch m;
1569 const wchar_t s[] = L"Jeffs Jeff";
1570 assert(std::regex_search(s, m, std::wregex(L"Jeff(?!s\\b)")));
1571 assert(m.size() == 1);
1572 assert(m.prefix().matched);
1573 assert(m.prefix().first == s);
1574 assert(m.prefix().second == m[0].first);
1575 assert(!m.suffix().matched);
1576 assert(m.suffix().first == m[0].second);
1577 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1578 assert(m.length(0) == 4);
1579 assert(m.position(0) == 6);
1580 assert(m.str(0) == L"Jeff");
1581 }
1582 {
1583 std::wcmatch m;
1584 const wchar_t s[] = L"5%k";
1585 assert(std::regex_search(s, m, std::wregex(L"\\d[\\W]k")));
1586 assert(m.size() == 1);
1587 assert(!m.prefix().matched);
1588 assert(m.prefix().first == s);
1589 assert(m.prefix().second == m[0].first);
1590 assert(!m.suffix().matched);
1591 assert(m.suffix().first == m[0].second);
1592 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1593 assert(m.length(0) == std::char_traits<wchar_t>::length(s));
1594 assert(m.position(0) == 0);
1595 assert(m.str(0) == s);
1596 }
1597 }
1598