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