Debian Codegraph @

libcxx/test/std/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <regex>
10
11 // class regex_token_iterator<BidirectionalIterator, charT, traits>
12
13 // const value_type& operator*() const;
14
15 #include <regex>
16 #include <cassert>
17 #include <iterator>
18
19 #include "test_macros.h"
20
21 int main(int, char**)
22 {
23 {
24 std::regex phone_numbers("\\d{3}-\\d{4}");
25 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
26 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
27 phone_numbers, -1);
28 assert(i != std::cregex_token_iterator());
29 assert((*i).str() == "start ");
30 ++i;
31 assert(i != std::cregex_token_iterator());
32 assert((*i).str() == ", ");
33 ++i;
34 assert(i != std::cregex_token_iterator());
35 assert((*i).str() == ", ");
36 ++i;
37 assert(i != std::cregex_token_iterator());
38 assert((*i).str() == " end");
39 ++i;
40 assert(i == std::cregex_token_iterator());
41 }
42 {
43 std::regex phone_numbers("\\d{3}-\\d{4}");
44 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
45 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
46 phone_numbers);
47 assert(i != std::cregex_token_iterator());
48 assert((*i).str() == "555-1234");
49 ++i;
50 assert(i != std::cregex_token_iterator());
51 assert((*i).str() == "555-2345");
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 }
58 {
59 std::regex phone_numbers("\\d{3}-(\\d{4})");
60 const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
61 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
62 phone_numbers, 1);
63 assert(i != std::cregex_token_iterator());
64 assert((*i).str() == "1234");
65 ++i;
66 assert(i != std::cregex_token_iterator());
67 assert((*i).str() == "2345");
68 ++i;
69 assert(i != std::cregex_token_iterator());
70 assert((*i).str() == "3456");
71 ++i;
72 assert(i == std::cregex_token_iterator());
73 }
74
75 return 0;
76 }