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