16#ifndef _PCRE2CPP_EXCEPTIONS_HPP_
17 #define _PCRE2CPP_EXCEPTIONS_HPP_
21 #if !_PCRE2CPP_HAS_CXX17
27 #if _PCRE2CPP_HAS_ASSERTS
39 template<utf_type utf>
43 using _pcre2_data_t = utils::pcre2_data<utf>;
44 using _string_type =
typename _pcre2_data_t::string_type;
45 using _uchar_type =
typename _pcre2_data_t::uchar_type;
46 using _char_type =
typename _pcre2_data_t::string_char_type;
48 _uchar_type error_message[120];
49 if (
const int size = _pcre2_data_t::get_error_message(error_code, error_message, 120); size != PCRE2_ERROR_BADDATA) {
50 return _string_type(
reinterpret_cast<_char_type*
>(error_message), 120);
52 return _string_type();
63 template<utf_type utf>
65 const size_t error_offset)
noexcept {
68 #if _PCRE2CPP_HAS_UTF8
70 return fmt::format(
"error at {} {}", error_offset, pcre2cpp::generate_error_message<utf>(error_code));
74 #if _PCRE2CPP_HAS_UTF16
76 return fmt::format(u
"error at {} {}", error_offset, pcre2cpp::generate_error_message<utf>(error_code));
80 #if _PCRE2CPP_HAS_UTF32
82 return fmt::format(U
"error at {} {}", error_offset, pcre2cpp::generate_error_message<utf>(error_code));
87 return _string_type();
98 template<utf_type utf>
100 #if _PCRE2CPP_HAS_UTF8
104 #if _PCRE2CPP_HAS_UTF16
107 for (
const auto& c : message) { msg +=
static_cast<std::string::value_type
>(c); }
112 #if _PCRE2CPP_HAS_UTF32
115 for (
const auto& c : message) { msg +=
static_cast<std::string::value_type
>(c); }
121 return std::string();
125 #if _PCRE2CPP_HAS_EXCEPTIONS
126 #pragma region PCRE2CPP_EXCEPTION
133 template<utf_type utf>
134 class basic_pcre2cpp_exception :
public std::runtime_error {
136 using _pcre2_data_t = utils::pcre2_data<utf>;
137 using _string_type =
typename _pcre2_data_t::string_type;
138 using _string_view_type =
typename _pcre2_data_t::string_view_type;
139 using _uchar_type =
typename _pcre2_data_t::uchar_type;
140 using _char_type =
typename _pcre2_data_t::string_char_type;
143 _string_type _message;
147 explicit basic_pcre2cpp_exception(
const _string_view_type message) noexcept
148 : std::runtime_error(convert_any_utf_to_utf8<utf>(message)), _message(message) {}
151 explicit basic_pcre2cpp_exception(
const int error_code) noexcept
152 : std::runtime_error(convert_any_utf_to_utf8<utf>(generate_error_message<utf>(error_code))),
153 _message(generate_error_message<utf>(error_code)) {}
156 basic_pcre2cpp_exception(
const int error_code,
const size_t error_offset) noexcept
157 : std::runtime_error(convert_any_utf_to_utf8<utf>(generate_error_message<utf>(error_code, error_offset))),
158 _message(generate_error_message<utf>(error_code, error_offset)) {}
164 #if _PCRE2CPP_HAS_UTF8
165 using u8pcre2cpp_exception = basic_pcre2cpp_exception<utf_type::UTF_8>;
167 #if _PCRE2CPP_HAS_UTF16
168 using u16pcre2cpp_exception = basic_pcre2cpp_exception<utf_type::UTF_16>;
170 #if _PCRE2CPP_HAS_UTF32
171 using u32pcre2cpp_exception = basic_pcre2cpp_exception<utf_type::UTF_32>;
174 #if _PCRE2CPP_HAS_UTF8
175 using pcre2cpp_exception = u8pcre2cpp_exception;
176 #elif _PCRE2CPP_HAS_UTF16
177 using pcre2cpp_exception = u16pcre2cpp_exception;
178 #elif _PCRE2CPP_HAS_UTF32
179 using pcre2cpp_exception = u32pcre2cpp_exception;
182 #pragma endregion PCRE2CPP_EXCEPTION
184 #pragma region REGEX_EXCEPTION
191 template<utf_type utf>
192 class basic_regex_exception :
public basic_pcre2cpp_exception<utf> {
194 using _string_view_type =
typename utils::pcre2_data<utf>::string_view_type;
198 explicit basic_regex_exception(
const _string_view_type message) noexcept : basic_pcre2cpp_exception<utf>(message) {}
201 basic_regex_exception(
const int error_code,
const size_t error_offset) noexcept
202 : basic_pcre2cpp_exception<utf>(error_code, error_offset) {}
204 using basic_pcre2cpp_exception<utf>::get_error;
207 #if _PCRE2CPP_HAS_UTF8
208 using u8regex_exception = basic_regex_exception<utf_type::UTF_8>;
210 #if _PCRE2CPP_HAS_UTF16
211 using u16regex_exception = basic_regex_exception<utf_type::UTF_16>;
213 #if _PCRE2CPP_HAS_UTF32
214 using u32regex_exception = basic_regex_exception<utf_type::UTF_32>;
217 #if _PCRE2CPP_HAS_UTF8
218 using regex_exception = u8regex_exception;
219 #elif _PCRE2CPP_HAS_UTF16
220 using regex_exception = u16regex_exception;
221 #elif _PCRE2CPP_HAS_UTF32
222 using regex_exception = u32regex_exception;
225 #pragma endregion REGEX_EXCEPTION
227 #pragma region MATCH_RESULT_EXCEPTION
234 template<utf_type utf>
235 class basic_match_result_exception :
public basic_pcre2cpp_exception<utf> {
237 using _string_view_type =
typename utils::pcre2_data<utf>::string_view_type;
241 explicit basic_match_result_exception(
const _string_view_type message) noexcept
242 : basic_pcre2cpp_exception<utf>(message) {}
245 explicit basic_match_result_exception(
const int error_code) noexcept : basic_pcre2cpp_exception<utf>(error_code) {}
247 using basic_pcre2cpp_exception<utf>::get_error;
250 #if _PCRE2CPP_HAS_UTF8
251 using u8match_result_exception = basic_match_result_exception<utf_type::UTF_8>;
253 #if _PCRE2CPP_HAS_UTF16
254 using u16match_result_exception = basic_match_result_exception<utf_type::UTF_16>;
256 #if _PCRE2CPP_HAS_UTF32
257 using u32match_result_exception = basic_match_result_exception<utf_type::UTF_32>;
260 #if _PCRE2CPP_HAS_UTF8
261 using match_result_exception = u8match_result_exception;
262 #elif _PCRE2CPP_HAS_UTF16
263 using match_result_exception = u16match_result_exception;
264 #elif _PCRE2CPP_HAS_UTF32
265 using match_result_exception = u32match_result_exception;
268 #pragma endregion MATCH_RESULT_EXCEPTION
@ UTF_16
Definition pcre2cpp.hpp:357
@ UTF_32
Definition pcre2cpp.hpp:360
@ UTF_8
Definition pcre2cpp.hpp:354
#define _PCRE2CPP_CONSTEXPR17
constexpr for c++17 and higher
Definition config.hpp:239
#define _PCRE2CPP_CONSTEXPR20
constexpr keyword for c++20 and higher
Definition config.hpp:257
#define _PCRE2CPP_ERROR(MESSAGE)
compiler error
Definition config.hpp:278
Main namespace of pcre2cpp library.
Translation container from pcre2 library to pcre2cpp.
Definition pcre2cpp.hpp:372