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