blob: d8111363c176e1817a9b1070db40f1413fef0555 [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, int submatch = 0,
16// regex_constants::match_flag_type m =
17// regex_constants::match_default);
18
19#include <regex>
20#include <cassert>
21
22int main()
23{
24 {
25 std::regex phone_numbers("\\d{3}-\\d{4}");
26 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
Howard Hinnant59832522011-09-21 18:33:46 +000027 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
Howard Hinnant262b7792010-08-17 20:42:03 +000028 phone_numbers, -1);
29 assert(i != std::cregex_token_iterator());
30 assert(i->str() == "start ");
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() == ", ");
37 ++i;
38 assert(i != std::cregex_token_iterator());
39 assert(i->str() == " end");
40 ++i;
41 assert(i == std::cregex_token_iterator());
42 }
43 {
44 std::regex phone_numbers("\\d{3}-\\d{4}");
45 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
Howard Hinnant59832522011-09-21 18:33:46 +000046 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
Howard Hinnant262b7792010-08-17 20:42:03 +000047 phone_numbers);
48 assert(i != std::cregex_token_iterator());
49 assert(i->str() == "555-1234");
50 ++i;
51 assert(i != std::cregex_token_iterator());
52 assert(i->str() == "555-2345");
53 ++i;
54 assert(i != std::cregex_token_iterator());
55 assert(i->str() == "555-3456");
56 ++i;
57 assert(i == std::cregex_token_iterator());
58 }
59 {
60 std::regex phone_numbers("\\d{3}-(\\d{4})");
61 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
Howard Hinnant59832522011-09-21 18:33:46 +000062 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
Howard Hinnant262b7792010-08-17 20:42:03 +000063 phone_numbers, 1);
64 assert(i != std::cregex_token_iterator());
65 assert(i->str() == "1234");
66 ++i;
67 assert(i != std::cregex_token_iterator());
68 assert(i->str() == "2345");
69 ++i;
70 assert(i != std::cregex_token_iterator());
71 assert(i->str() == "3456");
72 ++i;
73 assert(i == std::cregex_token_iterator());
74 }
Howard Hinnanta8d77592010-08-18 00:13:08 +000075}