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