Home | History | Annotate | Download | only in re.tokiter.cnstr
      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 // class regex_token_iterator<BidirectionalIterator, charT, traits>
     13 
     14 // regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
     15 //                      const regex_type& re,
     16 //                      const std::vector<int>& submatches,
     17 //                      regex_constants::match_flag_type m =
     18 //                                              regex_constants::match_default);
     19 
     20 #include <regex>
     21 #include <cassert>
     22 
     23 int main()
     24 {
     25     {
     26         std::regex phone_numbers("\\d{3}-(\\d{4})");
     27         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
     28         std::vector<int> v;
     29         v.push_back(-1);
     30         v.push_back(-1);
     31         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
     32                                      phone_numbers, v);
     33         assert(i != std::cregex_token_iterator());
     34         assert(i->str() == "start ");
     35         ++i;
     36         assert(i != std::cregex_token_iterator());
     37         assert(i->str() == "start ");
     38         ++i;
     39         assert(i != std::cregex_token_iterator());
     40         assert(i->str() == ", ");
     41         ++i;
     42         assert(i != std::cregex_token_iterator());
     43         assert(i->str() == ", ");
     44         ++i;
     45         assert(i != std::cregex_token_iterator());
     46         assert(i->str() == ", ");
     47         ++i;
     48         assert(i != std::cregex_token_iterator());
     49         assert(i->str() == ", ");
     50         ++i;
     51         assert(i != std::cregex_token_iterator());
     52         assert(i->str() == " end");
     53         ++i;
     54         assert(i == std::cregex_token_iterator());
     55     }
     56     {
     57         std::regex phone_numbers("\\d{3}-(\\d{4})");
     58         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
     59         std::vector<int> v;
     60         v.push_back(-1);
     61         v.push_back(0);
     62         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
     63                                      phone_numbers, v);
     64         assert(i != std::cregex_token_iterator());
     65         assert(i->str() == "start ");
     66         ++i;
     67         assert(i != std::cregex_token_iterator());
     68         assert(i->str() == "555-1234");
     69         ++i;
     70         assert(i != std::cregex_token_iterator());
     71         assert(i->str() == ", ");
     72         ++i;
     73         assert(i != std::cregex_token_iterator());
     74         assert(i->str() == "555-2345");
     75         ++i;
     76         assert(i != std::cregex_token_iterator());
     77         assert(i->str() == ", ");
     78         ++i;
     79         assert(i != std::cregex_token_iterator());
     80         assert(i->str() == "555-3456");
     81         ++i;
     82         assert(i != std::cregex_token_iterator());
     83         assert(i->str() == " end");
     84         ++i;
     85         assert(i == std::cregex_token_iterator());
     86     }
     87     {
     88         std::regex phone_numbers("\\d{3}-(\\d{4})");
     89         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
     90         std::vector<int> v;
     91         v.push_back(-1);
     92         v.push_back(0);
     93         v.push_back(1);
     94         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
     95                                      phone_numbers, v);
     96         assert(i != std::cregex_token_iterator());
     97         assert(i->str() == "start ");
     98         ++i;
     99         assert(i != std::cregex_token_iterator());
    100         assert(i->str() == "555-1234");
    101         ++i;
    102         assert(i != std::cregex_token_iterator());
    103         assert(i->str() == "1234");
    104         ++i;
    105         assert(i != std::cregex_token_iterator());
    106         assert(i->str() == ", ");
    107         ++i;
    108         assert(i != std::cregex_token_iterator());
    109         assert(i->str() == "555-2345");
    110         ++i;
    111         assert(i != std::cregex_token_iterator());
    112         assert(i->str() == "2345");
    113         ++i;
    114         assert(i != std::cregex_token_iterator());
    115         assert(i->str() == ", ");
    116         ++i;
    117         assert(i != std::cregex_token_iterator());
    118         assert(i->str() == "555-3456");
    119         ++i;
    120         assert(i != std::cregex_token_iterator());
    121         assert(i->str() == "3456");
    122         ++i;
    123         assert(i != std::cregex_token_iterator());
    124         assert(i->str() == " end");
    125         ++i;
    126         assert(i == std::cregex_token_iterator());
    127     }
    128 }
    129