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