93 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <regex>10 11// template <class BidirectionalIterator, class Allocator, class charT, class traits>12// bool13// regex_search(BidirectionalIterator first, BidirectionalIterator last,14// match_results<BidirectionalIterator, Allocator>& m,15// const basic_regex<charT, traits>& e,16// regex_constants::match_flag_type flags = regex_constants::match_default);17 18#include <regex>19#include <cassert>20 21#include "test_macros.h"22#include "test_iterators.h"23 24int main(int, char**)25{26 {27 std::cmatch m;28 const char s[] = "tournament";29 assert(std::regex_search(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_search(s, m, std::regex("tour\n\ntournament",46 std::regex_constants::egrep)));47 assert(m.size() == 1);48 assert(!m.prefix().matched);49 assert(m.prefix().first == s);50 assert(m.prefix().second == m[0].first);51 assert(m.suffix().matched);52 assert(m.suffix().first == m[0].second);53 assert(m.suffix().second == s + std::char_traits<char>::length(s));54 assert(m.length(0) == 0);55 assert(m.position(0) == 0);56 assert(m.str(0) == "");57 }58 {59 std::cmatch m;60 const char s[] = "tournament";61 assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+\ntourna",62 std::regex_constants::egrep)));63 assert(m.size() == 2);64 assert(!m.prefix().matched);65 assert(m.prefix().first == s);66 assert(m.prefix().second == m[0].first);67 assert(!m.suffix().matched);68 assert(m.suffix().first == m[0].second);69 assert(m.suffix().second == s + std::char_traits<char>::length(s));70 assert(m.length(0) == 10);71 assert(m.position(0) == 0);72 assert(m.str(0) == "tournament");73 }74 {75 std::cmatch m;76 const char s[] = "tourna";77 assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+\ntourna",78 std::regex_constants::egrep)));79 assert(m.size() == 2);80 assert(!m.prefix().matched);81 assert(m.prefix().first == s);82 assert(m.prefix().second == m[0].first);83 assert(!m.suffix().matched);84 assert(m.suffix().first == m[0].second);85 assert(m.suffix().second == s + std::char_traits<char>::length(s));86 assert(m.length(0) == 6);87 assert(m.position(0) == 0);88 assert(m.str(0) == "tourna");89 }90 91 return 0;92}93