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