regex_error.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // class template regex -*- C++ -*-
  2. // Copyright (C) 2010-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /**
  21. * @file bits/regex_error.h
  22. * @brief Error and exception objects for the std regex library.
  23. *
  24. * This is an internal header file, included by other library headers.
  25. * Do not attempt to use it directly. @headername{regex}
  26. */
  27. namespace std _GLIBCXX_VISIBILITY(default)
  28. {
  29. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  30. /**
  31. * @addtogroup regex
  32. * @{
  33. */
  34. namespace regex_constants
  35. {
  36. /**
  37. * @name 5.3 Error Types
  38. */
  39. //@{
  40. enum error_type
  41. {
  42. _S_error_collate,
  43. _S_error_ctype,
  44. _S_error_escape,
  45. _S_error_backref,
  46. _S_error_brack,
  47. _S_error_paren,
  48. _S_error_brace,
  49. _S_error_badbrace,
  50. _S_error_range,
  51. _S_error_space,
  52. _S_error_badrepeat,
  53. _S_error_complexity,
  54. _S_error_stack,
  55. };
  56. /** The expression contained an invalid collating element name. */
  57. constexpr error_type error_collate(_S_error_collate);
  58. /** The expression contained an invalid character class name. */
  59. constexpr error_type error_ctype(_S_error_ctype);
  60. /**
  61. * The expression contained an invalid escaped character, or a trailing
  62. * escape.
  63. */
  64. constexpr error_type error_escape(_S_error_escape);
  65. /** The expression contained an invalid back reference. */
  66. constexpr error_type error_backref(_S_error_backref);
  67. /** The expression contained mismatched [ and ]. */
  68. constexpr error_type error_brack(_S_error_brack);
  69. /** The expression contained mismatched ( and ). */
  70. constexpr error_type error_paren(_S_error_paren);
  71. /** The expression contained mismatched { and } */
  72. constexpr error_type error_brace(_S_error_brace);
  73. /** The expression contained an invalid range in a {} expression. */
  74. constexpr error_type error_badbrace(_S_error_badbrace);
  75. /**
  76. * The expression contained an invalid character range,
  77. * such as [b-a] in most encodings.
  78. */
  79. constexpr error_type error_range(_S_error_range);
  80. /**
  81. * There was insufficient memory to convert the expression into a
  82. * finite state machine.
  83. */
  84. constexpr error_type error_space(_S_error_space);
  85. /**
  86. * One of <em>*?+{</em> was not preceded by a valid regular expression.
  87. */
  88. constexpr error_type error_badrepeat(_S_error_badrepeat);
  89. /**
  90. * The complexity of an attempted match against a regular expression
  91. * exceeded a pre-set level.
  92. */
  93. constexpr error_type error_complexity(_S_error_complexity);
  94. /**
  95. * There was insufficient memory to determine whether the
  96. * regular expression could match the specified character sequence.
  97. */
  98. constexpr error_type error_stack(_S_error_stack);
  99. //@}
  100. } // namespace regex_constants
  101. // [7.8] Class regex_error
  102. /**
  103. * @brief A regular expression exception class.
  104. * @ingroup exceptions
  105. *
  106. * The regular expression library throws objects of this class on error.
  107. */
  108. class regex_error : public std::runtime_error
  109. {
  110. regex_constants::error_type _M_code;
  111. public:
  112. /**
  113. * @brief Constructs a regex_error object.
  114. *
  115. * @param __ecode the regex error code.
  116. */
  117. explicit
  118. regex_error(regex_constants::error_type __ecode);
  119. virtual ~regex_error() throw();
  120. /**
  121. * @brief Gets the regex error code.
  122. *
  123. * @returns the regex error code.
  124. */
  125. regex_constants::error_type
  126. code() const
  127. { return _M_code; }
  128. private:
  129. regex_error(regex_constants::error_type __ecode, const char* __what)
  130. : std::runtime_error(__what), _M_code(__ecode)
  131. { }
  132. friend void __throw_regex_error(regex_constants::error_type, const char*);
  133. };
  134. //@} // group regex
  135. void
  136. __throw_regex_error(regex_constants::error_type __ecode);
  137. inline void
  138. __throw_regex_error(regex_constants::error_type __ecode, const char* __what)
  139. { _GLIBCXX_THROW_OR_ABORT(regex_error(__ecode, __what)); }
  140. _GLIBCXX_END_NAMESPACE_VERSION
  141. } // namespace std