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