blob: a51b8274bdd84e3ebc4c946945f7bc4184ec60ab [file] [log] [blame]
Howard Hinnant262b7792010-08-17 20:42:03 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant262b7792010-08-17 20:42:03 +00007//
8//===----------------------------------------------------------------------===//
9
10// <regex>
11
12// class regex_token_iterator<BidirectionalIterator, charT, traits>
13
14// template <size_t N>
15// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
16// const regex_type& re,
17// const int (&submatches)[N],
18// regex_constants::match_flag_type m =
19// regex_constants::match_default);
20
21#include <regex>
22#include <cassert>
23
24int main()
25{
26 {
27 std::regex phone_numbers("\\d{3}-(\\d{4})");
28 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
29 const int indices[] = {-1, 0, 1};
Howard Hinnant59832522011-09-21 18:33:46 +000030 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
Howard Hinnant262b7792010-08-17 20:42:03 +000031 phone_numbers, indices);
32 assert(i != std::cregex_token_iterator());
33 assert(i->str() == "start ");
34 ++i;
35 assert(i != std::cregex_token_iterator());
36 assert(i->str() == "555-1234");
37 ++i;
38 assert(i != std::cregex_token_iterator());
39 assert(i->str() == "1234");
40 ++i;
41 assert(i != std::cregex_token_iterator());
42 assert(i->str() == ", ");
43 ++i;
44 assert(i != std::cregex_token_iterator());
45 assert(i->str() == "555-2345");
46 ++i;
47 assert(i != std::cregex_token_iterator());
48 assert(i->str() == "2345");
49 ++i;
50 assert(i != std::cregex_token_iterator());
51 assert(i->str() == ", ");
52 ++i;
53 assert(i != std::cregex_token_iterator());
54 assert(i->str() == "555-3456");
55 ++i;
56 assert(i != std::cregex_token_iterator());
57 assert(i->str() == "3456");
58 ++i;
59 assert(i != std::cregex_token_iterator());
60 assert(i->str() == " end");
61 ++i;
62 assert(i == std::cregex_token_iterator());
63 }
Howard Hinnanta8d77592010-08-18 00:13:08 +000064}