1 // regex -*- C++ -*- 2 3 // Copyright (C) 2011-2022 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 // <http://www.gnu.org/licenses/>. 24 25 #include <stdexcept> 26 #include <bits/regex_error.h> 27 #include <bits/functexcept.h> 28 29 namespace std _GLIBCXX_VISIBILITY(default) 30 { 31 _GLIBCXX_BEGIN_NAMESPACE_VERSION 32 33 void __throw_regex_error(regex_constants::error_type __ecode)34 __throw_regex_error(regex_constants::error_type __ecode 35 __attribute__((unused))) 36 { _GLIBCXX_THROW_OR_ABORT(regex_error(__ecode)); } 37 38 namespace 39 { 40 const char* desc(regex_constants::error_type e)41 desc(regex_constants::error_type e) 42 { 43 using namespace regex_constants; 44 switch (e) 45 { 46 case error_collate: 47 return "Invalid collating element in regular expression"; 48 case error_ctype: 49 return "Invalid character class in regular expression"; 50 case error_escape: 51 return "Invalid escape in regular expression"; 52 case error_backref: 53 return "Invalid back reference in regular expression"; 54 case error_brack: 55 return "Mismatched '[' and ']' in regular expression"; 56 case error_paren: 57 return "Mismatched '(' and ')' in regular expression"; 58 case error_brace: 59 return "Mismatched '{' and '}' in regular expression"; 60 case error_badbrace: 61 return "Invalid range in '{}' in regular expression"; 62 case error_range: 63 return "Invalid character range in regular expression"; 64 case error_space: 65 return "Insufficient memory to compile regular expression"; 66 case error_badrepeat: 67 return "Invalid '?', '*', or '+' in regular expression"; 68 case error_complexity: 69 return "Complexity of regex match exceeded implementation limits"; 70 case error_stack: 71 return "Insufficient memory to determine regex match"; 72 case _S_null: 73 return "Unexpected null character in regular expression"; 74 case _S_grammar: 75 return "Conflicting regex grammar options"; 76 default: 77 return "regex error"; 78 }; 79 80 } 81 } 82 regex_error(regex_constants::error_type __ecode)83 regex_error::regex_error(regex_constants::error_type __ecode) 84 : std::runtime_error(desc(__ecode)), _M_code(__ecode) 85 { } 86 ~regex_error()87 regex_error::~regex_error() throw() { } 88 89 _GLIBCXX_END_NAMESPACE_VERSION 90 } // namespace std 91