blob: b40d7eb9224dea6d46bbadb03b651daf9bc0b350 [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// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
15// const regex_type& re,
16// initializer_list<int> submatches,
17// regex_constants::match_flag_type m =
18// regex_constants::match_default);
19
20#include <regex>
21#include <cassert>
22
23int main()
24{
Howard Hinnante3e32912011-08-12 21:56:02 +000025#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant262b7792010-08-17 20:42:03 +000026 {
27 std::regex phone_numbers("\\d{3}-(\\d{4})");
28 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
Howard Hinnant59832522011-09-21 18:33:46 +000029 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
Howard Hinnant262b7792010-08-17 20:42:03 +000030 phone_numbers, {-1, 0, 1});
31 assert(i != std::cregex_token_iterator());
32 assert(i->str() == "start ");
33 ++i;
34 assert(i != std::cregex_token_iterator());
35 assert(i->str() == "555-1234");
36 ++i;
37 assert(i != std::cregex_token_iterator());
38 assert(i->str() == "1234");
39 ++i;
40 assert(i != std::cregex_token_iterator());
41 assert(i->str() == ", ");
42 ++i;
43 assert(i != std::cregex_token_iterator());
44 assert(i->str() == "555-2345");
45 ++i;
46 assert(i != std::cregex_token_iterator());
47 assert(i->str() == "2345");
48 ++i;
49 assert(i != std::cregex_token_iterator());
50 assert(i->str() == ", ");
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 assert(i->str() == "3456");
57 ++i;
58 assert(i != std::cregex_token_iterator());
59 assert(i->str() == " end");
60 ++i;
61 assert(i == std::cregex_token_iterator());
62 }
Howard Hinnante3e32912011-08-12 21:56:02 +000063#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnanta8d77592010-08-18 00:13:08 +000064}