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