Home | History | Annotate | Download | only in re.alg.search
      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>
     23 #include "test_macros.h"
     24 
     25 int main()
     26 {
     27     // This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...)
     28     // Test for https://bugs.llvm.org/show_bug.cgi?id=16240 fixed in r185273.
     29     {
     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();
     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     {
     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>();
     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 }
     65