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