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