Home | History | Annotate | Download | only in re.tokiter.deref
      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 // const value_type& operator*() const;
     15 
     16 #include <regex>
     17 #include <cassert>
     18 #include "test_macros.h"
     19 
     20 int main()
     21 {
     22     {
     23         std::regex phone_numbers("\\d{3}-\\d{4}");
     24         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
     25         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
     26                                      phone_numbers, -1);
     27         assert(i != std::cregex_token_iterator());
     28         assert((*i).str() == "start ");
     29         ++i;
     30         assert(i != std::cregex_token_iterator());
     31         assert((*i).str() == ", ");
     32         ++i;
     33         assert(i != std::cregex_token_iterator());
     34         assert((*i).str() == ", ");
     35         ++i;
     36         assert(i != std::cregex_token_iterator());
     37         assert((*i).str() == " end");
     38         ++i;
     39         assert(i == std::cregex_token_iterator());
     40     }
     41     {
     42         std::regex phone_numbers("\\d{3}-\\d{4}");
     43         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
     44         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
     45                                      phone_numbers);
     46         assert(i != std::cregex_token_iterator());
     47         assert((*i).str() == "555-1234");
     48         ++i;
     49         assert(i != std::cregex_token_iterator());
     50         assert((*i).str() == "555-2345");
     51         ++i;
     52         assert(i != std::cregex_token_iterator());
     53         assert((*i).str() == "555-3456");
     54         ++i;
     55         assert(i == std::cregex_token_iterator());
     56     }
     57     {
     58         std::regex phone_numbers("\\d{3}-(\\d{4})");
     59         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
     60         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
     61                                      phone_numbers, 1);
     62         assert(i != std::cregex_token_iterator());
     63         assert((*i).str() == "1234");
     64         ++i;
     65         assert(i != std::cregex_token_iterator());
     66         assert((*i).str() == "2345");
     67         ++i;
     68         assert(i != std::cregex_token_iterator());
     69         assert((*i).str() == "3456");
     70         ++i;
     71         assert(i == std::cregex_token_iterator());
     72     }
     73 }
     74