Home | History | Annotate | Download | only in re.badexp
      1 // -*- C++ -*-
      2 //===----------------------------------------------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 // <regex>
     12 
     13 // class regex_error
     14 //     : public runtime_error
     15 // {
     16 // public:
     17 //     explicit regex_error(regex_constants::error_type ecode);
     18 //     regex_constants::error_type code() const;
     19 // };
     20 
     21 #include <regex>
     22 #include <cassert>
     23 
     24 int main()
     25 {
     26     {
     27         std::regex_error e(std::regex_constants::error_collate);
     28         assert(e.code() == std::regex_constants::error_collate);
     29         assert(e.what() == std::string("The expression contained an invalid collating element name."));
     30     }
     31     {
     32         std::regex_error e(std::regex_constants::error_ctype);
     33         assert(e.code() == std::regex_constants::error_ctype);
     34         assert(e.what() == std::string("The expression contained an invalid character class name."));
     35     }
     36     {
     37         std::regex_error e(std::regex_constants::error_escape);
     38         assert(e.code() == std::regex_constants::error_escape);
     39         assert(e.what() == std::string("The expression contained an invalid escaped character, or a "
     40                "trailing escape."));
     41     }
     42     {
     43         std::regex_error e(std::regex_constants::error_backref);
     44         assert(e.code() == std::regex_constants::error_backref);
     45         assert(e.what() == std::string("The expression contained an invalid back reference."));
     46     }
     47     {
     48         std::regex_error e(std::regex_constants::error_brack);
     49         assert(e.code() == std::regex_constants::error_brack);
     50         assert(e.what() == std::string("The expression contained mismatched [ and ]."));
     51     }
     52     {
     53         std::regex_error e(std::regex_constants::error_paren);
     54         assert(e.code() == std::regex_constants::error_paren);
     55         assert(e.what() == std::string("The expression contained mismatched ( and )."));
     56     }
     57     {
     58         std::regex_error e(std::regex_constants::error_brace);
     59         assert(e.code() == std::regex_constants::error_brace);
     60         assert(e.what() == std::string("The expression contained mismatched { and }."));
     61     }
     62     {
     63         std::regex_error e(std::regex_constants::error_badbrace);
     64         assert(e.code() == std::regex_constants::error_badbrace);
     65         assert(e.what() == std::string("The expression contained an invalid range in a {} expression."));
     66     }
     67     {
     68         std::regex_error e(std::regex_constants::error_range);
     69         assert(e.code() == std::regex_constants::error_range);
     70         assert(e.what() == std::string("The expression contained an invalid character range, "
     71                "such as [b-a] in most encodings."));
     72     }
     73     {
     74         std::regex_error e(std::regex_constants::error_space);
     75         assert(e.code() == std::regex_constants::error_space);
     76         assert(e.what() == std::string("There was insufficient memory to convert the expression into "
     77                "a finite state machine."));
     78     }
     79     {
     80         std::regex_error e(std::regex_constants::error_badrepeat);
     81         assert(e.code() == std::regex_constants::error_badrepeat);
     82         assert(e.what() == std::string("One of *?+{ was not preceded by a valid regular expression."));
     83     }
     84     {
     85         std::regex_error e(std::regex_constants::error_complexity);
     86         assert(e.code() == std::regex_constants::error_complexity);
     87         assert(e.what() == std::string("The complexity of an attempted match against a regular "
     88                "expression exceeded a pre-set level."));
     89     }
     90     {
     91         std::regex_error e(std::regex_constants::error_stack);
     92         assert(e.code() == std::regex_constants::error_stack);
     93         assert(e.what() == std::string("There was insufficient memory to determine whether the regular "
     94                "expression could match the specified character sequence."));
     95     }
     96 }
     97