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