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