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