Home | History | Annotate | Download | only in re.regex.construct
      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 charT, class traits = regex_traits<charT>> class basic_regex;
     13 
     14 // template <class ST, class SA>
     15 //    basic_regex(const basic_string<charT, ST, SA>& s,
     16 //                flag_type f = regex_constants::ECMAScript);
     17 
     18 #include <regex>
     19 #include <cassert>
     20 
     21 template <class String>
     22 void
     23 test(const String& p, std::regex_constants::syntax_option_type f, unsigned mc)
     24 {
     25     std::basic_regex<typename String::value_type> r(p, f);
     26     assert(r.flags() == f);
     27     assert(r.mark_count() == mc);
     28 }
     29 
     30 int main()
     31 {
     32     test(std::string("\\(a\\)"), std::regex_constants::basic, 1);
     33     test(std::string("\\(a[bc]\\)"), std::regex_constants::basic, 1);
     34     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::basic, 2);
     35     test(std::string("(a([bc]))"), std::regex_constants::basic, 0);
     36 
     37     test(std::string("\\(a\\)"), std::regex_constants::extended, 0);
     38     test(std::string("\\(a[bc]\\)"), std::regex_constants::extended, 0);
     39     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::extended, 0);
     40     test(std::string("(a([bc]))"), std::regex_constants::extended, 2);
     41 
     42     test(std::string("\\(a\\)"), std::regex_constants::ECMAScript, 0);
     43     test(std::string("\\(a[bc]\\)"), std::regex_constants::ECMAScript, 0);
     44     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::ECMAScript, 0);
     45     test(std::string("(a([bc]))"), std::regex_constants::ECMAScript, 2);
     46 
     47     test(std::string("\\(a\\)"), std::regex_constants::awk, 0);
     48     test(std::string("\\(a[bc]\\)"), std::regex_constants::awk, 0);
     49     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::awk, 0);
     50     test(std::string("(a([bc]))"), std::regex_constants::awk, 2);
     51 
     52     test(std::string("\\(a\\)"), std::regex_constants::grep, 1);
     53     test(std::string("\\(a[bc]\\)"), std::regex_constants::grep, 1);
     54     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::grep, 2);
     55     test(std::string("(a([bc]))"), std::regex_constants::grep, 0);
     56 
     57     test(std::string("\\(a\\)"), std::regex_constants::egrep, 0);
     58     test(std::string("\\(a[bc]\\)"), std::regex_constants::egrep, 0);
     59     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::egrep, 0);
     60     test(std::string("(a([bc]))"), std::regex_constants::egrep, 2);
     61 }
     62