brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 22d5221 Raw
66 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 <string>20#include <list>21#include <cassert>22#include "test_macros.h"23 24int main(int, char**)25{26    // This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...)27    // Test for https://llvm.org/PR16240 fixed in r185273.28    {29        std::string s("aaaa a");30        std::regex re("\\ba");31        std::sregex_iterator it(s.begin(), s.end(), re);32        std::sregex_iterator end = std::sregex_iterator();33 34        assert(it->position(0) == 0);35        assert(it->length(0) == 1);36 37        ++it;38        assert(it->position(0) == 5);39        assert(it->length(0) == 1);40 41        ++it;42        assert(it == end);43    }44 45    // This regex_iterator uses regex_search(_BidirectionalIterator __first, ...)46    {47        std::string s("aaaa a");48        std::list<char> l(s.begin(), s.end());49        std::regex re("\\ba");50        std::regex_iterator<std::list<char>::iterator> it(l.begin(), l.end(), re);51        std::regex_iterator<std::list<char>::iterator> end = std::regex_iterator<std::list<char>::iterator>();52 53        assert(it->position(0) == 0);54        assert(it->length(0) == 1);55 56        ++it;57        assert(it->position(0) == 5);58        assert(it->length(0) == 1);59 60        ++it;61        assert(it == end);62    }63 64  return 0;65}66