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_match(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_iterators.h" 23 24 int main() 25 { 26 { 27 std::cmatch m; 28 const char s[] = "tournament"; 29 assert(std::regex_match(s, m, std::regex("tour\nto\ntournament", 30 std::regex_constants::egrep))); 31 assert(m.size() == 1); 32 assert(!m.prefix().matched); 33 assert(m.prefix().first == s); 34 assert(m.prefix().second == m[0].first); 35 assert(!m.suffix().matched); 36 assert(m.suffix().first == m[0].second); 37 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 38 assert(m.length(0) == 10); 39 assert(m.position(0) == 0); 40 assert(m.str(0) == "tournament"); 41 } 42 { 43 std::cmatch m; 44 const char s[] = "ment"; 45 assert(!std::regex_match(s, m, std::regex("tour\n\ntournament", 46 std::regex_constants::egrep))); 47 assert(m.size() == 0); 48 } 49 { 50 std::cmatch m; 51 const char s[] = "tournament"; 52 assert(std::regex_match(s, m, std::regex("(tour|to|tournament)+\ntourna", 53 std::regex_constants::egrep))); 54 assert(m.size() == 2); 55 assert(!m.prefix().matched); 56 assert(m.prefix().first == s); 57 assert(m.prefix().second == m[0].first); 58 assert(!m.suffix().matched); 59 assert(m.suffix().first == m[0].second); 60 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 61 assert(m.length(0) == 10); 62 assert(m.position(0) == 0); 63 assert(m.str(0) == "tournament"); 64 } 65 { 66 std::cmatch m; 67 const char s[] = "tourna"; 68 assert(std::regex_match(s, m, std::regex("(tour|to|tournament)+\ntourna", 69 std::regex_constants::egrep))); 70 assert(m.size() == 2); 71 assert(!m.prefix().matched); 72 assert(m.prefix().first == s); 73 assert(m.prefix().second == m[0].first); 74 assert(!m.suffix().matched); 75 assert(m.suffix().first == m[0].second); 76 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 77 assert(m.length(0) == 6); 78 assert(m.position(0) == 0); 79 assert(m.str(0) == "tourna"); 80 } 81 } 82