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