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