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