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