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