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