• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <regex>
11 
12 // template <class BidirectionalIterator, class Allocator, class charT, class traits>
13 //     bool
14 //     regex_search(BidirectionalIterator first, BidirectionalIterator last,
15 //                  match_results<BidirectionalIterator, Allocator>& m,
16 //                  const basic_regex<charT, traits>& e,
17 //                  regex_constants::match_flag_type flags = regex_constants::match_default);
18 
19 #include <regex>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "test_iterators.h"
24 
main()25 int main()
26 {
27     {
28         std::cmatch m;
29         const char s[] = "tournament";
30         assert(std::regex_search(s, m, std::regex("tour\nto\ntournament",
31                 std::regex_constants::egrep)));
32         assert(m.size() == 1);
33         assert(!m.prefix().matched);
34         assert(m.prefix().first == s);
35         assert(m.prefix().second == m[0].first);
36         assert(!m.suffix().matched);
37         assert(m.suffix().first == m[0].second);
38         assert(m.suffix().second == s + std::char_traits<char>::length(s));
39         assert(m.length(0) == 10);
40         assert(m.position(0) == 0);
41         assert(m.str(0) == "tournament");
42     }
43     {
44         std::cmatch m;
45         const char s[] = "ment";
46         assert(std::regex_search(s, m, std::regex("tour\n\ntournament",
47                 std::regex_constants::egrep)));
48         assert(m.size() == 1);
49         assert(!m.prefix().matched);
50         assert(m.prefix().first == s);
51         assert(m.prefix().second == m[0].first);
52         assert(m.suffix().matched);
53         assert(m.suffix().first == m[0].second);
54         assert(m.suffix().second == s + std::char_traits<char>::length(s));
55         assert(m.length(0) == 0);
56         assert(m.position(0) == 0);
57         assert(m.str(0) == "");
58     }
59     {
60         std::cmatch m;
61         const char s[] = "tournament";
62         assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+\ntourna",
63                 std::regex_constants::egrep)));
64         assert(m.size() == 2);
65         assert(!m.prefix().matched);
66         assert(m.prefix().first == s);
67         assert(m.prefix().second == m[0].first);
68         assert(!m.suffix().matched);
69         assert(m.suffix().first == m[0].second);
70         assert(m.suffix().second == s + std::char_traits<char>::length(s));
71         assert(m.length(0) == 10);
72         assert(m.position(0) == 0);
73         assert(m.str(0) == "tournament");
74     }
75     {
76         std::cmatch m;
77         const char s[] = "tourna";
78         assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+\ntourna",
79                 std::regex_constants::egrep)));
80         assert(m.size() == 2);
81         assert(!m.prefix().matched);
82         assert(m.prefix().first == s);
83         assert(m.prefix().second == m[0].first);
84         assert(!m.suffix().matched);
85         assert(m.suffix().first == m[0].second);
86         assert(m.suffix().second == s + std::char_traits<char>::length(s));
87         assert(m.length(0) == 6);
88         assert(m.position(0) == 0);
89         assert(m.str(0) == "tourna");
90     }
91 }
92