PCRE2 C++ Wrapper 1.2.4
pcre2cpp
Loading...
Searching...
No Matches
pcre2cpp.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fmt/format.h>
4#include <fmt/xchar.h>
5#include <memory>
6#include <mstd/mstd.hpp>
7#include <pcre2.h>
8#include <stdexcept>
9#include <string>
10#include <unordered_map>
11#include <variant>
12#include <vector>
13
14#pragma region config.hpp
15#ifndef _PCRE2CPP_CONFIG_HPP_
16 #define _PCRE2CPP_CONFIG_HPP_
17
22
28
33
38
39 #pragma region VERSION
44 #define PCRE2CPP_VERSION_MAJOR 1
49 #define PCRE2CPP_VERSION_MINOR 2
54 #define PCRE2CPP_VERSION_PATCH 4
55
60 #define _PCRE2CPP_STRINGIFY_HELPER(x) #x
61
66 #define _PCRE2CPP_VERSION_TO_STRING(major, minor, patch) \
67 _PCRE2CPP_STRINGIFY_HELPER(major) "." _PCRE2CPP_STRINGIFY_HELPER(minor) "." _PCRE2CPP_STRINGIFY_HELPER(patch)
68
72 #define _PCRE2CPP_VERSION_TO_INT(major, minor, patch) (major * 100 + minor * 10 + patch)
73
78 #define PCRE2CPP_VERSION_STRING \
79 _PCRE2CPP_VERSION_TO_STRING(PCRE2CPP_VERSION_MAJOR, PCRE2CPP_VERSION_MINOR, PCRE2CPP_VERSION_PATCH)
80
84 #define PCRE2CPP_VERSION_INT _PCRE2CPP_VERSION_TO_INT(PCRE2CPP_VERSION_MAJOR, PCRE2CPP_VERSION_MINOR, PCRE2CPP_VERSION_PATCH)
89 #define PCRE2CPP_VERSION PCRE2CPP_VERSION_STRING
90 #pragma endregion
91
92 #pragma region LAST_UPDATE
97 #define PCRE2CPP_LAST_UPDATE_DAY 07
102 #define PCRE2CPP_LAST_UPDATE_MONTH 04
107 #define PCRE2CPP_LAST_UPDATE_YEAR 2026
108
113 #define _PCRE2CPP_LAST_UPDATE_DATE_HELPER(day, month, year) \
114 _PCRE2CPP_STRINGIFY_HELPER(day) "." _PCRE2CPP_STRINGIFY_HELPER(month) "." _PCRE2CPP_STRINGIFY_HELPER(year)
115
120 #define PCRE2CPP_LAST_UPDATE_DATE \
121 _PCRE2CPP_LAST_UPDATE_DATE_HELPER(PCRE2CPP_LAST_UPDATE_DAY, PCRE2CPP_LAST_UPDATE_MONTH, PCRE2CPP_LAST_UPDATE_YEAR)
122 #pragma endregion
123
124 #pragma region CXX_VERSIONS
130 #ifndef _HAS_CXX17
131 // clang-format off
132 #define _PCRE2CPP_HAS_CXX17 __cplusplus >= 201703l
133 // clang-format on
134 #else
135 #define _PCRE2CPP_HAS_CXX17 _HAS_CXX17
136 #endif
137
143 #ifndef PCRE2CPP_ENABLE_CXX20
144 #define _PCRE2CPP_HAS_CXX20 0
145 #elif !defined(_HAS_CXX20)
146 // clang-format off
147 #define _PCRE2CPP_HAS_CXX20 __cplusplus >= 202002l
148 // clang-format on
149 #else
150 #define _PCRE2CPP_HAS_CXX20 _HAS_CXX20
151 #endif
152 #pragma endregion
153
159
165
166 #ifdef PCRE2CPP_CHANGE_ASSERTS_TO_EXCEPTIONS
167 #define _PCRE2CPP_HAS_EXCEPTIONS _PCRE2CPP_HAS_CXX17
168 #define _PCRE2CPP_HAS_ASSERTS 0
169 #else
170 #define _PCRE2CPP_HAS_EXCEPTIONS 0
171 #define _PCRE2CPP_HAS_ASSERTS _PCRE2CPP_HAS_CXX17
172 #endif
173
174 #if _PCRE2CPP_HAS_EXCEPTIONS
175 #define _PCRE2CPP_NOEXCEPT noexcept
176 #else
177 #define _PCRE2CPP_NOEXCEPT
178 #endif
179
180 #pragma region UTFS_ENABLED
186
192
198
199 #ifdef PCRE2CPP_DISABLE_UTF8
200 #define _PCRE2CPP_HAS_UTF8 0
201 #else
202 #define _PCRE2CPP_HAS_UTF8 1
203 #define PCRE2_CODE_UNIT_WIDTH 8
204 #endif
205
206 #ifdef PCRE2CPP_DISABLE_UTF16
207 #define _PCRE2CPP_HAS_UTF16 0
208 #else
209 #define _PCRE2CPP_HAS_UTF16 1
210 #ifndef PCRE2_CODE_UNIT_WIDTH
211 #define PCRE2_CODE_UNIT_WIDTH 16
212 #else
213 #define PCRE2_CODE_UNIT_WIDTH 0
214 #endif
215 #endif
216
217 #ifdef PCRE2CPP_DISABLE_UTF32
218 #define _PCRE2CPP_HAS_UTF32 0
219 #else
220 #define _PCRE2CPP_HAS_UTF32 1
221 #ifndef PCRE2_CODE_UNIT_WIDTH
222 #define PCRE2_CODE_UNIT_WIDTH 32
223 #else
224 #define PCRE2_CODE_UNIT_WIDTH 0
225 #endif
226 #endif
227 #pragma endregion
228
229 #pragma region VERSION_SPECIFIC_VALUES
235 #if _PCRE2CPP_HAS_CXX17
236 #define _PCRE2CPP_CONSTEXPR17 constexpr
237 #else
238 #define _PCRE2CPP_CONSTEXPR17
239 #endif
240
246
252 #if _PCRE2CPP_HAS_CXX20
253 #define _PCRE2CPP_CONSTEXPR20 constexpr
254 #define _PCRE2CPP_REQUIRES(condition) requires (condition)
255 #else
256 #define _PCRE2CPP_CONSTEXPR20
257 #define _PCRE2CPP_REQUIRES(condition)
258 #endif
259 #pragma endregion
260
261
266 #define _PCRE2CPP_MESSAGE(MESSAGE) _MSTD_MESSAGE(MESSAGE)
271 #define _PCRE2CPP_WARNING(MESSAGE) _MSTD_WARNING(MESSAGE)
276 #define _PCRE2CPP_ERROR(MESSAGE) _MSTD_ERROR(MESSAGE)
277#endif
278#pragma endregion // config.hpp
279
280#pragma region libs.hpp
281#ifndef _PCRE2CPP_LIBS_HPP_
282 #define _PCRE2CPP_LIBS_HPP_
283
284
285 #if !_PCRE2CPP_HAS_CXX17
286_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
287 #else
288
289
290 #if _PCRE2CPP_HAS_EXCEPTIONS
291 #endif
292
293 #endif
294#endif
295#pragma endregion // libs.hpp
296
297#pragma region types.hpp
298#ifndef _PCRE2CPP_TYPES_HPP_
299 #define _PCRE2CPP_TYPES_HPP_
300
301
302 #if !_PCRE2CPP_HAS_CXX17
303_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
304 #else
305
306
307namespace pcre2cpp {
308 enum class utf_type : uint8_t;
309
310 namespace utils {
311 template<utf_type utf>
312 struct pcre2_data;
313 }
314
315 #if _PCRE2CPP_HAS_EXCEPTIONS
316 template<utf_type utf>
317 class basic_pcre2cpp_exception;
318 template<utf_type utf>
319 class basic_regex_exception;
320 template<utf_type utf>
321 class basic_match_result_exception;
322 #endif
323
324 template<utf_type utf>
325 struct basic_match_value;
326 struct sub_match_value;
327 template<utf_type utf>
328 class basic_match_result;
329 template<utf_type utf>
330 class basic_regex;
331} // namespace pcre2cpp
332 #endif
333#endif
334#pragma endregion // types.hpp
335
336#pragma region utils_pcre2_data.hpp
337#ifndef _PCRE2CPP_PCRE2_DATA_HPP_
338 #define _PCRE2CPP_PCRE2_DATA_HPP_
339
340 #include <pcre2cpp/config.hpp>
341
342 #if !_PCRE2CPP_HAS_CXX17
343_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
344 #else
345 #include <pcre2cpp/types.hpp>
346
347namespace pcre2cpp {
352 enum class utf_type : uint8_t {
353 #if _PCRE2CPP_HAS_UTF8
354 UTF_8 = 8,
355 #endif
356 #if _PCRE2CPP_HAS_UTF16
357 UTF_16 = 16,
358 #endif
359 #if _PCRE2CPP_HAS_UTF32
361 #endif
362 };
363} // namespace pcre2cpp
364
365namespace pcre2cpp::utils {
371 template<utf_type utf>
372 struct pcre2_data {};
373
374 #pragma region UTF_8
375 #if _PCRE2CPP_HAS_UTF8
380 template<>
382 #pragma region CODE
384 using code_type = pcre2_code_8;
386 using compile_ctx_type = pcre2_compile_context_8;
388 using general_ctx_type = pcre2_general_context_8;
389 #pragma endregion
390
391 #pragma region MATCH
393 using match_data_type = pcre2_match_data_8;
395 using match_ctx_type = pcre2_match_context_8;
396 #pragma endregion
397
398 #pragma region PCRE2_STRING
400 using sptr_type = PCRE2_SPTR8;
402 using uchar_type = PCRE2_UCHAR8;
403 #pragma endregion
404
405 #pragma region CPP_STRING
406 // #if _PCRE2CPP_HAS_CXX20
407 // using string_type = std::u8string;
408 // using string_view_type = std::u8string_view;
409 // #else
410 // using string_type = std::string;
411 // using string_view_type = std::string_view;
412 // #endif
414 using string_type = std::string;
416 using string_view_type = std::string_view;
418 using string_char_type = string_type::value_type;
419 #pragma endregion
420
421 #pragma region UTF_INFO
426 #pragma endregion
427
428 #pragma region CODE_FUNCTIONS
430 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<code_type*(sptr_type, size_t, uint32_t, int*, size_t*, compile_ctx_type*)>
431 compile = pcre2_compile_8;
433 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(code_type*)> code_free = pcre2_code_free_8;
434 #pragma endregion
435
436 #pragma region MATCH_DATA_FUNCTIONS
438 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<match_data_type*(const code_type*, general_ctx_type*)>
439 match_data_from_pattern = pcre2_match_data_create_from_pattern_8;
441 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(match_data_type*)> match_data_free = pcre2_match_data_free_8;
442 #pragma endregion
443
444 #pragma region MATCH_FUNCTIONS
447 mstd::c_func_t<int(const code_type*, sptr_type, size_t, size_t, uint32_t, match_data_type*, match_ctx_type*)>
448 match = pcre2_match_8;
449 #pragma endregion
450
451 #pragma region OVECTOR_FUNCTIONS
453 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<size_t*(match_data_type*)> get_ovector_ptr = pcre2_get_ovector_pointer_8;
455 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<uint32_t(match_data_type*)> get_ovector_count = pcre2_get_ovector_count_8;
456 #pragma endregion
457
458 #pragma region ERROR_FUNCTIONS
460 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(int, uchar_type*, size_t)> get_error_message = pcre2_get_error_message_8;
461 #pragma endregion
462
463 #pragma region PATTERN_INFO_FUNCTIONS
465 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, uint32_t, void*)> get_info = pcre2_pattern_info_8;
466 #pragma endregion
467
468 #pragma region SUBSTRING_FUNCTIONS
471 pcre2_substring_number_from_name_8;
472 #pragma endregion
473 };
474 #endif
475
476 #pragma endregion
477
478 #pragma region UTF_16
479
480 #if _PCRE2CPP_HAS_UTF16
485 template<>
487 #pragma region CODE
489 using code_type = pcre2_code_16;
491 using compile_ctx_type = pcre2_compile_context_16;
493 using general_ctx_type = pcre2_general_context_16;
494 #pragma endregion
495
496 #pragma region MATCH
498 using match_data_type = pcre2_match_data_16;
500 using match_ctx_type = pcre2_match_context_16;
501 #pragma endregion
502
503 #pragma region PCRE2_STRING
505 using sptr_type = PCRE2_SPTR16;
507 using uchar_type = PCRE2_UCHAR16;
508 #pragma endregion
509
510 #pragma region CPP_STRING
512 using string_type = std::u16string;
514 using string_view_type = std::u16string_view;
516 using string_char_type = string_type::value_type;
517 #pragma endregion
518
519 #pragma region UTF_INFO
523 static _PCRE2CPP_CONSTEXPR17 size_t utf_size = 16;
524 #pragma endregion
525
526 #pragma region CODE_FUNCTIONS
528 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<code_type*(sptr_type, size_t, uint32_t, int*, size_t*, compile_ctx_type*)>
529 compile = pcre2_compile_16;
531 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(code_type*)> code_free = pcre2_code_free_16;
532 #pragma endregion
533
534 #pragma region MATCH_DATA_FUNCTIONS
536 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<match_data_type*(const code_type*, general_ctx_type*)>
537 match_data_from_pattern = pcre2_match_data_create_from_pattern_16;
539 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(match_data_type*)> match_data_free = pcre2_match_data_free_16;
540 #pragma endregion
541
542 #pragma region MATCH_FUNCTIONS
545 mstd::c_func_t<int(const code_type*, sptr_type, size_t, size_t, uint32_t, match_data_type*, match_ctx_type*)>
546 match = pcre2_match_16;
547 #pragma endregion
548
549 #pragma region OVECTOR_FUNCTIONS
551 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<size_t*(match_data_type*)> get_ovector_ptr = pcre2_get_ovector_pointer_16;
553 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<uint32_t(match_data_type*)> get_ovector_count = pcre2_get_ovector_count_16;
554 #pragma endregion
555
556 #pragma region ERROR_FUNCTIONS
558 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(int, uchar_type*, size_t)> get_error_message = pcre2_get_error_message_16;
559 #pragma endregion
560
561 #pragma region PATTERN_INFO_FUNCTIONS
563 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, uint32_t, void*)> get_info = pcre2_pattern_info_16;
564 #pragma endregion
565
566 #pragma region SUBSTRING_FUNCTIONS
569 pcre2_substring_number_from_name_16;
570 #pragma endregion
571 };
572 #endif
573
574 #pragma endregion
575
576 #pragma region UTF_32
577
578 #if _PCRE2CPP_HAS_UTF32
583 template<>
585 #pragma region CODE
587 using code_type = pcre2_code_32;
589 using compile_ctx_type = pcre2_compile_context_32;
591 using general_ctx_type = pcre2_general_context_32;
592 #pragma endregion
593
594 #pragma region MATCH
596 using match_data_type = pcre2_match_data_32;
598 using match_ctx_type = pcre2_match_context_32;
599 #pragma endregion
600
601 #pragma region PCRE2_STRING
603 using sptr_type = PCRE2_SPTR32;
605 using uchar_type = PCRE2_UCHAR32;
606 #pragma endregion
607
608 #pragma region CPP_STRING
610 using string_type = std::u32string;
612 using string_view_type = std::u32string_view;
614 using string_char_type = string_type::value_type;
615 #pragma endregion
616
617 #pragma region UTF_INFO
621 static _PCRE2CPP_CONSTEXPR17 size_t utf_size = 32;
622 #pragma endregion
623
624 #pragma region CODE_FUNCTIONS
626 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<code_type*(sptr_type, size_t, uint32_t, int*, size_t*, compile_ctx_type*)>
627 compile = pcre2_compile_32;
629 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(code_type*)> code_free = pcre2_code_free_32;
630 #pragma endregion
631
632 #pragma region MATCH_DATA_FUNCTIONS
634 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<match_data_type*(const code_type*, general_ctx_type*)>
635 match_data_from_pattern = pcre2_match_data_create_from_pattern_32;
637 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(match_data_type*)> match_data_free = pcre2_match_data_free_32;
638 #pragma endregion
639
640 #pragma region MATCH_FUNCTIONS
643 mstd::c_func_t<int(const code_type*, sptr_type, size_t, size_t, uint32_t, match_data_type*, match_ctx_type*)>
644 match = pcre2_match_32;
645 #pragma endregion
646
647 #pragma region OVECTOR_FUNCTIONS
649 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<size_t*(match_data_type*)> get_ovector_ptr = pcre2_get_ovector_pointer_32;
651 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<uint32_t(match_data_type*)> get_ovector_count = pcre2_get_ovector_count_32;
652 #pragma endregion
653
654 #pragma region ERROR_FUNCTIONS
656 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(int, uchar_type*, size_t)> get_error_message = pcre2_get_error_message_32;
657 #pragma endregion
658
659 #pragma region PATTERN_INFO_FUNCTIONS
661 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, uint32_t, void*)> get_info = pcre2_pattern_info_32;
662 #pragma endregion
663
664 #pragma region SUBSTRING_FUNCTIONS
667 pcre2_substring_number_from_name_32;
668 #pragma endregion
669 };
670 #endif
671
672 #pragma endregion
673
674 #if _PCRE2CPP_HAS_UTF8
676 #endif
677 #if _PCRE2CPP_HAS_UTF16
679 #endif
680 #if _PCRE2CPP_HAS_UTF32
682 #endif
683} // namespace pcre2cpp::utils
684 #endif
685#endif
686#pragma endregion // utils_pcre2_data.hpp
687
688#pragma region exceptions_exceptions.hpp
689#ifndef _PCRE2CPP_EXCEPTIONS_HPP_
690 #define _PCRE2CPP_EXCEPTIONS_HPP_
691
692 #include <pcre2cpp/config.hpp>
693
694 #if !_PCRE2CPP_HAS_CXX17
695_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
696 #else
697
698 #include <pcre2cpp/types.hpp>
700 #if _PCRE2CPP_HAS_ASSERTS
702 #endif
703
704namespace pcre2cpp {
712 template<utf_type utf>
713 static _PCRE2CPP_CONSTEXPR17 typename utils::pcre2_data<utf>::string_type generate_error_message(
714 const int error_code
715 ) noexcept {
716 using _pcre2_data_t = utils::pcre2_data<utf>;
717 using _string_type = typename _pcre2_data_t::string_type;
718 using _uchar_type = typename _pcre2_data_t::uchar_type;
719 using _char_type = typename _pcre2_data_t::string_char_type;
720
721 _uchar_type error_message[120];
722 if (const int size = _pcre2_data_t::get_error_message(error_code, error_message, 120); size != PCRE2_ERROR_BADDATA) {
723 return _string_type(reinterpret_cast<_char_type*>(error_message), 120);
724 }
725 return _string_type();
726 }
727
736 template<utf_type utf>
737 static _PCRE2CPP_CONSTEXPR17 typename utils::pcre2_data<utf>::string_type generate_error_message(const int error_code,
738 const size_t error_offset) noexcept {
739 using _string_type = typename utils::pcre2_data<utf>::string_type;
740
741 #if _PCRE2CPP_HAS_UTF8
743 return fmt::format("error at {} {}", error_offset, pcre2cpp::generate_error_message<utf>(error_code));
744 }
745 else
746 #endif
747 #if _PCRE2CPP_HAS_UTF16
749 return fmt::format(u"error at {} {}", error_offset, pcre2cpp::generate_error_message<utf>(error_code));
750 }
751 else
752 #endif
753 #if _PCRE2CPP_HAS_UTF32
755 return fmt::format(U"error at {} {}", error_offset, pcre2cpp::generate_error_message<utf>(error_code));
756 }
757 else
758 #endif
759 {
760 return _string_type();
761 }
762 }
763
771 template<utf_type utf>
772 static _PCRE2CPP_CONSTEXPR20 std::string convert_any_utf_to_utf8(const typename utils::pcre2_data<utf>::string_view_type message) noexcept {
773 #if _PCRE2CPP_HAS_UTF8
774 if _PCRE2CPP_CONSTEXPR17 (utf == pcre2cpp::utf_type::UTF_8) { return std::string(message); }
775 else
776 #endif
777 #if _PCRE2CPP_HAS_UTF16
779 std::string msg;
780 for (const auto& c : message) { msg += static_cast<std::string::value_type>(c); }
781 return msg;
782 }
783 else
784 #endif
785 #if _PCRE2CPP_HAS_UTF32
787 std::string msg;
788 for (const auto& c : message) { msg += static_cast<std::string::value_type>(c); }
789 return msg;
790 }
791 else
792 #endif
793 {
794 return std::string();
795 }
796 }
797
798 #if _PCRE2CPP_HAS_EXCEPTIONS
799 #pragma region PCRE2CPP_EXCEPTION
800
806 template<utf_type utf>
807 class basic_pcre2cpp_exception : public std::runtime_error {
808 private:
809 using _pcre2_data_t = utils::pcre2_data<utf>;
810 using _string_type = typename _pcre2_data_t::string_type;
811 using _string_view_type = typename _pcre2_data_t::string_view_type;
812 using _uchar_type = typename _pcre2_data_t::uchar_type;
813 using _char_type = typename _pcre2_data_t::string_char_type;
814
816 _string_type _message;
817
818 public:
820 explicit basic_pcre2cpp_exception(const _string_view_type message) noexcept
821 : std::runtime_error(convert_any_utf_to_utf8<utf>(message)), _message(message) {}
822
824 explicit basic_pcre2cpp_exception(const int error_code) noexcept
825 : std::runtime_error(convert_any_utf_to_utf8<utf>(generate_error_message<utf>(error_code))),
826 _message(generate_error_message<utf>(error_code)) {}
827
829 basic_pcre2cpp_exception(const int error_code, const size_t error_offset) noexcept
830 : std::runtime_error(convert_any_utf_to_utf8<utf>(generate_error_message<utf>(error_code, error_offset))),
831 _message(generate_error_message<utf>(error_code, error_offset)) {}
832
834 _PCRE2CPP_CONSTEXPR17 const _string_type& get_error() const noexcept { return _message; }
835 };
836
837 #if _PCRE2CPP_HAS_UTF8
838 using u8pcre2cpp_exception = basic_pcre2cpp_exception<utf_type::UTF_8>;
839 #endif
840 #if _PCRE2CPP_HAS_UTF16
841 using u16pcre2cpp_exception = basic_pcre2cpp_exception<utf_type::UTF_16>;
842 #endif
843 #if _PCRE2CPP_HAS_UTF32
844 using u32pcre2cpp_exception = basic_pcre2cpp_exception<utf_type::UTF_32>;
845 #endif
846
847 #if _PCRE2CPP_HAS_UTF8
848 using pcre2cpp_exception = u8pcre2cpp_exception;
849 #elif _PCRE2CPP_HAS_UTF16
850 using pcre2cpp_exception = u16pcre2cpp_exception;
851 #elif _PCRE2CPP_HAS_UTF32
852 using pcre2cpp_exception = u32pcre2cpp_exception;
853 #endif
854
855 #pragma endregion PCRE2CPP_EXCEPTION
856
857 #pragma region REGEX_EXCEPTION
858
864 template<utf_type utf>
865 class basic_regex_exception : public basic_pcre2cpp_exception<utf> {
866 private:
867 using _string_view_type = typename utils::pcre2_data<utf>::string_view_type;
868
869 public:
871 explicit basic_regex_exception(const _string_view_type message) noexcept : basic_pcre2cpp_exception<utf>(message) {}
872
874 basic_regex_exception(const int error_code, const size_t error_offset) noexcept
875 : basic_pcre2cpp_exception<utf>(error_code, error_offset) {}
876
877 using basic_pcre2cpp_exception<utf>::get_error;
878 };
879
880 #if _PCRE2CPP_HAS_UTF8
881 using u8regex_exception = basic_regex_exception<utf_type::UTF_8>;
882 #endif
883 #if _PCRE2CPP_HAS_UTF16
884 using u16regex_exception = basic_regex_exception<utf_type::UTF_16>;
885 #endif
886 #if _PCRE2CPP_HAS_UTF32
887 using u32regex_exception = basic_regex_exception<utf_type::UTF_32>;
888 #endif
889
890 #if _PCRE2CPP_HAS_UTF8
891 using regex_exception = u8regex_exception;
892 #elif _PCRE2CPP_HAS_UTF16
893 using regex_exception = u16regex_exception;
894 #elif _PCRE2CPP_HAS_UTF32
895 using regex_exception = u32regex_exception;
896 #endif
897
898 #pragma endregion REGEX_EXCEPTION
899
900 #pragma region MATCH_RESULT_EXCEPTION
901
907 template<utf_type utf>
908 class basic_match_result_exception : public basic_pcre2cpp_exception<utf> {
909 private:
910 using _string_view_type = typename utils::pcre2_data<utf>::string_view_type;
911
912 public:
914 explicit basic_match_result_exception(const _string_view_type message) noexcept
915 : basic_pcre2cpp_exception<utf>(message) {}
916
918 explicit basic_match_result_exception(const int error_code) noexcept : basic_pcre2cpp_exception<utf>(error_code) {}
919
920 using basic_pcre2cpp_exception<utf>::get_error;
921 };
922
923 #if _PCRE2CPP_HAS_UTF8
924 using u8match_result_exception = basic_match_result_exception<utf_type::UTF_8>;
925 #endif
926 #if _PCRE2CPP_HAS_UTF16
927 using u16match_result_exception = basic_match_result_exception<utf_type::UTF_16>;
928 #endif
929 #if _PCRE2CPP_HAS_UTF32
930 using u32match_result_exception = basic_match_result_exception<utf_type::UTF_32>;
931 #endif
932
933 #if _PCRE2CPP_HAS_UTF8
934 using match_result_exception = u8match_result_exception;
935 #elif _PCRE2CPP_HAS_UTF16
936 using match_result_exception = u16match_result_exception;
937 #elif _PCRE2CPP_HAS_UTF32
938 using match_result_exception = u32match_result_exception;
939 #endif
940
941 #pragma endregion MATCH_RESULT_EXCEPTION
942 #endif
943} // namespace pcre2cpp
944 #endif
945#endif
946#pragma endregion // exceptions_exceptions.hpp
947
948#pragma region match_match_options.hpp
949#ifndef _PCRE2CPP_REGEX_MATCH_OPTIONS_HPP_
950 #define _PCRE2CPP_REGEX_MATCH_OPTIONS_HPP_
951
952 #include <pcre2cpp/config.hpp>
953
954 #if !_PCRE2CPP_HAS_CXX17
955_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
956 #else
957
958 #include <pcre2cpp/types.hpp>
959
960namespace pcre2cpp {
965 enum class match_options_bits : uint32_t {
967 None = 0u,
969 Anchored = PCRE2_ANCHORED,
971 CopyMatchedSubject = PCRE2_COPY_MATCHED_SUBJECT,
973 DisableRecurseLoopCheck = PCRE2_DISABLE_RECURSELOOP_CHECK,
975 EndAnchored = PCRE2_ENDANCHORED,
977 NotBOL = PCRE2_NOTBOL,
979 NotEOL = PCRE2_NOTEOL,
981 NotEmpty = PCRE2_NOTEMPTY,
983 NotEmptyAtStart = PCRE2_NOTEMPTY_ATSTART,
985 NoJIT = PCRE2_NO_JIT,
987 NoUTFCheck = PCRE2_NO_UTF_CHECK,
989 PartialHard = PCRE2_PARTIAL_HARD,
991 PartialSoft = PCRE2_PARTIAL_SOFT
992 };
993
998 using match_options = mstd::flags<match_options_bits>;
999
1007 static _PCRE2CPP_CONSTEXPR17 match_options operator|(const match_options_bits opt0, const match_options_bits opt1) noexcept {
1008 return mstd::operator|(opt0, opt1);
1009 }
1010} // namespace pcre2cpp
1011 #endif
1012#endif
1013#pragma endregion // match_match_options.hpp
1014
1015#pragma region match_match_result.hpp
1016#ifndef _PCRE2CPP_MATCH_RESULT_HPP_
1017 #define _PCRE2CPP_MATCH_RESULT_HPP_
1018
1019 #include <pcre2cpp/config.hpp>
1020
1021 #if !_PCRE2CPP_HAS_CXX17
1022_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
1023 #else
1024
1027 #include <pcre2cpp/types.hpp>
1029
1030namespace pcre2cpp {
1031 #pragma region MATCH_VALUE
1032
1038 template<utf_type utf>
1040 private:
1041 using _string_type = typename utils::pcre2_data<utf>::string_type;
1042
1043 public:
1047 _string_type value;
1048 };
1049
1050 #if _PCRE2CPP_HAS_UTF8
1052 #endif
1053 #if _PCRE2CPP_HAS_UTF16
1055 #endif
1056 #if _PCRE2CPP_HAS_UTF32
1058 #endif
1059
1060 #if _PCRE2CPP_HAS_UTF8
1062 #elif _PCRE2CPP_HAS_UTF16
1064 #elif _PCRE2CPP_HAS_UTF32
1066 #endif
1067 #pragma endregion
1068
1069 #pragma region SUB_MATCH_VALUE
1070
1079 size_t size;
1080 };
1081
1082 #pragma endregion
1083
1089 template<utf_type utf>
1091 public:
1093 static _PCRE2CPP_CONSTEXPR17 size_t bad_offset = std::numeric_limits<size_t>::max();
1094
1095 private:
1096 using _pcre2_data_t = utils::pcre2_data<utf>;
1097 using _string_type = typename _pcre2_data_t::string_type;
1098 using _string_view_type = typename _pcre2_data_t::string_view_type;
1099 using _match_value = basic_match_value<utf>;
1100 #if _PCRE2CPP_HAS_EXCEPTIONS
1101 using _match_result_exception = basic_match_result_exception<utf>;
1102 #endif
1103 using _named_sub_values_table = std::unordered_map<_string_type, size_t>;
1104 using _named_sub_values_table_ptr = std::shared_ptr<_named_sub_values_table>;
1105
1107 struct _value_result_data {
1108 size_t search_offset = bad_offset;
1109 _match_value result = { bad_offset, _string_type() };
1110 std::vector<std::optional<sub_match_value> > sub_results = {};
1111 _named_sub_values_table_ptr named_sub_values = {};
1112 bool found = false;
1113 };
1114
1116 std::variant<match_error_codes, _value_result_data> _data = _value_result_data();
1117
1119 static _PCRE2CPP_CONSTEXPR17 _string_type _get_out_of_bounds_string() noexcept {
1120 #if _PCRE2CPP_HAS_UTF8
1121 if _PCRE2CPP_CONSTEXPR17 (utf == utf_type::UTF_8) { return "Subexpression index out of bounds or has no value"; }
1122 else
1123 #endif
1124 #if _PCRE2CPP_HAS_UTF16
1126 return u"Subexpression index out of bounds or has no value";
1127 }
1128 else
1129 #endif
1130 #if _PCRE2CPP_HAS_UTF32
1132 return U"Subexpression index out of bounds or has no value";
1133 }
1134 else
1135 #endif
1136 {
1137 return _string_type();
1138 }
1139 }
1140
1142 static _PCRE2CPP_CONSTEXPR17 _string_type _get_subexpression_not_found(const _string_view_type name) noexcept {
1143 #if _PCRE2CPP_HAS_UTF8
1145 return fmt::format("Subexpression with provided name '{}' not found", name);
1146 }
1147 else
1148 #endif
1149 #if _PCRE2CPP_HAS_UTF16
1151 return fmt::format(u"Subexpression with provided name '{}' not found", name);
1152 }
1153 else
1154 #endif
1155 #if _PCRE2CPP_HAS_UTF32
1157 return fmt::format(U"Subexpression with provided name '{}' not found", name);
1158 }
1159 else
1160 #endif
1161 {
1162 return _string_type();
1163 }
1164 }
1165
1167 _PCRE2CPP_CONSTEXPR17 bool _has_named_sub_result(const _string_view_type name) const noexcept {
1168 const auto& named_sub_values = std::get<_value_result_data>(_data).named_sub_values;
1169 #if _PCRE2CPP_HAS_CXX20
1170 return named_sub_values->contains(name.data());
1171 #else
1172 return named_sub_values->find(name.data()) != named_sub_values->end();
1173 #endif
1174 }
1175
1177 _PCRE2CPP_CONSTEXPR17 bool _has_sub_value(const size_t idx) const noexcept {
1178 const auto& subResults = std::get<_value_result_data>(_data).sub_results;
1179 return idx < subResults.size() && subResults[idx].has_value();
1180 }
1181
1183 _PCRE2CPP_CONSTEXPR17 size_t _get_named_sub_result_idx(const _string_view_type name) const _PCRE2CPP_NOEXCEPT {
1184 if (!_has_named_sub_result(name)) {
1185 #if _PCRE2CPP_HAS_EXCEPTIONS
1186 throw _match_result_exception(_get_subexpression_not_found(name));
1187 #else
1188 pcre2cpp_assert(false, "{}", _get_subexpression_not_found(name));
1189 return bad_offset;
1190 #endif
1191 }
1192 return std::get<_value_result_data>(_data).named_sub_values->at(name.data());
1193 }
1194
1196 _PCRE2CPP_CONSTEXPR17 sub_match_value _get_sub_value(const size_t idx) const _PCRE2CPP_NOEXCEPT {
1197 if (!_has_sub_value(idx)) {
1198 #if _PCRE2CPP_HAS_EXCEPTIONS
1199 throw basic_match_result_exception<utf>(_get_out_of_bounds_string());
1200 #else
1201 pcre2cpp_assert(false, "{}", _get_out_of_bounds_string());
1202 return { .relative_offset = bad_offset, .size = 0 };
1203 #endif
1204 }
1205
1206 return std::get<_value_result_data>(_data).sub_results[idx].value();
1207 }
1208
1209 public:
1210 #pragma region CONSTRUCTORS
1213
1215 _PCRE2CPP_CONSTEXPR17 explicit basic_match_result(const match_error_codes error_code) noexcept : _data(error_code) {}
1216
1218 _PCRE2CPP_CONSTEXPR17 basic_match_result(const size_t search_offset,
1219 const _named_sub_values_table_ptr& named_sub_values) noexcept
1220 : _data(_value_result_data { .search_offset = search_offset, .named_sub_values = named_sub_values }) {}
1221
1223 _PCRE2CPP_CONSTEXPR17 basic_match_result(const size_t search_offset, const _match_value& result,
1224 const std::vector<std::optional<sub_match_value> >& sub_results,
1225 const _named_sub_values_table_ptr& named_sub_values) noexcept
1226 : _data(_value_result_data { .search_offset = search_offset,
1227 .result = result,
1228 .sub_results = sub_results,
1229 .named_sub_values = named_sub_values,
1230 .found = true }) {}
1231
1236 #pragma endregion
1237
1240
1242 _PCRE2CPP_CONSTEXPR17 basic_match_result& operator=(const basic_match_result& other) noexcept = default;
1244 _PCRE2CPP_CONSTEXPR17 basic_match_result& operator=(basic_match_result&& other) noexcept = default;
1245
1246 #pragma region ERRORS
1247
1249 _PCRE2CPP_CONSTEXPR17 bool has_error() const noexcept { return std::holds_alternative<match_error_codes>(_data); }
1250
1252 _PCRE2CPP_CONSTEXPR17 match_error_codes get_error_code() const noexcept {
1253 if (!has_error()) { return match_error_codes::None; }
1254 return std::get<match_error_codes>(_data);
1255 }
1256
1258 _PCRE2CPP_CONSTEXPR17 _string_type get_error_message() const noexcept {
1259 if (!has_error()) { return _string_type(); }
1260 return pcre2cpp::generate_error_message<utf>(static_cast<int>(std::get<match_error_codes>(_data)));
1261 }
1262
1263 #if _PCRE2CPP_HAS_EXCEPTIONS
1265 _PCRE2CPP_CONSTEXPR17 void throw_error() const {
1266 if (!has_error()) { return; }
1267 throw _match_result_exception(static_cast<int>(std::get<match_error_codes>(_data)));
1268 }
1269 #endif
1270
1271 #pragma endregion ERRORS
1272
1273 #pragma region RESULTS
1274
1276 _PCRE2CPP_CONSTEXPR17 bool has_result() const noexcept { return std::holds_alternative<_value_result_data>(_data); }
1277
1279 _PCRE2CPP_CONSTEXPR17 bool has_value() const noexcept {
1280 if (!has_result()) { return false; }
1281 return std::get<_value_result_data>(_data).found;
1282 }
1283
1285 _PCRE2CPP_CONSTEXPR17 bool has_sub_value(const size_t idx) const noexcept {
1286 if (!has_value()) { return false; }
1287 return _has_sub_value(idx);
1288 }
1289
1291 _PCRE2CPP_CONSTEXPR17 bool has_sub_value(const _string_view_type name) const noexcept {
1292 return _has_named_sub_result(name) && has_sub_value(_get_named_sub_result_idx(name));
1293 }
1294
1297 if (!has_result()) { return bad_offset; }
1298 return std::get<_value_result_data>(_data).search_offset;
1299 }
1300
1301 #pragma region RESULT
1302
1304 _PCRE2CPP_CONSTEXPR17 _match_value get_result() const noexcept {
1305 if (!has_value()) { return { bad_offset, _string_type() }; }
1306 return std::get<_value_result_data>(_data).result;
1307 }
1308
1311 if (!has_value()) { return bad_offset; }
1312 const auto& value = std::get<_value_result_data>(_data);
1313 return value.search_offset + value.result.relative_offset;
1314 }
1315
1318 if (!has_value()) { return bad_offset; }
1319 return std::get<_value_result_data>(_data).result.relative_offset;
1320 }
1321
1323 _PCRE2CPP_CONSTEXPR17 size_t get_result_size() const noexcept {
1324 if (!has_value()) { return 0; }
1325 return std::get<_value_result_data>(_data).result.value.size();
1326 }
1327
1329 _PCRE2CPP_CONSTEXPR17 _string_type get_result_value() const noexcept {
1330 if (!has_value()) { return _string_type(); }
1331 return std::get<_value_result_data>(_data).result.value;
1332 }
1333
1334 #pragma endregion RESULT
1335
1336 #pragma region ALL_SUB_RESULTS
1337
1339 _PCRE2CPP_CONSTEXPR20 std::vector<std::optional<sub_match_value> > get_sub_results() const noexcept {
1340 if (!has_value()) { return {}; }
1341 return std::get<_value_result_data>(_data).sub_results;
1342 }
1343
1345 _PCRE2CPP_CONSTEXPR17 size_t get_sub_results_count() const noexcept { return get_sub_results().size(); }
1346
1348 _PCRE2CPP_CONSTEXPR20 std::vector<size_t> get_sub_results_global_offsets() const noexcept {
1349 if (!has_value()) { return {}; }
1350
1351 const auto& value = std::get<_value_result_data>(_data);
1352
1353 std::vector<size_t> offsets;
1354 offsets.reserve(value.sub_results.size());
1355 for (const auto& subResult : value.sub_results) {
1356 if (subResult.has_value()) {
1357 offsets.push_back(value.search_offset + value.result.relative_offset + subResult->relative_offset);
1358 }
1359 else { offsets.push_back(bad_offset); }
1360 }
1361 return offsets;
1362 }
1363
1365 _PCRE2CPP_CONSTEXPR20 std::vector<size_t> get_sub_results_relative_offsets() const noexcept {
1366 if (!has_value()) { return {}; }
1367
1368 const auto& value = std::get<_value_result_data>(_data);
1369
1370 std::vector<size_t> offsets;
1371 offsets.reserve(value.sub_results.size());
1372 for (const auto& subResult : value.sub_results) {
1373 if (subResult.has_value()) {
1374 offsets.push_back(value.result.relative_offset + subResult->relative_offset);
1375 }
1376 else { offsets.push_back(bad_offset); }
1377 }
1378 return offsets;
1379 }
1380
1382 _PCRE2CPP_CONSTEXPR20 std::vector<size_t> get_sub_results_in_result_offsets() const noexcept {
1383 if (!has_value()) { return {}; }
1384
1385 const auto& sub_results = std::get<_value_result_data>(_data).sub_results;
1386
1387 std::vector<size_t> offsets;
1388 offsets.reserve(sub_results.size());
1389 for (const auto& subResult : sub_results) {
1390 if (subResult.has_value()) { offsets.push_back(subResult->relative_offset); }
1391 else { offsets.push_back(bad_offset); }
1392 }
1393 return offsets;
1394 }
1395
1397 _PCRE2CPP_CONSTEXPR20 std::vector<size_t> get_sub_results_sizes() const noexcept {
1398 if (!has_value()) { return {}; }
1399
1400 const auto& sub_results = std::get<_value_result_data>(_data).sub_results;
1401
1402 std::vector<size_t> values;
1403 values.reserve(sub_results.size());
1404 for (const auto& subResult : sub_results) {
1405 if (subResult.has_value()) { values.emplace_back(subResult->size); }
1406 else { values.push_back(0); }
1407 }
1408 return values;
1409 }
1410
1412 _PCRE2CPP_CONSTEXPR17 std::vector<_string_type> get_sub_results_values() const noexcept {
1413 if (!has_value()) { return {}; }
1414
1415 const auto& data = std::get<_value_result_data>(_data);
1416 const auto& value = data.result.value;
1417 const auto& sub_results = data.sub_results;
1418
1419 std::vector<_string_type> values;
1420 values.reserve(sub_results.size());
1421 for (const auto& subResult : sub_results) {
1422 if (subResult.has_value()) {
1423 values.emplace_back(value.data() + subResult->relative_offset, subResult->size);
1424 }
1425 else { values.push_back(_string_type()); }
1426 }
1427 return values;
1428 }
1429
1430 #pragma endregion ALL_SUB_RESULTS
1431
1432 #pragma region SUB_RESULTS_BY_IDX
1433
1436 return _get_sub_value(idx);
1437 }
1438
1441 if (!has_sub_value(idx)) { return bad_offset; }
1442
1443 const auto [relative_offset, size] = _get_sub_value(idx);
1444 const auto& value = std::get<_value_result_data>(_data);
1445 return value.search_offset + value.result.relative_offset + relative_offset;
1446 }
1447
1450 if (!has_sub_value(idx)) { return bad_offset; }
1451
1452 const auto [relative_offset, size] = _get_sub_value(idx);
1453 const auto& value = std::get<_value_result_data>(_data);
1454 return value.result.relative_offset + relative_offset;
1455 }
1456
1459 if (!has_sub_value(idx)) { return bad_offset; }
1460 return _get_sub_value(idx).relative_offset;
1461 }
1462
1465 if (!has_sub_value(idx)) { return 0; }
1466 return _get_sub_value(idx).size;
1467 }
1468
1471 if (!has_sub_value(idx)) { return _string_type(); }
1472
1473 const auto [relative_offset, size] = _get_sub_value(idx);
1474 const auto& value = std::get<_value_result_data>(_data).result.value;
1475 return _string_type(value.data() + relative_offset, size);
1476 }
1477
1478 #pragma endregion
1479
1480 #pragma region SUB_RESULTS_BY_NAME
1481
1484 return get_sub_result(_get_named_sub_result_idx(name));
1485 }
1486
1488 _PCRE2CPP_CONSTEXPR17 size_t get_sub_result_global_offset(const _string_view_type name) const _PCRE2CPP_NOEXCEPT {
1489 return get_sub_result_global_offset(_get_named_sub_result_idx(name));
1490 }
1491
1494 return get_sub_result_relative_offset(_get_named_sub_result_idx(name));
1495 }
1496
1499 return get_sub_result_in_result_offset(_get_named_sub_result_idx(name));
1500 }
1501
1503 _PCRE2CPP_CONSTEXPR17 size_t get_sub_result_size(const _string_view_type name) const _PCRE2CPP_NOEXCEPT {
1504 return get_sub_result_size(_get_named_sub_result_idx(name));
1505 }
1506
1508 _PCRE2CPP_CONSTEXPR17 _string_type get_sub_result_value(const _string_view_type name) const _PCRE2CPP_NOEXCEPT {
1509 return get_sub_result_value(_get_named_sub_result_idx(name));
1510 }
1511
1512 #pragma endregion
1513
1514 #pragma endregion RESULTS
1515 };
1516
1517 #if _PCRE2CPP_HAS_UTF8
1519 #endif
1520 #if _PCRE2CPP_HAS_UTF16
1522 #endif
1523 #if _PCRE2CPP_HAS_UTF32
1525 #endif
1526
1527 #if _PCRE2CPP_HAS_UTF8
1529 #elif _PCRE2CPP_HAS_UTF16
1531 #elif _PCRE2CPP_HAS_UTF32
1533 #endif
1534} // namespace pcre2cpp
1535 #endif
1536#endif
1537#pragma endregion // match_match_result.hpp
1538
1539#pragma region regex_compile_options.hpp
1540#ifndef _PCRE2CPP_COMPILE_OPTIONS_HPP_
1541 #define _PCRE2CPP_COMPILE_OPTIONS_HPP_
1542
1543 #include <pcre2cpp/config.hpp>
1544
1545 #if !_PCRE2CPP_HAS_CXX17
1546_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
1547 #else
1548
1549 #include <pcre2cpp/types.hpp>
1550
1551namespace pcre2cpp {
1556 enum class compile_options_bits : uint32_t {
1558 None = 0u,
1560 Anchored = PCRE2_ANCHORED,
1562 AllowEmptyClass = PCRE2_ALLOW_EMPTY_CLASS,
1564 AltBSUX = PCRE2_ALT_BSUX,
1566 AltCircumflex = PCRE2_ALT_CIRCUMFLEX,
1568 AltVerbNames = PCRE2_ALT_VERBNAMES,
1570 AutoCallout = PCRE2_AUTO_CALLOUT,
1572 Caseless = PCRE2_CASELESS,
1574 DollarEndonly = PCRE2_DOLLAR_ENDONLY,
1576 DotAll = PCRE2_DOTALL,
1578 DupNames = PCRE2_DUPNAMES,
1580 EndAnchored = PCRE2_ENDANCHORED,
1582 Extended = PCRE2_EXTENDED,
1584 FirstLine = PCRE2_FIRSTLINE,
1586 Literal = PCRE2_LITERAL,
1588 MatchInvalidUTF = PCRE2_MATCH_INVALID_UTF,
1590 MatchUnsetBackRef = PCRE2_MATCH_UNSET_BACKREF,
1592 Multiline = PCRE2_MULTILINE,
1594 NeverBackslashC = PCRE2_NEVER_BACKSLASH_C,
1596 NeverUCP = PCRE2_NEVER_UCP,
1598 NeverUTF = PCRE2_NEVER_UTF,
1600 NoAutoCapture = PCRE2_NO_AUTO_CAPTURE,
1602 NoAutoPossess = PCRE2_NO_AUTO_POSSESS,
1604 NoDotStarAnchor = PCRE2_NO_DOTSTAR_ANCHOR,
1606 NoStartOptimize = PCRE2_NO_START_OPTIMIZE,
1608 NoUTFCheck = PCRE2_NO_UTF_CHECK,
1610 UCP = PCRE2_UCP,
1612 UnGreedy = PCRE2_UNGREEDY,
1614 UseOffsetLimit = PCRE2_USE_OFFSET_LIMIT,
1616 UTF = PCRE2_UTF
1617 };
1618
1623 using compile_options = mstd::flags<compile_options_bits>;
1624
1632 const compile_options_bits opt1) noexcept {
1633 return mstd::operator|(opt0, opt1);
1634 }
1635} // namespace pcre2cpp
1636 #endif
1637#endif
1638#pragma endregion // regex_compile_options.hpp
1639
1640#pragma region regex_regex.hpp
1641#ifndef _PCRE2CPP_REGEX_HPP_
1642 #define _PCRE2CPP_REGEX_HPP_
1643
1644 #include <pcre2cpp/config.hpp>
1645
1646 #if !_PCRE2CPP_HAS_CXX17
1647_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
1648 #else
1649
1655 #include <pcre2cpp/types.hpp>
1657
1658namespace pcre2cpp {
1664 template<utf_type utf>
1666 private:
1667 using _pcre2_data_t = utils::pcre2_data<utf>;
1668
1669 using _code_type = typename _pcre2_data_t::code_type;
1670 using _code_ptr = std::shared_ptr<_code_type>;
1671 using _match_data_type = typename _pcre2_data_t::match_data_type;
1672 using _match_data_ptr = std::shared_ptr<_match_data_type>;
1673 using _string_type = typename _pcre2_data_t::string_type;
1674 using _string_view_type = typename _pcre2_data_t::string_view_type;
1675 using _string_char_type = typename _pcre2_data_t::string_char_type;
1676 using _match_value_type = basic_match_value<utf>;
1677 using _match_result_type = basic_match_result<utf>;
1678 using _sptr_type = typename _pcre2_data_t::sptr_type;
1679 using _named_sub_values_table = std::unordered_map<_string_type, size_t>;
1680 using _named_sub_values_table_ptr = std::shared_ptr<_named_sub_values_table>;
1681 using _uchar_type = typename _pcre2_data_t::uchar_type;
1682 #if _PCRE2CPP_HAS_EXCEPTIONS
1683 using _regex_exception = basic_regex_exception<utf>;
1684 #endif
1685
1687 _code_ptr _code = nullptr;
1689 _match_data_ptr _match_data = nullptr;
1691 _named_sub_values_table_ptr _named_sub_values = nullptr;
1692
1694 int _error_code = 0;
1696 size_t _error_offset = 0;
1697
1698 static _PCRE2CPP_CONSTEXPR17 _string_type _get_regex_not_initialized_error() noexcept {
1699 #if _PCRE2CPP_HAS_UTF8
1700 if _PCRE2CPP_CONSTEXPR17 (utf == utf_type::UTF_8) { return "Regex was not initialized!!"; }
1701 else
1702 #endif
1703 #if _PCRE2CPP_HAS_UTF16
1705 return u"Regex was not initialized!!";
1706 }
1707 else
1708 #endif
1709 #if _PCRE2CPP_HAS_UTF32
1711 return U"Regex was not initialized!!";
1712 }
1713 else
1714 #endif
1715 {
1716 return _string_type();
1717 }
1718 }
1719
1720 public:
1722 _PCRE2CPP_CONSTEXPR20 explicit basic_regex(const _string_view_type pattern,
1724 // Compile Code
1725 _code_type* code = _pcre2_data_t::compile(reinterpret_cast<_sptr_type>(pattern.data()), pattern.size(), opts,
1726 &_error_code, &_error_offset, nullptr);
1727
1728 if (code == nullptr) {
1729 #if !_PCRE2CPP_HAS_EXCEPTIONS
1730 std::string message = fmt::format("Failed to initialize code: {}",
1731 convert_any_utf_to_utf8<utf>(generate_error_message<utf>(_error_code, _error_offset)));
1732 pcre2cpp_assert(false, "{}", message);
1733 return;
1734 #else
1735 throw _regex_exception(_error_code, _error_offset);
1736 #endif
1737 }
1738
1739 _code = std::shared_ptr<_code_type>(code, _pcre2_data_t::code_free);
1740
1741 // Get Named Sub Values
1742 _named_sub_values = std::make_shared<_named_sub_values_table>();
1743
1744 size_t name_count = 0;
1745 _uchar_type* name_table = nullptr;
1746 size_t name_entry_size = 0;
1747
1748 _pcre2_data_t::get_info(_code.get(), PCRE2_INFO_NAMECOUNT, &name_count);
1749 _pcre2_data_t::get_info(_code.get(), PCRE2_INFO_NAMETABLE, &name_table);
1750 _pcre2_data_t::get_info(_code.get(), PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size);
1751
1752 for (size_t i = 0; i != name_count; ++i) {
1753 _uchar_type* entry = name_table + i * name_entry_size + 2;
1754 const int index = _pcre2_data_t::substring_number_from_name(_code.get(), entry);
1755
1756 _uchar_type* entry_end = entry + 1;
1757 while (*entry_end != 0 && entry_end - entry < name_entry_size - 3) { entry_end += 1; }
1758 _named_sub_values->emplace(_string_type(entry, entry_end), static_cast<size_t>(index) - 1);
1759 }
1760
1761 // Create Match Data
1762 _match_data_type* match_data = _pcre2_data_t::match_data_from_pattern(_code.get(), nullptr);
1763 _match_data = std::shared_ptr<_match_data_type>(match_data, _pcre2_data_t::match_data_free);
1764 }
1765
1767 _PCRE2CPP_CONSTEXPR17 basic_regex(const basic_regex& other) noexcept = default;
1769 _PCRE2CPP_CONSTEXPR17 basic_regex(basic_regex&& other) noexcept = default;
1770
1773
1775 _PCRE2CPP_CONSTEXPR17 basic_regex& operator=(const basic_regex& other) noexcept = default;
1777 _PCRE2CPP_CONSTEXPR17 basic_regex& operator=(basic_regex&& other) noexcept = default;
1778
1779 #pragma region CHECK_INITIALIZATION
1780
1782 _PCRE2CPP_CONSTEXPR17 bool is_initialized() const noexcept { return _code != nullptr; }
1783
1784 #pragma endregion CHECK_INITIALIZATION
1785
1786 #pragma region ERROR
1787
1789 _PCRE2CPP_CONSTEXPR17 _string_type get_error_message() const noexcept {
1790 if (is_initialized()) {
1791 #if _PCRE2CPP_HAS_UTF8
1792 if _PCRE2CPP_CONSTEXPR17 (utf == utf_type::UTF_8) { return ""; }
1793 else
1794 #endif
1795 #if _PCRE2CPP_HAS_UTF16
1797 return L"";
1798 }
1799 else
1800 #endif
1801 #if _PCRE2CPP_HAS_UTF32
1803 return U"";
1804 }
1805 else
1806 #endif
1807 {
1808 return _string_type();
1809 }
1810 }
1811 return pcre2cpp::generate_error_message<utf>(_error_code, _error_offset);
1812 }
1813
1814 #pragma endregion ERROR
1815
1817 _PCRE2CPP_CONSTEXPR17 bool match(const _string_view_type text, const size_t offset = 0,
1819 if (!is_initialized()) {
1820 #if !_PCRE2CPP_HAS_EXCEPTIONS
1821 pcre2cpp_assert(false, "Regex was not initialized!!");
1822 return false;
1823 #else
1824 throw _regex_exception(_get_regex_not_initialized_error());
1825 #endif
1826 }
1827
1828 const int match_code = _pcre2_data_t::match(_code.get(), reinterpret_cast<_sptr_type>(text.data()), text.size(),
1829 offset, opts, _match_data.get(), nullptr);
1830
1831 return match_code != static_cast<int>(match_error_codes::NoMatch) && match_code > 0;
1832 }
1833
1835 _PCRE2CPP_CONSTEXPR20 bool match(const _string_view_type text, _match_result_type& result, const size_t offset = 0,
1836 const match_options opts = match_options_bits::None) const noexcept {
1837 if (!is_initialized()) {
1838 #if !_PCRE2CPP_HAS_EXCEPTIONS
1839 pcre2cpp_assert(false, "Regex was not initialized!!");
1840 return false;
1841 #else
1842 throw _regex_exception(_get_regex_not_initialized_error());
1843 #endif
1844 }
1845
1846 const int match_code = _pcre2_data_t::match(_code.get(), reinterpret_cast<_sptr_type>(text.data()), text.size(),
1847 offset, opts, _match_data.get(), nullptr);
1848
1849 if (match_code == static_cast<int>(match_error_codes::NoMatch) || match_code <= 0) {
1850 result = _match_result_type(static_cast<match_error_codes>(match_code));
1851 return false;
1852 }
1853
1854 const size_t* offsetVector = _pcre2_data_t::get_ovector_ptr(_match_data.get());
1855 const size_t matchStart = offsetVector[0];
1856 const size_t matchEnd = offsetVector[1];
1857 _match_value_type value = { .relative_offset = matchStart - offset,
1858 .value = _string_type(text.substr(matchStart, matchEnd - matchStart)) };
1859
1860 const size_t offsetVectorsCount = _pcre2_data_t::get_ovector_count(_match_data.get());
1861 std::vector<std::optional<sub_match_value> > sub_values;
1862 sub_values.reserve(offsetVectorsCount);
1863 for (size_t i = 1; i != offsetVectorsCount; ++i) {
1864 const size_t subMatchStart = offsetVector[i * 2];
1865 const size_t subMatchEnd = offsetVector[i * 2 + 1];
1866
1867 if (subMatchStart == PCRE2_UNSET || subMatchEnd == PCRE2_UNSET) { sub_values.emplace_back(); }
1868 else {
1869 sub_values.push_back(sub_match_value { .relative_offset = subMatchStart - matchStart,
1870 .size = subMatchEnd - subMatchStart });
1871 }
1872 }
1873
1874 result = _match_result_type(offset, value, sub_values, _named_sub_values);
1875 return true;
1876 }
1877
1879 _PCRE2CPP_CONSTEXPR17 bool match_at(const _string_view_type text, const size_t offset = 0) const noexcept {
1880 _match_result_type result;
1881 return match_at(text, result, offset);
1882 }
1883
1885 _PCRE2CPP_CONSTEXPR17 bool match_at(const _string_view_type text, _match_result_type& result,
1886 const size_t offset = 0) const noexcept {
1887 if (!match(text, result, offset)) { return false; }
1888
1889 if (result.get_result_relative_offset() != 0) {
1890 result = _match_result_type(offset, _named_sub_values);
1891 return false;
1892 }
1893
1894 return true;
1895 }
1896
1898 _PCRE2CPP_CONSTEXPR17 bool match_all(const _string_view_type text, std::vector<_match_result_type>& results,
1899 size_t offset = 0) const noexcept {
1900 size_t start_offset = offset;
1901 _match_result_type result;
1902 while (match(text, result, offset)) {
1903 results.emplace_back(start_offset,
1904 _match_value_type { .relative_offset = offset - start_offset + result.get_result_relative_offset(),
1905 .value = result.get_result_value() },
1906 result.get_sub_results(), _named_sub_values);
1907 offset += result.get_result_relative_offset() + result.get_result_size();
1908 }
1909
1910 return results.size() != 0;
1911 }
1912 };
1913
1914 #if _PCRE2CPP_HAS_UTF8
1916 #endif
1917 #if _PCRE2CPP_HAS_UTF16
1919 #endif
1920 #if _PCRE2CPP_HAS_UTF32
1922 #endif
1923
1924 #if _PCRE2CPP_HAS_UTF8
1926 #elif _PCRE2CPP_HAS_UTF16
1927 using regex = u16regex;
1928 #elif _PCRE2CPP_HAS_UTF32
1929 using regex = u32regex;
1930 #endif
1931} // namespace pcre2cpp
1932 #endif
1933#endif
1934#pragma endregion // regex_regex.hpp
1935
1936#pragma region utils_assert.hpp
1937#ifndef _PCRE2CPP_ASSERT_HPP_
1938 #define _PCRE2CPP_ASSERT_HPP_
1939
1940 #include <pcre2cpp/config.hpp>
1941
1942 #if !_PCRE2CPP_HAS_ASSERTS
1943_PCRE2CPP_ERROR("This is only available for c++17 and greater and when asserts are enabled!");
1944 #else
1945
1946
1952
1953 #if _DEBUG
1954 #define pcre2cpp_assert(expression, ...) \
1955 MSTD_STOP_ASSERT_BASE(expression, [](const std::string_view) -> void {} __VA_OPT__(, ) __VA_ARGS__)
1956 #elif !defined(PCRE2CPP_DISABLE_ASSERT_ON_RELEASE)
1957 #define pcre2cpp_assert(expression, ...) \
1958 MSTD_LOG_ASSERT_BASE(expression, [](const std::string_view) -> void {} __VA_OPT__(, ) __VA_ARGS__)
1959 #else
1960 #define pcre2cpp_assert(expression, ...) \
1961 MSTD_EMPTY_ASSERT_BASE(expression, [](const std::string_view) -> void {} __VA_OPT__(, ) __VA_ARGS__)
1962 #endif
1963
1964 #endif
1965#endif
1966#pragma endregion // utils_assert.hpp
1967
1968#pragma region pcre2cpp.hpp
1969#ifndef _PCRE2CPP_PCRE2CPP_HPP_
1970 #define _PCRE2CPP_PCRE2CPP_HPP_
1971
1972
1973 #if !_PCRE2CPP_HAS_CXX17
1974_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
1975 #else
1976
1977
1978
1979
1980 #if _PCRE2CPP_HAS_ASSERTS
1981 #endif
1982
1983 #endif
1984#endif
1985#pragma endregion // pcre2cpp.hpp
1986
Basic container to result data of match function.
Definition pcre2cpp.hpp:1090
_PCRE2CPP_CONSTEXPR17 basic_match_result(const size_t search_offset, const _named_sub_values_table_ptr &named_sub_values) noexcept
constructor with no value but also without error
Definition pcre2cpp.hpp:1218
_PCRE2CPP_CONSTEXPR17 bool has_result() const noexcept
returns true when result holds some result not error
Definition pcre2cpp.hpp:1276
_PCRE2CPP_CONSTEXPR17 match_error_codes get_error_code() const noexcept
return error code
Definition pcre2cpp.hpp:1252
_PCRE2CPP_CONSTEXPR17 basic_match_result(basic_match_result &&other) noexcept=default
default move constructor
_PCRE2CPP_CONSTEXPR17 bool has_sub_value(const _string_view_type name) const noexcept
returns true when result has sub value with given name
Definition pcre2cpp.hpp:1291
_PCRE2CPP_CONSTEXPR17 size_t get_search_offset() const noexcept
returns search offset
Definition pcre2cpp.hpp:1296
_PCRE2CPP_CONSTEXPR17 size_t get_sub_results_count() const noexcept
returns sub results count
Definition pcre2cpp.hpp:1345
_PCRE2CPP_CONSTEXPR17 sub_match_value get_sub_result(const _string_view_type name) const _PCRE2CPP_NOEXCEPT
returns sub result container
Definition pcre2cpp.hpp:1483
_PCRE2CPP_CONSTEXPR17 basic_match_result() noexcept=default
default constructor
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_relative_offset(const _string_view_type name) const _PCRE2CPP_NOEXCEPT
returns sub result offset relative to search offset
Definition pcre2cpp.hpp:1493
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_global_offset(const _string_view_type name) const _PCRE2CPP_NOEXCEPT
returns sub result offset from the beginning of searched string
Definition pcre2cpp.hpp:1488
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_global_offset(const size_t idx) const _PCRE2CPP_NOEXCEPT
returns sub result offset from the beginning of searched string
Definition pcre2cpp.hpp:1440
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_size(const size_t idx) const _PCRE2CPP_NOEXCEPT
returns sub result value size
Definition pcre2cpp.hpp:1464
_PCRE2CPP_CONSTEXPR17 std::vector< _string_type > get_sub_results_values() const noexcept
returns sub results string values
Definition pcre2cpp.hpp:1412
_PCRE2CPP_CONSTEXPR17 basic_match_result(const basic_match_result &other) noexcept=default
default copy constructor
_PCRE2CPP_CONSTEXPR20 std::vector< size_t > get_sub_results_sizes() const noexcept
returns sub results value sizes
Definition pcre2cpp.hpp:1397
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_in_result_offset(const _string_view_type name) const _PCRE2CPP_NOEXCEPT
returns sub result offset relative to result offset
Definition pcre2cpp.hpp:1498
_PCRE2CPP_CONSTEXPR17 sub_match_value get_sub_result(const size_t idx) const _PCRE2CPP_NOEXCEPT
returns sub result container
Definition pcre2cpp.hpp:1435
static _PCRE2CPP_CONSTEXPR17 size_t bad_offset
Definition pcre2cpp.hpp:1093
_PCRE2CPP_CONSTEXPR17 _string_type get_error_message() const noexcept
returns error message
Definition pcre2cpp.hpp:1258
_PCRE2CPP_CONSTEXPR17 _match_value get_result() const noexcept
returns match result container
Definition pcre2cpp.hpp:1304
_PCRE2CPP_CONSTEXPR17 size_t get_result_global_offset() const noexcept
returns offset of value from the beginning of searched string
Definition pcre2cpp.hpp:1310
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_in_result_offset(const size_t idx) const _PCRE2CPP_NOEXCEPT
returns sub result offset relative to result offset
Definition pcre2cpp.hpp:1458
_PCRE2CPP_CONSTEXPR20 std::vector< size_t > get_sub_results_in_result_offsets() const noexcept
returns sub results offsets relative to result offset
Definition pcre2cpp.hpp:1382
_PCRE2CPP_CONSTEXPR20 std::vector< std::optional< sub_match_value > > get_sub_results() const noexcept
returns all sub results
Definition pcre2cpp.hpp:1339
_PCRE2CPP_CONSTEXPR17 bool has_error() const noexcept
returns true if result holds error
Definition pcre2cpp.hpp:1249
_PCRE2CPP_CONSTEXPR17 basic_match_result(const size_t search_offset, const _match_value &result, const std::vector< std::optional< sub_match_value > > &sub_results, const _named_sub_values_table_ptr &named_sub_values) noexcept
constructor with good result
Definition pcre2cpp.hpp:1223
_PCRE2CPP_CONSTEXPR17 _string_type get_result_value() const noexcept
returns match string value
Definition pcre2cpp.hpp:1329
_PCRE2CPP_CONSTEXPR20 std::vector< size_t > get_sub_results_global_offsets() const noexcept
returns sub results offsets from the beginning of search string
Definition pcre2cpp.hpp:1348
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_relative_offset(const size_t idx) const _PCRE2CPP_NOEXCEPT
returns sub result offset relative to search offset
Definition pcre2cpp.hpp:1449
_PCRE2CPP_CONSTEXPR17 size_t get_result_size() const noexcept
returns size of match value
Definition pcre2cpp.hpp:1323
_PCRE2CPP_CONSTEXPR20 std::vector< size_t > get_sub_results_relative_offsets() const noexcept
returns sub results offsets relative to search offset
Definition pcre2cpp.hpp:1365
_PCRE2CPP_CONSTEXPR17 size_t get_result_relative_offset() const noexcept
return offset relative to search offset
Definition pcre2cpp.hpp:1317
_PCRE2CPP_CONSTEXPR17 _string_type get_sub_result_value(const _string_view_type name) const _PCRE2CPP_NOEXCEPT
returns sub result string value
Definition pcre2cpp.hpp:1508
_PCRE2CPP_CONSTEXPR20 ~basic_match_result() noexcept=default
default destructor
_PCRE2CPP_CONSTEXPR17 bool has_value() const noexcept
returns true when result has value
Definition pcre2cpp.hpp:1279
_PCRE2CPP_CONSTEXPR17 bool has_sub_value(const size_t idx) const noexcept
returns true when result has sub value on given index
Definition pcre2cpp.hpp:1285
_PCRE2CPP_CONSTEXPR17 size_t get_sub_result_size(const _string_view_type name) const _PCRE2CPP_NOEXCEPT
returns sub result value size
Definition pcre2cpp.hpp:1503
_PCRE2CPP_CONSTEXPR17 _string_type get_sub_result_value(const size_t idx) const _PCRE2CPP_NOEXCEPT
returns sub result string value
Definition pcre2cpp.hpp:1470
Basic PCRE2 Regex container.
Definition pcre2cpp.hpp:1665
_PCRE2CPP_CONSTEXPR17 basic_regex(const basic_regex &other) noexcept=default
default copy constructor
_PCRE2CPP_CONSTEXPR20 bool match(const _string_view_type text, _match_result_type &result, const size_t offset=0, const match_options opts=match_options_bits::None) const noexcept
returns true if match was found and result is stored in result variable
Definition pcre2cpp.hpp:1835
_PCRE2CPP_CONSTEXPR17 bool match_all(const _string_view_type text, std::vector< _match_result_type > &results, size_t offset=0) const noexcept
returns true if any match was found and all results store in results array
Definition pcre2cpp.hpp:1898
_PCRE2CPP_CONSTEXPR20 basic_regex(const _string_view_type pattern, const compile_options opts=compile_options_bits::None) _PCRE2CPP_NOEXCEPT
basic regex container with pattern and compile options
Definition pcre2cpp.hpp:1722
_PCRE2CPP_CONSTEXPR17 bool match(const _string_view_type text, const size_t offset=0, const match_options opts=match_options_bits::None) const _PCRE2CPP_NOEXCEPT
returns true if match was found
Definition pcre2cpp.hpp:1817
_PCRE2CPP_CONSTEXPR17 bool is_initialized() const noexcept
returns true if regex was initialized
Definition pcre2cpp.hpp:1782
_PCRE2CPP_CONSTEXPR17 _string_type get_error_message() const noexcept
returns error message if there is any compilation error
Definition pcre2cpp.hpp:1789
_PCRE2CPP_CONSTEXPR17 bool match_at(const _string_view_type text, _match_result_type &result, const size_t offset=0) const noexcept
returns true if match was found, and it has relative offset == 0 and result is stored in result varia...
Definition pcre2cpp.hpp:1885
_PCRE2CPP_CONSTEXPR17 basic_regex(basic_regex &&other) noexcept=default
default move constructor
_PCRE2CPP_CONSTEXPR20 ~basic_regex() noexcept=default
default destructor
_PCRE2CPP_CONSTEXPR17 bool match_at(const _string_view_type text, const size_t offset=0) const noexcept
returns true if match was found, and it has relative offset == 0
Definition pcre2cpp.hpp:1879
#define _PCRE2CPP_NOEXCEPT
Definition config.hpp:178
utf_type
Enum with supported utf types.
Definition pcre2cpp.hpp:352
compile_options_bits
Compile options.
Definition pcre2cpp.hpp:1556
match_options_bits
Match options.
Definition pcre2cpp.hpp:965
mstd::flags< match_options_bits > match_options
Match options flags group.
Definition pcre2cpp.hpp:998
mstd::flags< compile_options_bits > compile_options
Compile options flags group.
Definition pcre2cpp.hpp:1623
@ UTF_16
Definition pcre2cpp.hpp:357
@ UTF_32
Definition pcre2cpp.hpp:360
@ UTF_8
Definition pcre2cpp.hpp:354
@ NoAutoPossess
Disable auto - possessification.
Definition pcre2cpp.hpp:1602
@ MatchUnsetBackRef
Match unset backreferences.
Definition pcre2cpp.hpp:1590
@ DollarEndonly
$ not to match newline at end
Definition pcre2cpp.hpp:1574
@ Caseless
Do caseless matching.
Definition pcre2cpp.hpp:1572
@ AllowEmptyClass
Allow empty classes.
Definition pcre2cpp.hpp:1562
@ DotAll
. matches anything including NL
Definition pcre2cpp.hpp:1576
@ NoDotStarAnchor
Disable automatic anchoring for .*.
Definition pcre2cpp.hpp:1604
@ NeverUCP
Lock out PCRE2_UCP, e.g.via(*UCP).
Definition pcre2cpp.hpp:1596
@ AutoCallout
Compile automatic callouts.
Definition pcre2cpp.hpp:1570
@ AltVerbNames
Process backslashes in verb names.
Definition pcre2cpp.hpp:1568
@ AltCircumflex
Alternative handling of ^ in multiline mode.
Definition pcre2cpp.hpp:1566
@ NoStartOptimize
Disable match - time start optimizations.
Definition pcre2cpp.hpp:1606
@ None
No options set (default).
Definition pcre2cpp.hpp:1558
@ Multiline
^ and $ match newlines within data
Definition pcre2cpp.hpp:1592
@ UnGreedy
Invert greediness of quantifiers.
Definition pcre2cpp.hpp:1612
@ UTF
Treat pattern and subjects as UTF strings.
Definition pcre2cpp.hpp:1616
@ NoAutoCapture
Disable numbered capturing paren - theses(named ones available).
Definition pcre2cpp.hpp:1600
@ UseOffsetLimit
Enable offset limit for unanchored matching.
Definition pcre2cpp.hpp:1614
@ MatchInvalidUTF
Enable support for matching invalid UTF.
Definition pcre2cpp.hpp:1588
@ AltBSUX
Alternative handling of \u, \U, and \x.
Definition pcre2cpp.hpp:1564
@ NeverUTF
Lock out PCRE2_UTF, e.g.via(*UTF).
Definition pcre2cpp.hpp:1598
@ FirstLine
Force matching to be before newline.
Definition pcre2cpp.hpp:1584
@ DupNames
Allow duplicate names for subpatterns.
Definition pcre2cpp.hpp:1578
@ Literal
Pattern characters are all literal.
Definition pcre2cpp.hpp:1586
@ NeverBackslashC
Lock out the use of \C in patterns.
Definition pcre2cpp.hpp:1594
@ Extended
Ignore white space and # comments.
Definition pcre2cpp.hpp:1582
@ UCP
Use Unicode properties for \d, \w, etc.
Definition pcre2cpp.hpp:1610
@ NotEOL
Subject string is not the end of a line.
Definition pcre2cpp.hpp:979
@ PartialHard
Return match_error_codes::Partial for a partial match even if there is a full match.
Definition pcre2cpp.hpp:989
@ NotBOL
Subject string is not the beginning of a line.
Definition pcre2cpp.hpp:977
@ NotEmpty
An empty string is not a valid match.
Definition pcre2cpp.hpp:981
@ PartialSoft
Return match_error_codes::Partial for a partial match if no full matches are found.
Definition pcre2cpp.hpp:991
@ None
No options set (default).
Definition pcre2cpp.hpp:967
@ CopyMatchedSubject
On success, make a private subject copy.
Definition pcre2cpp.hpp:971
@ NoUTFCheck
Do not check the subject for UTF validity(only relevant if compile_options::UTF was set at compile ti...
Definition pcre2cpp.hpp:987
@ Anchored
Match only at the first position.
Definition pcre2cpp.hpp:969
@ NotEmptyAtStart
An empty string at the start of the subject is not a valid match.
Definition pcre2cpp.hpp:983
@ EndAnchored
Pattern can match only at end of subject.
Definition pcre2cpp.hpp:975
@ DisableRecurseLoopCheck
Only useful in rare cases; use with care.
Definition pcre2cpp.hpp:973
@ NoJIT
Do not use JIT matching.
Definition pcre2cpp.hpp:985
#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
#define pcre2cpp_assert(expression,...)
pcre2cpp assert
Definition pcre2cpp.hpp:1957
Definition pcre2cpp.hpp:310
pcre2_data< utf_type::UTF_8 > u8pcre2_data
Definition pcre2cpp.hpp:675
pcre2_data< utf_type::UTF_32 > u32pcre2_data
Definition pcre2cpp.hpp:681
pcre2_data< utf_type::UTF_16 > u16pcre2_data
Definition pcre2cpp.hpp:678
Main namespace of pcre2cpp library.
basic_regex< utf_type::UTF_16 > u16regex
Definition pcre2cpp.hpp:1918
basic_match_result< utf_type::UTF_8 > u8match_result
Definition pcre2cpp.hpp:1518
basic_match_result< utf_type::UTF_32 > u32match_result
Definition pcre2cpp.hpp:1524
u8regex regex
Definition pcre2cpp.hpp:1925
basic_regex< utf_type::UTF_32 > u32regex
Definition pcre2cpp.hpp:1921
basic_match_result< utf_type::UTF_16 > u16match_result
Definition pcre2cpp.hpp:1521
u8match_result match_result
Definition pcre2cpp.hpp:1528
u8match_value match_value
Definition pcre2cpp.hpp:1061
basic_match_value< utf_type::UTF_16 > u16match_value
Definition pcre2cpp.hpp:1054
basic_regex< utf_type::UTF_8 > u8regex
Definition pcre2cpp.hpp:1915
basic_match_value< utf_type::UTF_32 > u32match_value
Definition pcre2cpp.hpp:1057
basic_match_value< utf_type::UTF_8 > u8match_value
Definition pcre2cpp.hpp:1051
Match value container.
Definition pcre2cpp.hpp:1039
_string_type value
Definition pcre2cpp.hpp:1047
size_t relative_offset
Definition pcre2cpp.hpp:1045
Sub match value container.
Definition pcre2cpp.hpp:1075
size_t size
size of value
Definition pcre2cpp.hpp:1079
size_t relative_offset
offset relative to search offset
Definition pcre2cpp.hpp:1077
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, sptr_type)> substring_number_from_name
pointer to pcre2_substring_number_from_name function for utf-16
Definition pcre2cpp.hpp:568
string_type::value_type string_char_type
cpp string char type for utf-16
Definition pcre2cpp.hpp:516
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< size_t *(match_data_type *)> get_ovector_ptr
pointer to pcre2_get_ovector_pointer function for utf-16
Definition pcre2cpp.hpp:551
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(int, uchar_type *, size_t)> get_error_message
pointer to pcre2_get_error_message function for utf-16
Definition pcre2cpp.hpp:558
pcre2_compile_context_16 compile_ctx_type
pcre2 compile context structure type for utf-16
Definition pcre2cpp.hpp:491
pcre2_general_context_16 general_ctx_type
pcre2 general context structure type for utf-16
Definition pcre2cpp.hpp:493
pcre2_code_16 code_type
pcre2 code structure type for utf-16
Definition pcre2cpp.hpp:489
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< uint32_t(match_data_type *)> get_ovector_count
pointer to pcre2_get_ovector_count function for utf-16
Definition pcre2cpp.hpp:553
static _PCRE2CPP_CONSTEXPR17 utf_type uft
utf enum value for utf-16
Definition pcre2cpp.hpp:521
static _PCRE2CPP_CONSTEXPR17 size_t utf_size
utf byte size for utf-16
Definition pcre2cpp.hpp:523
pcre2_match_data_16 match_data_type
pcre2 match data structure type for utf-16
Definition pcre2cpp.hpp:498
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< match_data_type *(const code_type *, general_ctx_type *)> match_data_from_pattern
pointer to pcre2_match_data_create_from_pattern function for utf-16
Definition pcre2cpp.hpp:537
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< code_type *(sptr_type, size_t, uint32_t, int *, size_t *, compile_ctx_type *)> compile
pointer to pcre2_compile function for utf-16
Definition pcre2cpp.hpp:529
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, sptr_type, size_t, size_t, uint32_t, match_data_type *, match_ctx_type *)> match
pointer to pcre2_match function for utf-16
Definition pcre2cpp.hpp:546
pcre2_match_context_16 match_ctx_type
pcre2 match context structure type for utf-16
Definition pcre2cpp.hpp:500
std::u16string_view string_view_type
cpp string view type for utf-16
Definition pcre2cpp.hpp:514
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, uint32_t, void *)> get_info
pointer to pcre2_pattern_info function for utf-16
Definition pcre2cpp.hpp:563
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< void(code_type *)> code_free
pointer to pcre2_code_free function for utf-16
Definition pcre2cpp.hpp:531
PCRE2_UCHAR16 uchar_type
pcre2 unsigned char type for utf-16
Definition pcre2cpp.hpp:507
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< void(match_data_type *)> match_data_free
pointer to pcre2_match_data_free function for utf-16
Definition pcre2cpp.hpp:539
std::u16string string_type
cpp string type for utf-16
Definition pcre2cpp.hpp:512
PCRE2_SPTR16 sptr_type
pcre2 string pointer type for utf-16
Definition pcre2cpp.hpp:505
static _PCRE2CPP_CONSTEXPR17 utf_type uft
utf enum value for utf-32
Definition pcre2cpp.hpp:619
pcre2_compile_context_32 compile_ctx_type
pcre2 compile context structure type for utf-32
Definition pcre2cpp.hpp:589
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< size_t *(match_data_type *)> get_ovector_ptr
pointer to pcre2_get_ovector_pointer function for utf-32
Definition pcre2cpp.hpp:649
static _PCRE2CPP_CONSTEXPR17 size_t utf_size
utf byte size for utf-32
Definition pcre2cpp.hpp:621
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(int, uchar_type *, size_t)> get_error_message
pointer to pcre2_get_error_message function for utf-32
Definition pcre2cpp.hpp:656
string_type::value_type string_char_type
cpp string char type for utf-32
Definition pcre2cpp.hpp:614
pcre2_code_32 code_type
pcre2 code structure type for utf-32
Definition pcre2cpp.hpp:587
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< void(code_type *)> code_free
pointer to pcre2_code_free function for utf-32
Definition pcre2cpp.hpp:629
pcre2_general_context_32 general_ctx_type
pcre2 general context structure type for utf-32
Definition pcre2cpp.hpp:591
PCRE2_UCHAR32 uchar_type
pcre2 unsigned char type for utf-32
Definition pcre2cpp.hpp:605
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< void(match_data_type *)> match_data_free
pointer to pcre2_match_data_free function for utf-32
Definition pcre2cpp.hpp:637
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< match_data_type *(const code_type *, general_ctx_type *)> match_data_from_pattern
pointer to pcre2_match_data_create_from_pattern function for utf-32
Definition pcre2cpp.hpp:635
PCRE2_SPTR32 sptr_type
pcre2 string pointer type for utf-32
Definition pcre2cpp.hpp:603
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, sptr_type)> substring_number_from_name
pointer to pcre2_substring_number_from_name function for utf-32
Definition pcre2cpp.hpp:666
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< code_type *(sptr_type, size_t, uint32_t, int *, size_t *, compile_ctx_type *)> compile
pointer to pcre2_compile function for utf-32
Definition pcre2cpp.hpp:627
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, sptr_type, size_t, size_t, uint32_t, match_data_type *, match_ctx_type *)> match
pointer to pcre2_match function for utf-32
Definition pcre2cpp.hpp:644
pcre2_match_context_32 match_ctx_type
pcre2 match context structure type for utf-32
Definition pcre2cpp.hpp:598
std::u32string_view string_view_type
cpp string view type for utf-32
Definition pcre2cpp.hpp:612
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< uint32_t(match_data_type *)> get_ovector_count
pointer to pcre2_get_ovector_count function for utf-32
Definition pcre2cpp.hpp:651
pcre2_match_data_32 match_data_type
pcre2 match data structure type for utf-32
Definition pcre2cpp.hpp:596
std::u32string string_type
cpp string type for utf-32
Definition pcre2cpp.hpp:610
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, uint32_t, void *)> get_info
pointer to pcre2_pattern_info function for utf-32
Definition pcre2cpp.hpp:661
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< code_type *(sptr_type, size_t, uint32_t, int *, size_t *, compile_ctx_type *)> compile
pointer to pcre2_compile function for utf-8
Definition pcre2cpp.hpp:431
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, uint32_t, void *)> get_info
pointer to pcre2_pattern_info function for utf-8
Definition pcre2cpp.hpp:465
pcre2_match_context_8 match_ctx_type
pcre2 match context structure type for utf-8
Definition pcre2cpp.hpp:395
static _PCRE2CPP_CONSTEXPR17 size_t utf_size
utf byte size for utf-8
Definition pcre2cpp.hpp:425
PCRE2_UCHAR8 uchar_type
pcre2 unsigned char type for utf-8
Definition pcre2cpp.hpp:402
static _PCRE2CPP_CONSTEXPR17 utf_type uft
utf enum value for utf-8
Definition pcre2cpp.hpp:423
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< void(match_data_type *)> match_data_free
pointer to pcre2_match_data_free function for utf-8
Definition pcre2cpp.hpp:441
pcre2_compile_context_8 compile_ctx_type
pcre2 compile context structure type for utf-8
Definition pcre2cpp.hpp:386
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< uint32_t(match_data_type *)> get_ovector_count
pointer to pcre2_get_ovector_count function for utf-8
Definition pcre2cpp.hpp:455
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< match_data_type *(const code_type *, general_ctx_type *)> match_data_from_pattern
pointer to pcre2_match_data_create_from_pattern function for utf-8
Definition pcre2cpp.hpp:439
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(int, uchar_type *, size_t)> get_error_message
pointer to pcre2_get_error_message function for utf-8
Definition pcre2cpp.hpp:460
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< size_t *(match_data_type *)> get_ovector_ptr
pointer to pcre2_get_ovector_pointer function for utf-8
Definition pcre2cpp.hpp:453
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< void(code_type *)> code_free
pointer to pcre2_code_free function for utf-8
Definition pcre2cpp.hpp:433
pcre2_match_data_8 match_data_type
pcre2 match data structure type for utf-8
Definition pcre2cpp.hpp:393
std::string string_type
cpp string type for utf-8
Definition pcre2cpp.hpp:414
PCRE2_SPTR8 sptr_type
pcre2 string pointer type for utf-8
Definition pcre2cpp.hpp:400
string_type::value_type string_char_type
cpp string char type for utf-8
Definition pcre2cpp.hpp:418
pcre2_general_context_8 general_ctx_type
pcre2 general context structure type for utf-8
Definition pcre2cpp.hpp:388
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, sptr_type)> substring_number_from_name
pointer to pcre2_substring_number_from_name function for utf-8
Definition pcre2cpp.hpp:470
pcre2_code_8 code_type
pcre2 code structure type for utf-8
Definition pcre2cpp.hpp:384
std::string_view string_view_type
cpp string view type for utf-8
Definition pcre2cpp.hpp:416
static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t< int(const code_type *, sptr_type, size_t, size_t, uint32_t, match_data_type *, match_ctx_type *)> match
pointer to pcre2_match function for utf-8
Definition pcre2cpp.hpp:448
Translation container from pcre2 library to pcre2cpp.
Definition pcre2cpp.hpp:372