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