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