Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Howard Hinnant | 0ce0224 | 2010-09-28 17:19:10 +0000 | [diff] [blame^] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. 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); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 29 | assert(e.what() == std::string("The expression contained an invalid collating element name.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 30 | } |
| 31 | { |
| 32 | std::regex_error e(std::regex_constants::error_ctype); |
| 33 | assert(e.code() == std::regex_constants::error_ctype); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 34 | assert(e.what() == std::string("The expression contained an invalid character class name.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 35 | } |
| 36 | { |
| 37 | std::regex_error e(std::regex_constants::error_escape); |
| 38 | assert(e.code() == std::regex_constants::error_escape); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 39 | assert(e.what() == std::string("The expression contained an invalid escaped character, or a " |
| 40 | "trailing escape.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 41 | } |
| 42 | { |
| 43 | std::regex_error e(std::regex_constants::error_backref); |
| 44 | assert(e.code() == std::regex_constants::error_backref); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 45 | assert(e.what() == std::string("The expression contained an invalid back reference.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 46 | } |
| 47 | { |
| 48 | std::regex_error e(std::regex_constants::error_brack); |
| 49 | assert(e.code() == std::regex_constants::error_brack); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 50 | assert(e.what() == std::string("The expression contained mismatched [ and ].")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 51 | } |
| 52 | { |
| 53 | std::regex_error e(std::regex_constants::error_paren); |
| 54 | assert(e.code() == std::regex_constants::error_paren); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 55 | assert(e.what() == std::string("The expression contained mismatched ( and ).")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 56 | } |
| 57 | { |
| 58 | std::regex_error e(std::regex_constants::error_brace); |
| 59 | assert(e.code() == std::regex_constants::error_brace); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 60 | assert(e.what() == std::string("The expression contained mismatched { and }.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 61 | } |
| 62 | { |
| 63 | std::regex_error e(std::regex_constants::error_badbrace); |
| 64 | assert(e.code() == std::regex_constants::error_badbrace); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 65 | assert(e.what() == std::string("The expression contained an invalid range in a {} expression.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 66 | } |
| 67 | { |
| 68 | std::regex_error e(std::regex_constants::error_range); |
| 69 | assert(e.code() == std::regex_constants::error_range); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 70 | assert(e.what() == std::string("The expression contained an invalid character range, " |
| 71 | "such as [b-a] in most encodings.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 72 | } |
| 73 | { |
| 74 | std::regex_error e(std::regex_constants::error_space); |
| 75 | assert(e.code() == std::regex_constants::error_space); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 76 | assert(e.what() == std::string("There was insufficient memory to convert the expression into " |
| 77 | "a finite state machine.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 78 | } |
| 79 | { |
| 80 | std::regex_error e(std::regex_constants::error_badrepeat); |
| 81 | assert(e.code() == std::regex_constants::error_badrepeat); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 82 | assert(e.what() == std::string("One of *?+{ was not preceded by a valid regular expression.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 83 | } |
| 84 | { |
| 85 | std::regex_error e(std::regex_constants::error_complexity); |
| 86 | assert(e.code() == std::regex_constants::error_complexity); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 87 | assert(e.what() == std::string("The complexity of an attempted match against a regular " |
| 88 | "expression exceeded a pre-set level.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 89 | } |
| 90 | { |
| 91 | std::regex_error e(std::regex_constants::error_stack); |
| 92 | assert(e.code() == std::regex_constants::error_stack); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 93 | assert(e.what() == std::string("There was insufficient memory to determine whether the regular " |
| 94 | "expression could match the specified character sequence.")); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 95 | } |
| 96 | } |