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