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