Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 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 | |
| 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"; |
Howard Hinnant | 5983252 | 2011-09-21 18:33:46 +0000 | [diff] [blame] | 24 | std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 25 | phone_numbers, -1); |
| 26 | assert(i != std::cregex_token_iterator()); |
| 27 | assert((*i).str() == "start "); |
| 28 | ++i; |
| 29 | assert(i != std::cregex_token_iterator()); |
| 30 | assert((*i).str() == ", "); |
| 31 | ++i; |
| 32 | assert(i != std::cregex_token_iterator()); |
| 33 | assert((*i).str() == ", "); |
| 34 | ++i; |
| 35 | assert(i != std::cregex_token_iterator()); |
| 36 | assert((*i).str() == " end"); |
| 37 | ++i; |
| 38 | assert(i == std::cregex_token_iterator()); |
| 39 | } |
| 40 | { |
| 41 | std::regex phone_numbers("\\d{3}-\\d{4}"); |
| 42 | const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; |
Howard Hinnant | 5983252 | 2011-09-21 18:33:46 +0000 | [diff] [blame] | 43 | std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 44 | phone_numbers); |
| 45 | assert(i != std::cregex_token_iterator()); |
| 46 | assert((*i).str() == "555-1234"); |
| 47 | ++i; |
| 48 | assert(i != std::cregex_token_iterator()); |
| 49 | assert((*i).str() == "555-2345"); |
| 50 | ++i; |
| 51 | assert(i != std::cregex_token_iterator()); |
| 52 | assert((*i).str() == "555-3456"); |
| 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"; |
Howard Hinnant | 5983252 | 2011-09-21 18:33:46 +0000 | [diff] [blame] | 59 | std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 60 | phone_numbers, 1); |
| 61 | assert(i != std::cregex_token_iterator()); |
| 62 | assert((*i).str() == "1234"); |
| 63 | ++i; |
| 64 | assert(i != std::cregex_token_iterator()); |
| 65 | assert((*i).str() == "2345"); |
| 66 | ++i; |
| 67 | assert(i != std::cregex_token_iterator()); |
| 68 | assert((*i).str() == "3456"); |
| 69 | ++i; |
| 70 | assert(i == std::cregex_token_iterator()); |
| 71 | } |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 72 | } |