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