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