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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk), 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk | 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk))); 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::awk | 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::awk))); 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::awk))); 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::awk))); 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::awk); 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 std::cmatch m; 788 const char s[] = "\n\n\n"; 789 assert(std::regex_search(s, m, std::regex("[\\n]+", 790 std::regex_constants::awk))); 791 assert(m.size() == 1); 792 assert(!m.prefix().matched); 793 assert(m.prefix().first == s); 794 assert(m.prefix().second == m[0].first); 795 assert(!m.suffix().matched); 796 assert(m.suffix().first == m[0].second); 797 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 798 assert(m.length(0) == std::char_traits<char>::length(s)); 799 assert(m.position(0) == 0); 800 assert(m.str(0) == s); 801 } 802 { 803 std::wcmatch m; 804 const wchar_t s[] = L"a"; 805 assert(std::regex_search(s, m, std::wregex(L"a", std::regex_constants::awk))); 806 assert(m.size() == 1); 807 assert(!m.empty()); 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+1); 814 assert(m.length(0) == 1); 815 assert(m.position(0) == 0); 816 assert(m.str(0) == L"a"); 817 } 818 { 819 std::wcmatch m; 820 const wchar_t s[] = L"ab"; 821 assert(std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk))); 822 assert(m.size() == 1); 823 assert(!m.prefix().matched); 824 assert(m.prefix().first == s); 825 assert(m.prefix().second == m[0].first); 826 assert(!m.suffix().matched); 827 assert(m.suffix().first == m[0].second); 828 assert(m.suffix().second == s+2); 829 assert(m.length(0) == 2); 830 assert(m.position(0) == 0); 831 assert(m.str(0) == L"ab"); 832 } 833 { 834 std::wcmatch m; 835 const wchar_t s[] = L"ab"; 836 assert(!std::regex_search(s, m, std::wregex(L"ba", std::regex_constants::awk))); 837 assert(m.size() == 0); 838 assert(m.empty()); 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::awk))); 844 assert(m.size() == 1); 845 assert(m.prefix().matched); 846 assert(m.prefix().first == s); 847 assert(m.prefix().second == m[0].first); 848 assert(!m.suffix().matched); 849 assert(m.suffix().first == m[0].second); 850 assert(m.suffix().second == s+3); 851 assert(m.length(0) == 2); 852 assert(m.position(0) == 1); 853 assert(m.str(0) == L"ab"); 854 } 855 { 856 std::wcmatch m; 857 const wchar_t s[] = L"aab"; 858 assert(!std::regex_search(s, m, std::wregex(L"ab", std::regex_constants::awk), 859 std::regex_constants::match_continuous)); 860 assert(m.size() == 0); 861 } 862 { 863 std::wcmatch m; 864 const wchar_t s[] = L"abcd"; 865 assert(std::regex_search(s, m, std::wregex(L"bc", std::regex_constants::awk))); 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) == 2); 874 assert(m.position(0) == 1); 875 assert(m.str(0) == L"bc"); 876 } 877 { 878 std::wcmatch m; 879 const wchar_t s[] = L"abbc"; 880 assert(std::regex_search(s, m, std::wregex(L"ab*c", std::regex_constants::awk))); 881 assert(m.size() == 1); 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+4); 888 assert(m.length(0) == 4); 889 assert(m.position(0) == 0); 890 assert(m.str(0) == s); 891 } 892 { 893 std::wcmatch m; 894 const wchar_t s[] = L"ababc"; 895 assert(std::regex_search(s, m, std::wregex(L"(ab)*c", std::regex_constants::awk))); 896 assert(m.size() == 2); 897 assert(!m.prefix().matched); 898 assert(m.prefix().first == s); 899 assert(m.prefix().second == m[0].first); 900 assert(!m.suffix().matched); 901 assert(m.suffix().first == m[0].second); 902 assert(m.suffix().second == s+5); 903 assert(m.length(0) == 5); 904 assert(m.position(0) == 0); 905 assert(m.str(0) == s); 906 assert(m.length(1) == 2); 907 assert(m.position(1) == 2); 908 assert(m.str(1) == L"ab"); 909 } 910 { 911 std::wcmatch m; 912 const wchar_t s[] = L"abcdefghijk"; 913 assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi", 914 std::regex_constants::awk))); 915 assert(m.size() == 3); 916 assert(m.prefix().matched); 917 assert(m.prefix().first == s); 918 assert(m.prefix().second == m[0].first); 919 assert(m.suffix().matched); 920 assert(m.suffix().first == m[0].second); 921 assert(m.suffix().second == s+std::regex_traits<wchar_t>::length(s)); 922 assert(m.length(0) == 7); 923 assert(m.position(0) == 2); 924 assert(m.str(0) == L"cdefghi"); 925 assert(m.length(1) == 3); 926 assert(m.position(1) == 4); 927 assert(m.str(1) == L"efg"); 928 assert(m.length(2) == 1); 929 assert(m.position(2) == 4); 930 assert(m.str(2) == L"e"); 931 } 932 { 933 std::wcmatch m; 934 const wchar_t s[] = L"abc"; 935 assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk))); 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+3); 943 assert(m.length(0) == 3); 944 assert(m.position(0) == 0); 945 assert(m.str(0) == s); 946 } 947 { 948 std::wcmatch m; 949 const wchar_t s[] = L"abcd"; 950 assert(std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk))); 951 assert(m.size() == 1); 952 assert(!m.prefix().matched); 953 assert(m.prefix().first == s); 954 assert(m.prefix().second == m[0].first); 955 assert(m.suffix().matched); 956 assert(m.suffix().first == m[0].second); 957 assert(m.suffix().second == s+4); 958 assert(m.length(0) == 3); 959 assert(m.position(0) == 0); 960 assert(m.str(0) == L"abc"); 961 } 962 { 963 std::wcmatch m; 964 const wchar_t s[] = L"aabc"; 965 assert(!std::regex_search(s, m, std::wregex(L"^abc", std::regex_constants::awk))); 966 assert(m.size() == 0); 967 } 968 { 969 std::wcmatch m; 970 const wchar_t s[] = L"abc"; 971 assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk))); 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+3); 979 assert(m.length(0) == 3); 980 assert(m.position(0) == 0); 981 assert(m.str(0) == s); 982 } 983 { 984 std::wcmatch m; 985 const wchar_t s[] = L"efabc"; 986 assert(std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk))); 987 assert(m.size() == 1); 988 assert(m.prefix().matched); 989 assert(m.prefix().first == s); 990 assert(m.prefix().second == m[0].first); 991 assert(!m.suffix().matched); 992 assert(m.suffix().first == m[0].second); 993 assert(m.suffix().second == s+5); 994 assert(m.length(0) == 3); 995 assert(m.position(0) == 2); 996 assert(m.str(0) == s+2); 997 } 998 { 999 std::wcmatch m; 1000 const wchar_t s[] = L"efabcg"; 1001 assert(!std::regex_search(s, m, std::wregex(L"abc$", std::regex_constants::awk))); 1002 assert(m.size() == 0); 1003 } 1004 { 1005 std::wcmatch m; 1006 const wchar_t s[] = L"abc"; 1007 assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk))); 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::awk))); 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"acc"; 1037 assert(std::regex_search(s, m, std::wregex(L"a.c", std::regex_constants::awk))); 1038 assert(m.size() == 1); 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+3); 1045 assert(m.length(0) == 3); 1046 assert(m.position(0) == 0); 1047 assert(m.str(0) == s); 1048 } 1049 { 1050 std::wcmatch m; 1051 const wchar_t s[] = L"abcdef"; 1052 assert(std::regex_search(s, m, std::wregex(L"(.*).*", std::regex_constants::awk))); 1053 assert(m.size() == 2); 1054 assert(!m.prefix().matched); 1055 assert(m.prefix().first == s); 1056 assert(m.prefix().second == m[0].first); 1057 assert(!m.suffix().matched); 1058 assert(m.suffix().first == m[0].second); 1059 assert(m.suffix().second == s+6); 1060 assert(m.length(0) == 6); 1061 assert(m.position(0) == 0); 1062 assert(m.str(0) == s); 1063 assert(m.length(1) == 6); 1064 assert(m.position(1) == 0); 1065 assert(m.str(1) == s); 1066 } 1067 { 1068 std::wcmatch m; 1069 const wchar_t s[] = L"bc"; 1070 assert(std::regex_search(s, m, std::wregex(L"(a*)*", std::regex_constants::awk))); 1071 assert(m.size() == 2); 1072 assert(!m.prefix().matched); 1073 assert(m.prefix().first == s); 1074 assert(m.prefix().second == m[0].first); 1075 assert(m.suffix().matched); 1076 assert(m.suffix().first == m[0].second); 1077 assert(m.suffix().second == s+2); 1078 assert(m.length(0) == 0); 1079 assert(m.position(0) == 0); 1080 assert(m.str(0) == L""); 1081 assert(m.length(1) == 0); 1082 assert(m.position(1) == 0); 1083 assert(m.str(1) == L""); 1084 } 1085 { 1086 std::wcmatch m; 1087 const wchar_t s[] = L"abbc"; 1088 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1089 assert(m.size() == 0); 1090 } 1091 { 1092 std::wcmatch m; 1093 const wchar_t s[] = L"abbbc"; 1094 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 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"abbbbc"; 1109 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 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"abbbbbc"; 1124 assert(std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1125 assert(m.size() == 1); 1126 assert(!m.prefix().matched); 1127 assert(m.prefix().first == s); 1128 assert(m.prefix().second == m[0].first); 1129 assert(!m.suffix().matched); 1130 assert(m.suffix().first == m[0].second); 1131 assert(m.suffix().second == m[0].second); 1132 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1133 assert(m.position(0) == 0); 1134 assert(m.str(0) == s); 1135 } 1136 { 1137 std::wcmatch m; 1138 const wchar_t s[] = L"adefc"; 1139 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1140 assert(m.size() == 0); 1141 } 1142 { 1143 std::wcmatch m; 1144 const wchar_t s[] = L"abbbbbbc"; 1145 assert(!std::regex_search(s, m, std::wregex(L"ab{3,5}c", std::regex_constants::awk))); 1146 assert(m.size() == 0); 1147 } 1148 { 1149 std::wcmatch m; 1150 const wchar_t s[] = L"adec"; 1151 assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 1152 assert(m.size() == 0); 1153 } 1154 { 1155 std::wcmatch m; 1156 const wchar_t s[] = L"adefc"; 1157 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 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"adefgc"; 1172 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 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"adefghc"; 1187 assert(std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 1188 assert(m.size() == 1); 1189 assert(!m.prefix().matched); 1190 assert(m.prefix().first == s); 1191 assert(m.prefix().second == m[0].first); 1192 assert(!m.suffix().matched); 1193 assert(m.suffix().first == m[0].second); 1194 assert(m.suffix().second == m[0].second); 1195 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1196 assert(m.position(0) == 0); 1197 assert(m.str(0) == s); 1198 } 1199 { 1200 std::wcmatch m; 1201 const wchar_t s[] = L"adefghic"; 1202 assert(!std::regex_search(s, m, std::wregex(L"a.{3,5}c", std::regex_constants::awk))); 1203 assert(m.size() == 0); 1204 } 1205 { 1206 std::wcmatch m; 1207 const wchar_t s[] = L"tournament"; 1208 assert(std::regex_search(s, m, std::wregex(L"tour|to|tournament", 1209 std::regex_constants::awk))); 1210 assert(m.size() == 1); 1211 assert(!m.prefix().matched); 1212 assert(m.prefix().first == s); 1213 assert(m.prefix().second == m[0].first); 1214 assert(!m.suffix().matched); 1215 assert(m.suffix().first == m[0].second); 1216 assert(m.suffix().second == m[0].second); 1217 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1218 assert(m.position(0) == 0); 1219 assert(m.str(0) == s); 1220 } 1221 { 1222 std::wcmatch m; 1223 const wchar_t s[] = L"tournamenttotour"; 1224 assert(std::regex_search(s, m, std::wregex(L"(tour|to|tournament)+", 1225 std::regex_constants::awk | std::regex_constants::nosubs))); 1226 assert(m.size() == 1); 1227 assert(!m.prefix().matched); 1228 assert(m.prefix().first == s); 1229 assert(m.prefix().second == m[0].first); 1230 assert(!m.suffix().matched); 1231 assert(m.suffix().first == m[0].second); 1232 assert(m.suffix().second == m[0].second); 1233 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1234 assert(m.position(0) == 0); 1235 assert(m.str(0) == s); 1236 } 1237 { 1238 std::wcmatch m; 1239 const wchar_t s[] = L"ttotour"; 1240 assert(std::regex_search(s, m, std::wregex(L"(tour|to|t)+", 1241 std::regex_constants::awk))); 1242 assert(m.size() == 2); 1243 assert(!m.prefix().matched); 1244 assert(m.prefix().first == s); 1245 assert(m.prefix().second == m[0].first); 1246 assert(!m.suffix().matched); 1247 assert(m.suffix().first == m[0].second); 1248 assert(m.suffix().second == m[0].second); 1249 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1250 assert(m.position(0) == 0); 1251 assert(m.str(0) == s); 1252 assert(m.length(1) == 4); 1253 assert(m.position(1) == 3); 1254 assert(m.str(1) == L"tour"); 1255 } 1256 { 1257 std::wcmatch m; 1258 const wchar_t s[] = L"-ab,ab-"; 1259 assert(!std::regex_search(s, m, std::wregex(L"-(.*),\1-", std::regex_constants::awk))); 1260 assert(m.size() == 0); 1261 } 1262 { 1263 std::wcmatch m; 1264 const wchar_t s[] = L"-ab,ab-"; 1265 assert(std::regex_search(s, m, std::wregex(L"-.*,.*-", std::regex_constants::awk))); 1266 assert(m.size() == 1); 1267 assert(!m.prefix().matched); 1268 assert(m.prefix().first == s); 1269 assert(m.prefix().second == m[0].first); 1270 assert(!m.suffix().matched); 1271 assert(m.suffix().first == m[0].second); 1272 assert(m.suffix().second == m[0].second); 1273 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1274 assert(m.position(0) == 0); 1275 assert(m.str(0) == s); 1276 } 1277 { 1278 std::wcmatch m; 1279 const wchar_t s[] = L"a"; 1280 assert(std::regex_search(s, m, std::wregex(L"^[a]$", 1281 std::regex_constants::awk))); 1282 assert(m.size() == 1); 1283 assert(!m.prefix().matched); 1284 assert(m.prefix().first == s); 1285 assert(m.prefix().second == m[0].first); 1286 assert(!m.suffix().matched); 1287 assert(m.suffix().first == m[0].second); 1288 assert(m.suffix().second == m[0].second); 1289 assert(m.length(0) == 1); 1290 assert(m.position(0) == 0); 1291 assert(m.str(0) == L"a"); 1292 } 1293 { 1294 std::wcmatch m; 1295 const wchar_t s[] = L"a"; 1296 assert(std::regex_search(s, m, std::wregex(L"^[ab]$", 1297 std::regex_constants::awk))); 1298 assert(m.size() == 1); 1299 assert(!m.prefix().matched); 1300 assert(m.prefix().first == s); 1301 assert(m.prefix().second == m[0].first); 1302 assert(!m.suffix().matched); 1303 assert(m.suffix().first == m[0].second); 1304 assert(m.suffix().second == m[0].second); 1305 assert(m.length(0) == 1); 1306 assert(m.position(0) == 0); 1307 assert(m.str(0) == L"a"); 1308 } 1309 { 1310 std::wcmatch m; 1311 const wchar_t s[] = L"c"; 1312 assert(std::regex_search(s, m, std::wregex(L"^[a-f]$", 1313 std::regex_constants::awk))); 1314 assert(m.size() == 1); 1315 assert(!m.prefix().matched); 1316 assert(m.prefix().first == s); 1317 assert(m.prefix().second == m[0].first); 1318 assert(!m.suffix().matched); 1319 assert(m.suffix().first == m[0].second); 1320 assert(m.suffix().second == m[0].second); 1321 assert(m.length(0) == 1); 1322 assert(m.position(0) == 0); 1323 assert(m.str(0) == s); 1324 } 1325 { 1326 std::wcmatch m; 1327 const wchar_t s[] = L"g"; 1328 assert(!std::regex_search(s, m, std::wregex(L"^[a-f]$", 1329 std::regex_constants::awk))); 1330 assert(m.size() == 0); 1331 } 1332 { 1333 std::wcmatch m; 1334 const wchar_t s[] = L"Iraqi"; 1335 assert(std::regex_search(s, m, std::wregex(L"q[^u]", 1336 std::regex_constants::awk))); 1337 assert(m.size() == 1); 1338 assert(m.prefix().matched); 1339 assert(m.prefix().first == s); 1340 assert(m.prefix().second == m[0].first); 1341 assert(!m.suffix().matched); 1342 assert(m.suffix().first == m[0].second); 1343 assert(m.suffix().second == m[0].second); 1344 assert(m.length(0) == 2); 1345 assert(m.position(0) == 3); 1346 assert(m.str(0) == L"qi"); 1347 } 1348 { 1349 std::wcmatch m; 1350 const wchar_t s[] = L"Iraq"; 1351 assert(!std::regex_search(s, m, std::wregex(L"q[^u]", 1352 std::regex_constants::awk))); 1353 assert(m.size() == 0); 1354 } 1355 { 1356 std::wcmatch m; 1357 const wchar_t s[] = L"AmB"; 1358 assert(std::regex_search(s, m, std::wregex(L"A[[:lower:]]B", 1359 std::regex_constants::awk))); 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) == 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 std::regex_constants::awk))); 1376 assert(m.size() == 0); 1377 } 1378 { 1379 std::wcmatch m; 1380 const wchar_t s[] = L"AMB"; 1381 assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", 1382 std::regex_constants::awk))); 1383 assert(m.size() == 1); 1384 assert(!m.prefix().matched); 1385 assert(m.prefix().first == s); 1386 assert(m.prefix().second == m[0].first); 1387 assert(!m.suffix().matched); 1388 assert(m.suffix().first == m[0].second); 1389 assert(m.suffix().second == m[0].second); 1390 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1391 assert(m.position(0) == 0); 1392 assert(m.str(0) == s); 1393 } 1394 { 1395 std::wcmatch m; 1396 const wchar_t s[] = L"AmB"; 1397 assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]]B", 1398 std::regex_constants::awk))); 1399 assert(m.size() == 0); 1400 } 1401 { 1402 std::wcmatch m; 1403 const wchar_t s[] = L"A5B"; 1404 assert(!std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B", 1405 std::regex_constants::awk))); 1406 assert(m.size() == 0); 1407 } 1408 { 1409 std::wcmatch m; 1410 const wchar_t s[] = L"A?B"; 1411 assert(std::regex_search(s, m, std::wregex(L"A[^[:lower:]0-9]B", 1412 std::regex_constants::awk))); 1413 assert(m.size() == 1); 1414 assert(!m.prefix().matched); 1415 assert(m.prefix().first == s); 1416 assert(m.prefix().second == m[0].first); 1417 assert(!m.suffix().matched); 1418 assert(m.suffix().first == m[0].second); 1419 assert(m.suffix().second == m[0].second); 1420 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1421 assert(m.position(0) == 0); 1422 assert(m.str(0) == s); 1423 } 1424 { 1425 std::wcmatch m; 1426 const wchar_t s[] = L"-"; 1427 assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", 1428 std::regex_constants::awk))); 1429 assert(m.size() == 1); 1430 assert(!m.prefix().matched); 1431 assert(m.prefix().first == s); 1432 assert(m.prefix().second == m[0].first); 1433 assert(!m.suffix().matched); 1434 assert(m.suffix().first == m[0].second); 1435 assert(m.suffix().second == m[0].second); 1436 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1437 assert(m.position(0) == 0); 1438 assert(m.str(0) == s); 1439 } 1440 { 1441 std::wcmatch m; 1442 const wchar_t s[] = L"z"; 1443 assert(std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", 1444 std::regex_constants::awk))); 1445 assert(m.size() == 1); 1446 assert(!m.prefix().matched); 1447 assert(m.prefix().first == s); 1448 assert(m.prefix().second == m[0].first); 1449 assert(!m.suffix().matched); 1450 assert(m.suffix().first == m[0].second); 1451 assert(m.suffix().second == m[0].second); 1452 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1453 assert(m.position(0) == 0); 1454 assert(m.str(0) == s); 1455 } 1456 { 1457 std::wcmatch m; 1458 const wchar_t s[] = L"m"; 1459 assert(!std::regex_search(s, m, std::wregex(L"[a[.hyphen.]z]", 1460 std::regex_constants::awk))); 1461 assert(m.size() == 0); 1462 } 1463 std::locale::global(std::locale("cs_CZ.ISO8859-2")); 1464 { 1465 std::wcmatch m; 1466 const wchar_t s[] = L"m"; 1467 assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]", 1468 std::regex_constants::awk))); 1469 assert(m.size() == 1); 1470 assert(!m.prefix().matched); 1471 assert(m.prefix().first == s); 1472 assert(m.prefix().second == m[0].first); 1473 assert(!m.suffix().matched); 1474 assert(m.suffix().first == m[0].second); 1475 assert(m.suffix().second == m[0].second); 1476 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1477 assert(m.position(0) == 0); 1478 assert(m.str(0) == s); 1479 } 1480 { 1481 std::wcmatch m; 1482 const wchar_t s[] = L"Ch"; 1483 assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]", 1484 std::regex_constants::awk | std::regex_constants::icase))); 1485 assert(m.size() == 1); 1486 assert(!m.prefix().matched); 1487 assert(m.prefix().first == s); 1488 assert(m.prefix().second == m[0].first); 1489 assert(!m.suffix().matched); 1490 assert(m.suffix().first == m[0].second); 1491 assert(m.suffix().second == m[0].second); 1492 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1493 assert(m.position(0) == 0); 1494 assert(m.str(0) == s); 1495 } 1496 std::locale::global(std::locale("C")); 1497 { 1498 std::wcmatch m; 1499 const wchar_t s[] = L"m"; 1500 assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]", 1501 std::regex_constants::awk))); 1502 assert(m.size() == 0); 1503 } 1504 { 1505 std::wcmatch m; 1506 const wchar_t s[] = L"01a45cef9"; 1507 assert(std::regex_search(s, m, std::wregex(L"[ace1-9]*", 1508 std::regex_constants::awk))); 1509 assert(m.size() == 1); 1510 assert(!m.prefix().matched); 1511 assert(m.prefix().first == s); 1512 assert(m.prefix().second == m[0].first); 1513 assert(m.suffix().matched); 1514 assert(m.suffix().first == m[0].second); 1515 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1516 assert(m.length(0) == 0); 1517 assert(m.position(0) == 0); 1518 assert(m.str(0) == L""); 1519 } 1520 { 1521 std::wcmatch m; 1522 const wchar_t s[] = L"01a45cef9"; 1523 assert(std::regex_search(s, m, std::wregex(L"[ace1-9]+", 1524 std::regex_constants::awk))); 1525 assert(m.size() == 1); 1526 assert(m.prefix().matched); 1527 assert(m.prefix().first == s); 1528 assert(m.prefix().second == m[0].first); 1529 assert(m.suffix().matched); 1530 assert(m.suffix().first == m[0].second); 1531 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1532 assert(m.length(0) == 6); 1533 assert(m.position(0) == 1); 1534 assert(m.str(0) == L"1a45ce"); 1535 } 1536 { 1537 const wchar_t r[] = L"^[-+]?[0-9]+[CF]$"; 1538 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r); 1539 typedef forward_iterator<const wchar_t*> FI; 1540 typedef bidirectional_iterator<const wchar_t*> BI; 1541 std::wregex regex(FI(r), FI(r+sr), std::regex_constants::awk); 1542 std::match_results<BI> m; 1543 const wchar_t s[] = L"-40C"; 1544 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s); 1545 assert(std::regex_search(BI(s), BI(s+ss), m, regex)); 1546 assert(m.size() == 1); 1547 assert(!m.prefix().matched); 1548 assert(m.prefix().first == BI(s)); 1549 assert(m.prefix().second == m[0].first); 1550 assert(!m.suffix().matched); 1551 assert(m.suffix().first == m[0].second); 1552 assert(m.suffix().second == m[0].second); 1553 assert(m.length(0) == 4); 1554 assert(m.position(0) == 0); 1555 assert(m.str(0) == s); 1556 } 1557 { 1558 std::wcmatch m; 1559 const wchar_t s[] = L"\n\n\n"; 1560 assert(std::regex_search(s, m, std::wregex(L"[\\n]+", 1561 std::regex_constants::awk))); 1562 assert(m.size() == 1); 1563 assert(!m.prefix().matched); 1564 assert(m.prefix().first == s); 1565 assert(m.prefix().second == m[0].first); 1566 assert(!m.suffix().matched); 1567 assert(m.suffix().first == m[0].second); 1568 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1569 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1570 assert(m.position(0) == 0); 1571 assert(m.str(0) == s); 1572 } 1573 } 1574