Howard Hinnant | c815a4e | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 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 <string> |
| 21 | #include <list> |
| 22 | #include <cassert> |
Marshall Clow | fd5ceb2 | 2016-04-26 16:24:44 +0000 | [diff] [blame] | 23 | #include "test_macros.h" |
Howard Hinnant | c815a4e | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 24 | |
| 25 | int main() |
| 26 | { |
| 27 | // This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...) |
Eric Fiselier | 3c35491 | 2017-02-17 08:37:03 +0000 | [diff] [blame] | 28 | // Test for https://bugs.llvm.org/show_bug.cgi?id=16240 fixed in r185273. |
Howard Hinnant | c815a4e | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 29 | { |
Eric Fiselier | aae7649 | 2014-10-27 19:29:32 +0000 | [diff] [blame] | 30 | std::string s("aaaa a"); |
| 31 | std::regex re("\\ba"); |
| 32 | std::sregex_iterator it(s.begin(), s.end(), re); |
| 33 | std::sregex_iterator end = std::sregex_iterator(); |
Howard Hinnant | c815a4e | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 34 | |
| 35 | assert(it->position(0) == 0); |
| 36 | assert(it->length(0) == 1); |
| 37 | |
| 38 | ++it; |
| 39 | assert(it->position(0) == 5); |
| 40 | assert(it->length(0) == 1); |
| 41 | |
| 42 | ++it; |
| 43 | assert(it == end); |
| 44 | } |
| 45 | |
| 46 | // This regex_iterator uses regex_search(_BidirectionalIterator __first, ...) |
| 47 | { |
Eric Fiselier | aae7649 | 2014-10-27 19:29:32 +0000 | [diff] [blame] | 48 | std::string s("aaaa a"); |
| 49 | std::list<char> l(s.begin(), s.end()); |
| 50 | std::regex re("\\ba"); |
| 51 | std::regex_iterator<std::list<char>::iterator> it(l.begin(), l.end(), re); |
| 52 | std::regex_iterator<std::list<char>::iterator> end = std::regex_iterator<std::list<char>::iterator>(); |
Howard Hinnant | c815a4e | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 53 | |
| 54 | assert(it->position(0) == 0); |
| 55 | assert(it->length(0) == 1); |
| 56 | |
| 57 | ++it; |
| 58 | assert(it->position(0) == 5); |
| 59 | assert(it->length(0) == 1); |
| 60 | |
| 61 | ++it; |
| 62 | assert(it == end); |
| 63 | } |
| 64 | } |