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