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