libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

awk.pass.cpp (60941B)


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