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