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