From d4ac914f3553f6d2764edc2232bb8ad3fdf4c52d Mon Sep 17 00:00:00 2001 From: Manuel Bellersen Date: Wed, 30 Oct 2024 00:13:57 +0100 Subject: [PATCH] Using current CTRE (068c626) https://github.com/hanickadot/compile-time-regular-expressions/blob/main/single-header/ctre.hpp which should fix clang 19 usage https://github.com/getml/reflect-cpp/issues/221 (#233) --- include/rfl/thirdparty/ctre.hpp | 633 +++++++++++++++++++++----------- 1 file changed, 410 insertions(+), 223 deletions(-) diff --git a/include/rfl/thirdparty/ctre.hpp b/include/rfl/thirdparty/ctre.hpp index 95ab9815..096e4114 100644 --- a/include/rfl/thirdparty/ctre.hpp +++ b/include/rfl/thirdparty/ctre.hpp @@ -233,11 +233,81 @@ Software. #ifndef CTLL__FIXED_STRING__GPP #define CTLL__FIXED_STRING__GPP +#ifndef CTLL_IN_A_MODULE #include #include #include #include #include +#endif + +#ifndef CTLL__UTILITIES__HPP +#define CTLL__UTILITIES__HPP + +#ifndef CTLL_IN_A_MODULE +#include +#endif + +#ifdef CTLL_IN_A_MODULE +#define CTLL_EXPORT export +#else +#define CTLL_EXPORT +#endif + +#if defined __cpp_nontype_template_parameter_class + #define CTLL_CNTTP_COMPILER_CHECK 1 +#elif defined __cpp_nontype_template_args +// compiler which defines correctly feature test macro (not you clang) + #if __cpp_nontype_template_args >= 201911L + #define CTLL_CNTTP_COMPILER_CHECK 1 + #elif __cpp_nontype_template_args >= 201411L +// appleclang 13+ + #if defined __apple_build_version__ + #if defined __clang_major__ && __clang_major__ >= 13 +// but only in c++20 and more + #if __cplusplus > 201703L + #define CTLL_CNTTP_COMPILER_CHECK 1 + #endif + #endif + #else +// clang 12+ + #if defined __clang_major__ && __clang_major__ >= 12 +// but only in c++20 and more + #if __cplusplus > 201703L + #define CTLL_CNTTP_COMPILER_CHECK 1 + #endif + #endif + #endif + #endif +#endif + +#ifndef CTLL_CNTTP_COMPILER_CHECK + #define CTLL_CNTTP_COMPILER_CHECK 0 +#endif + +#ifdef _MSC_VER +#define CTLL_FORCE_INLINE __forceinline +#else +#define CTLL_FORCE_INLINE __attribute__((always_inline)) +#endif + +namespace ctll { + +template struct conditional_helper; + +template <> struct conditional_helper { + template using type = A; +}; + +template <> struct conditional_helper { + template using type = B; +}; + +template using conditional = typename conditional_helper::template type; + +} + +#endif namespace ctll { @@ -273,7 +343,7 @@ struct construct_from_pointer_t { }; constexpr auto construct_from_pointer = construct_from_pointer_t{}; -template struct fixed_string { +CTLL_EXPORT template struct fixed_string { char32_t content[N] = {}; size_t real_size{0}; bool correct_flag{true}; @@ -458,66 +528,6 @@ template fixed_string(fixed_string) -> fixed_string; #ifndef CTLL__TYPE_STACK__HPP #define CTLL__TYPE_STACK__HPP -#ifndef CTLL__UTILITIES__HPP -#define CTLL__UTILITIES__HPP - -#include - -#if defined __cpp_nontype_template_parameter_class - #define CTLL_CNTTP_COMPILER_CHECK 1 -#elif defined __cpp_nontype_template_args -// compiler which defines correctly feature test macro (not you clang) - #if __cpp_nontype_template_args >= 201911L - #define CTLL_CNTTP_COMPILER_CHECK 1 - #elif __cpp_nontype_template_args >= 201411L -// appleclang 13+ - #if defined __apple_build_version__ - #if defined __clang_major__ && __clang_major__ >= 13 -// but only in c++20 and more - #if __cplusplus > 201703L - #define CTLL_CNTTP_COMPILER_CHECK 1 - #endif - #endif - #else -// clang 12+ - #if defined __clang_major__ && __clang_major__ >= 12 -// but only in c++20 and more - #if __cplusplus > 201703L - #define CTLL_CNTTP_COMPILER_CHECK 1 - #endif - #endif - #endif - #endif -#endif - -#ifndef CTLL_CNTTP_COMPILER_CHECK - #define CTLL_CNTTP_COMPILER_CHECK 0 -#endif - -#ifdef _MSC_VER -#define CTLL_FORCE_INLINE __forceinline -#else -#define CTLL_FORCE_INLINE __attribute__((always_inline)) -#endif - -namespace ctll { - -template struct conditional_helper; - -template <> struct conditional_helper { - template using type = A; -}; - -template <> struct conditional_helper { - template using type = B; -}; - -template using conditional = typename conditional_helper::template type; - -} - -#endif - namespace ctll { template struct list { }; @@ -662,7 +672,7 @@ struct anything { template struct range { constexpr inline range() noexcept { } //template constexpr range(term) noexcept requires (A <= V) && (V <= B); - template > constexpr inline range(term) noexcept; + template > constexpr range(term) noexcept; }; #ifdef __EDG__ @@ -675,9 +685,9 @@ template struct contains { template struct set { constexpr inline set() noexcept { } #ifdef __EDG__ - template ::value>> constexpr inline set(term) noexcept; + template ::value>> constexpr set(term) noexcept; #else - template > constexpr inline set(term) noexcept; + template > constexpr set(term) noexcept; #endif }; @@ -686,9 +696,9 @@ template struct neg_set { constexpr inline neg_set() noexcept { } #ifdef __EDG__ - template ::value>> constexpr inline neg_set(term) noexcept; + template ::value>> constexpr neg_set(term) noexcept; #else - template > constexpr inline neg_set(term) noexcept; + template > constexpr neg_set(term) noexcept; #endif }; @@ -750,7 +760,9 @@ namespace ctll { #endif +#ifndef CTLL_IN_A_MODULE #include +#endif namespace ctll { @@ -951,11 +963,12 @@ struct pcre { struct backslash_range {}; struct block {}; struct block_name2 {}; + struct block_name {}; struct c {}; struct class_named_name {}; struct content2 {}; - struct content {}; struct content_in_capture {}; + struct content_or_empty {}; struct d {}; struct e {}; struct f {}; @@ -973,6 +986,7 @@ struct pcre { struct number2 {}; struct number {}; struct o {}; + struct opt_content {}; struct p {}; struct property_name2 {}; struct property_name {}; @@ -1073,16 +1087,16 @@ struct pcre { struct start_lookbehind_positive: ctll::action {}; // (q)LL1 function: - using _others = ctll::neg_set<'!','$','\x28','\x29','*','+',',','-','.','/',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','0','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D','1','2','3','4','5','6','7','8','9'>; + using _others = ctll::neg_set<'!','$','\x28','\x29','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>; static constexpr auto rule(s, ctll::term<'\\'>) -> ctll::push; static constexpr auto rule(s, ctll::term<'['>) -> ctll::push; static constexpr auto rule(s, ctll::term<'\x28'>) -> ctll::push; static constexpr auto rule(s, ctll::term<'^'>) -> ctll::push; static constexpr auto rule(s, ctll::term<'$'>) -> ctll::push; - static constexpr auto rule(s, ctll::set<'!',',','/',':','<','0','-','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(s, ctll::set<'!',',','-','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; static constexpr auto rule(s, _others) -> ctll::push; static constexpr auto rule(s, ctll::term<'.'>) -> ctll::push; - static constexpr auto rule(s, ctll::term<'|'>) -> ctll::push; + static constexpr auto rule(s, ctll::term<'|'>) -> ctll::push; static constexpr auto rule(s, ctll::epsilon) -> ctll::push; static constexpr auto rule(s, ctll::set<'\x29','*','+','?','\x7B','\x7D'>) -> ctll::reject; @@ -1091,7 +1105,7 @@ struct pcre { static constexpr auto rule(a, ctll::term<'\x28'>) -> ctll::push; static constexpr auto rule(a, ctll::term<'^'>) -> ctll::push; static constexpr auto rule(a, ctll::term<'$'>) -> ctll::push; - static constexpr auto rule(a, ctll::set<'!',',','/',':','<','0','-','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(a, ctll::set<'!',',','-','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; static constexpr auto rule(a, _others) -> ctll::push; static constexpr auto rule(a, ctll::term<'.'>) -> ctll::push; static constexpr auto rule(a, ctll::term<'\x29'>) -> ctll::push; @@ -1149,19 +1163,21 @@ struct pcre { static constexpr auto rule(block, ctll::term<'\x28'>) -> ctll::push>; static constexpr auto rule(block, ctll::term<'^'>) -> ctll::push>; static constexpr auto rule(block, ctll::term<'$'>) -> ctll::push>; - static constexpr auto rule(block, ctll::set<'!',',','/',':','<','0','-','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push>; + static constexpr auto rule(block, ctll::set<'!',',','-','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push>; static constexpr auto rule(block, _others) -> ctll::push>; static constexpr auto rule(block, ctll::term<'.'>) -> ctll::push>; - static constexpr auto rule(block, ctll::term<'|'>) -> ctll::push>; + static constexpr auto rule(block, ctll::term<'|'>) -> ctll::push>; static constexpr auto rule(block, ctll::term<'\x29'>) -> ctll::push; static constexpr auto rule(block, ctll::set<'*','+','\x7B','\x7D'>) -> ctll::reject; static constexpr auto rule(block_name2, ctll::set<'>','\x7D'>) -> ctll::epsilon; - static constexpr auto rule(block_name2, ctll::set<'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(block_name2, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; + + static constexpr auto rule(block_name, ctll::set<'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; static constexpr auto rule(c, ctll::term<'['>) -> ctll::push, i, range, set_start, set2b, set_make, ctll::term<']'>>; static constexpr auto rule(c, ctll::term<'\\'>) -> ctll::push>; - static constexpr auto rule(c, ctll::set<'!','0','$','\x28','\x29','*','+',',','.','/',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D','1','2','3','4','5','6','7','8','9'>) -> ctll::push>; + static constexpr auto rule(c, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>) -> ctll::push>; static constexpr auto rule(c, _others) -> ctll::push>; static constexpr auto rule(c, ctll::term<'^'>) -> ctll::push>; static constexpr auto rule(c, ctll::set<'-',']'>) -> ctll::reject; @@ -1182,28 +1198,29 @@ struct pcre { static constexpr auto rule(content2, ctll::epsilon) -> ctll::epsilon; static constexpr auto rule(content2, ctll::term<'|'>) -> ctll::push; - static constexpr auto rule(content, ctll::term<'\\'>) -> ctll::push; - static constexpr auto rule(content, ctll::term<'['>) -> ctll::push; - static constexpr auto rule(content, ctll::term<'\x28'>) -> ctll::push; - static constexpr auto rule(content, ctll::term<'^'>) -> ctll::push; - static constexpr auto rule(content, ctll::term<'$'>) -> ctll::push; - static constexpr auto rule(content, ctll::set<'!',',','/',':','<','0','-','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; - static constexpr auto rule(content, _others) -> ctll::push; - static constexpr auto rule(content, ctll::term<'.'>) -> ctll::push; - static constexpr auto rule(content, ctll::set<'\x29','*','+','?','\x7B','|','\x7D'>) -> ctll::reject; - static constexpr auto rule(content_in_capture, ctll::term<'\\'>) -> ctll::push; static constexpr auto rule(content_in_capture, ctll::term<'['>) -> ctll::push; static constexpr auto rule(content_in_capture, ctll::term<'\x28'>) -> ctll::push; static constexpr auto rule(content_in_capture, ctll::term<'^'>) -> ctll::push; static constexpr auto rule(content_in_capture, ctll::term<'$'>) -> ctll::push; - static constexpr auto rule(content_in_capture, ctll::set<'!',',','/',':','<','0','-','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(content_in_capture, ctll::set<'!',',','-','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; static constexpr auto rule(content_in_capture, _others) -> ctll::push; static constexpr auto rule(content_in_capture, ctll::term<'.'>) -> ctll::push; - static constexpr auto rule(content_in_capture, ctll::term<'|'>) -> ctll::push; + static constexpr auto rule(content_in_capture, ctll::term<'|'>) -> ctll::push; static constexpr auto rule(content_in_capture, ctll::term<'\x29'>) -> ctll::push; static constexpr auto rule(content_in_capture, ctll::set<'*','+','?','\x7B','\x7D'>) -> ctll::reject; + static constexpr auto rule(content_or_empty, ctll::term<'\\'>) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::term<'['>) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::term<'\x28'>) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::term<'^'>) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::term<'$'>) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::set<'!',',','-','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; + static constexpr auto rule(content_or_empty, _others) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::term<'.'>) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::term<'\x29'>) -> ctll::push; + static constexpr auto rule(content_or_empty, ctll::set<'*','+','?','\x7B','|','\x7D'>) -> ctll::reject; + static constexpr auto rule(d, ctll::term<'i'>) -> ctll::push; static constexpr auto rule(d, ctll::term<'c'>) -> ctll::push; static constexpr auto rule(d, ctll::term<'m'>) -> ctll::push; @@ -1269,7 +1286,7 @@ struct pcre { static constexpr auto rule(h, ctll::term<'u'>) -> ctll::push, ctll::term<'c'>, ctll::term<'t'>, class_named_punct>; static constexpr auto rule(hexdec_repeat, ctll::term<'\x7D'>) -> ctll::epsilon; - static constexpr auto rule(hexdec_repeat, ctll::set<'0','A','B','C','D','E','F','a','b','c','d','e','f','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(hexdec_repeat, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'>) -> ctll::push; static constexpr auto rule(i, ctll::term<'^'>) -> ctll::push, ctll::term<']'>>; static constexpr auto rule(i, ctll::term<'x'>) -> ctll::push, ctll::term<'i'>, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_xdigit, ctll::term<':'>, ctll::term<']'>>; @@ -1285,21 +1302,21 @@ struct pcre { static constexpr auto rule(i, ctll::term<'p'>) -> ctll::push, ctll::term<']'>>; static constexpr auto rule(j, ctll::term<'\\'>) -> ctll::push; - static constexpr auto rule(j, ctll::set<'!','$','\x28','\x29','*','+',',','.','/',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','^','0','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(j, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>) -> ctll::push; static constexpr auto rule(j, _others) -> ctll::push; static constexpr auto rule(j, ctll::set<'-','[',']'>) -> ctll::reject; static constexpr auto rule(k, ctll::term<'\x7B'>) -> ctll::push, push_hexdec, hexdec_repeat, ctll::term<'\x7D'>, finish_hexdec>; - static constexpr auto rule(k, ctll::set<'0','A','B','C','D','E','F','a','b','c','d','e','f','1','2','3','4','5','6','7','8','9'>) -> ctll::push, push_hexdec, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'>, push_hexdec, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'>, push_hexdec, finish_hexdec>; + static constexpr auto rule(k, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'>) -> ctll::push, push_hexdec, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'>, push_hexdec, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'>, push_hexdec, finish_hexdec>; static constexpr auto rule(l, ctll::term<'\x7B'>) -> ctll::push, push_hexdec, hexdec_repeat, ctll::term<'\x7D'>, finish_hexdec>; - static constexpr auto rule(l, ctll::set<'0','A','B','C','D','E','F','a','b','c','d','e','f','1','2','3','4','5','6','7','8','9'>) -> ctll::push, push_hexdec, finish_hexdec>; + static constexpr auto rule(l, ctll::set<'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'>) -> ctll::push, push_hexdec, finish_hexdec>; static constexpr auto rule(m, ctll::set<'0','1','2','3','4','5','6','7','8','9'>) -> ctll::push, make_back_reference>; static constexpr auto rule(m, ctll::term<'-'>) -> ctll::push, make_relative_back_reference>; static constexpr auto rule(m, ctll::set<'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push, make_back_reference>; - static constexpr auto rule(mod, ctll::set<'!','$','\x28','\x29',',','-','.','/','0',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','|','1','2','3','4','5','6','7','8','9'>) -> ctll::epsilon; + static constexpr auto rule(mod, ctll::set<'!','$','\x28','\x29',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','|'>) -> ctll::epsilon; static constexpr auto rule(mod, ctll::epsilon) -> ctll::epsilon; static constexpr auto rule(mod, _others) -> ctll::epsilon; static constexpr auto rule(mod, ctll::term<'?'>) -> ctll::push; @@ -1312,7 +1329,7 @@ struct pcre { static constexpr auto rule(mode_switch2, ctll::term<'s'>) -> ctll::push; static constexpr auto rule(mode_switch2, ctll::term<'\x29'>) -> ctll::push; - static constexpr auto rule(n, ctll::set<'0','1','2','3','4','5','6','7','8','9'>) -> ctll::push, mod>; + static constexpr auto rule(n, ctll::set<'0','1','2','3','4','5','6','7','8','9'>) -> ctll::push, mod>; static constexpr auto rule(n, ctll::term<'\x7D'>) -> ctll::push; static constexpr auto rule(number2, ctll::set<',','\x7D'>) -> ctll::epsilon; @@ -1320,30 +1337,41 @@ struct pcre { static constexpr auto rule(number, ctll::set<'0','1','2','3','4','5','6','7','8','9'>) -> ctll::push; - static constexpr auto rule(o, ctll::set<'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push'>, content_in_capture, make_capture_with_name, ctll::term<'\x29'>>; + static constexpr auto rule(o, ctll::set<'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push'>, content_in_capture, make_capture_with_name, ctll::term<'\x29'>>; static constexpr auto rule(o, ctll::term<'!'>) -> ctll::push>; static constexpr auto rule(o, ctll::term<'='>) -> ctll::push>; + static constexpr auto rule(opt_content, ctll::term<'\\'>) -> ctll::push; + static constexpr auto rule(opt_content, ctll::term<'['>) -> ctll::push; + static constexpr auto rule(opt_content, ctll::term<'\x28'>) -> ctll::push; + static constexpr auto rule(opt_content, ctll::term<'^'>) -> ctll::push; + static constexpr auto rule(opt_content, ctll::term<'$'>) -> ctll::push; + static constexpr auto rule(opt_content, ctll::set<'!',',','-','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; + static constexpr auto rule(opt_content, _others) -> ctll::push; + static constexpr auto rule(opt_content, ctll::term<'.'>) -> ctll::push; + static constexpr auto rule(opt_content, ctll::epsilon) -> ctll::push; + static constexpr auto rule(opt_content, ctll::set<'\x29','*','+','?','\x7B','|','\x7D'>) -> ctll::reject; + static constexpr auto rule(p, ctll::term<'p'>) -> ctll::push, ctll::term<'a'>, class_named_alpha>; static constexpr auto rule(p, ctll::term<'n'>) -> ctll::push, ctll::term<'m'>, class_named_alnum>; static constexpr auto rule(property_name2, ctll::term<'\x7D'>) -> ctll::epsilon; static constexpr auto rule(property_name2, ctll::term<'='>) -> ctll::push; - static constexpr auto rule(property_name2, ctll::set<'0','.','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(property_name2, ctll::set<'.','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; - static constexpr auto rule(property_name, ctll::set<'0','.','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(property_name, ctll::set<'.','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; static constexpr auto rule(property_value2, ctll::term<'\x7D'>) -> ctll::epsilon; - static constexpr auto rule(property_value2, ctll::set<'0','.','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(property_value2, ctll::set<'.','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; - static constexpr auto rule(property_value, ctll::set<'0','.','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(property_value, ctll::set<'.','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; - static constexpr auto rule(range, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D','1','2','3','4','5','6','7','8','9'>) -> ctll::epsilon; + static constexpr auto rule(range, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>) -> ctll::epsilon; static constexpr auto rule(range, ctll::epsilon) -> ctll::epsilon; static constexpr auto rule(range, _others) -> ctll::epsilon; static constexpr auto rule(range, ctll::term<'-'>) -> ctll::push; - static constexpr auto rule(repeat, ctll::set<'!','$','\x28','\x29',',','-','.','/','0',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','|','1','2','3','4','5','6','7','8','9'>) -> ctll::epsilon; + static constexpr auto rule(repeat, ctll::set<'!','$','\x28','\x29',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\','\"',']','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','|'>) -> ctll::epsilon; static constexpr auto rule(repeat, ctll::epsilon) -> ctll::epsilon; static constexpr auto rule(repeat, _others) -> ctll::epsilon; static constexpr auto rule(repeat, ctll::term<'?'>) -> ctll::push; @@ -1355,14 +1383,14 @@ struct pcre { static constexpr auto rule(set2a, ctll::term<']'>) -> ctll::epsilon; static constexpr auto rule(set2a, ctll::term<'['>) -> ctll::push, i, range, set_start, set2b>; static constexpr auto rule(set2a, ctll::term<'\\'>) -> ctll::push; - static constexpr auto rule(set2a, ctll::set<'!','$','\x28','\x29','*','+',',','.','/',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','^','0','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(set2a, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>) -> ctll::push; static constexpr auto rule(set2a, _others) -> ctll::push; static constexpr auto rule(set2a, ctll::term<'-'>) -> ctll::reject; static constexpr auto rule(set2b, ctll::term<']'>) -> ctll::epsilon; static constexpr auto rule(set2b, ctll::term<'['>) -> ctll::push, i, range, set_combine, set2b>; static constexpr auto rule(set2b, ctll::term<'\\'>) -> ctll::push; - static constexpr auto rule(set2b, ctll::set<'!','$','\x28','\x29','*','+',',','.','/',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','^','0','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(set2b, ctll::set<'!','$','\x28','\x29','*','+',',','.','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"','^','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\x7B','|','\x7D'>) -> ctll::push; static constexpr auto rule(set2b, _others) -> ctll::push; static constexpr auto rule(set2b, ctll::term<'-'>) -> ctll::reject; @@ -1373,7 +1401,7 @@ struct pcre { static constexpr auto rule(string2, ctll::term<'\x28'>) -> ctll::push; static constexpr auto rule(string2, ctll::term<'^'>) -> ctll::push; static constexpr auto rule(string2, ctll::term<'$'>) -> ctll::push; - static constexpr auto rule(string2, ctll::set<'!',',','/',':','<','0','-','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9'>) -> ctll::push; + static constexpr auto rule(string2, ctll::set<'!',',','-','/','0','1','2','3','4','5','6','7','8','9',':','<','=','>','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','\"',']','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'>) -> ctll::push; static constexpr auto rule(string2, _others) -> ctll::push; static constexpr auto rule(string2, ctll::term<'.'>) -> ctll::push; static constexpr auto rule(string2, ctll::set<'*','+','?','\x7B','\x7D'>) -> ctll::reject; @@ -1398,6 +1426,12 @@ struct pcre { #define CTRE_CNTTP_COMPILER_CHECK CTLL_CNTTP_COMPILER_CHECK +#ifdef CTRE_IN_A_MODULE +#define CTRE_EXPORT export +#else +#define CTRE_EXPORT +#endif + #if __GNUC__ > 9 #if __has_cpp_attribute(likely) #define CTRE_LIKELY [[likely]] @@ -1528,7 +1562,10 @@ constexpr CTRE_FORCE_INLINE bool is_case_insensitive(flags f) { } // namespace ctre #endif + +#ifndef CTRE_IN_A_MODULE #include +#endif namespace ctre { @@ -1659,7 +1696,9 @@ using ascii_chars = char_range<'\x00','\x7F'>; #endif +#ifndef CTRE_IN_A_MODULE #include +#endif namespace ctre { @@ -1741,7 +1780,9 @@ template struct mode_switch { }; #ifndef H_COR3NTIN_UNICODE_SYNOPSYS #define H_COR3NTIN_UNICODE_SYNOPSYS +#ifndef UNICODE_DB_IN_A_MODULE #include +#endif namespace uni { @@ -2082,7 +2123,9 @@ static auto rotate(assert_line_end) -> assert_line_end; #ifndef CTRE__ID__HPP #define CTRE__ID__HPP +#ifndef CTRE_IN_A_MODULE #include +#endif namespace ctre { @@ -2102,8 +2145,10 @@ template struct id { #endif +#ifndef CTRE_IN_A_MODULE #include #include +#endif namespace ctre { @@ -3043,8 +3088,10 @@ constexpr bool starts_with_anchor(const flags & f, ctll::list= 201811 +#ifndef CTRE_IN_A_MODULE #include #include +#endif #if __cpp_lib_char8_t >= 201811L #define CTRE_ENABLE_UTF8_RANGE @@ -3288,11 +3335,13 @@ struct utf8_range { #endif +#ifndef CTRE_IN_A_MODULE #include #include #include #include #include +#include #ifdef _MSC_VER #include #endif @@ -3300,6 +3349,10 @@ struct utf8_range { #if __has_include() #include #endif +#if __cpp_concepts >= 202002L +#include +#endif +#endif namespace ctre { @@ -3403,16 +3456,22 @@ template struct captured_content { } #if __has_include() - template constexpr CTRE_FORCE_INLINE auto to_number(int base = 10) const noexcept -> R { + template constexpr CTRE_FORCE_INLINE auto to_number(Ts && ... args) const noexcept -> R { R result{0}; const auto view = to_view(); - std::from_chars(view.data(), view.data() + view.size(), result, base); + std::from_chars(view.data(), view.data() + view.size(), result, std::forward(args)...); return result; } + + template constexpr CTRE_FORCE_INLINE auto to_optional_number(Ts && ... args) const noexcept -> std::optional { + if (!static_cast(*this)) { + return std::nullopt; + } + + return to_number(std::forward(args)...); + } #endif - template struct identify; - template constexpr CTRE_FORCE_INLINE auto to_view() const noexcept { // random access, because C++ (waving hands around) constexpr bool must_be_nonreverse_contiguous_iterator = is_random_accessible>::iterator_category> && !is_reverse_iterator; @@ -3422,6 +3481,17 @@ template struct captured_content { return std::basic_string_view(data_unsafe(), static_cast(unit_size())); } + constexpr CTRE_FORCE_INLINE auto view() const noexcept { + return to_view(); + } + + template constexpr CTRE_FORCE_INLINE auto to_optional_view() const noexcept -> std::optional> { + if (!static_cast(*this)) { + return std::nullopt; + } + return to_view(); + } + constexpr CTRE_FORCE_INLINE std::basic_string to_string() const noexcept { #if __cpp_char8_t >= 201811 if constexpr (std::is_same_v) { @@ -3434,11 +3504,14 @@ template struct captured_content { #endif } - constexpr CTRE_FORCE_INLINE auto view() const noexcept { - return to_view(); + constexpr CTRE_FORCE_INLINE auto str() const noexcept { + return to_string(); } - constexpr CTRE_FORCE_INLINE auto str() const noexcept { + template constexpr CTRE_FORCE_INLINE auto to_optional_string() const noexcept -> std::optional> { + if (!static_cast(*this)) { + return std::nullopt; + } return to_string(); } @@ -3450,6 +3523,14 @@ template struct captured_content { return to_string(); } + constexpr CTRE_FORCE_INLINE operator std::optional>() const noexcept { + return to_optional_view(); + } + + constexpr CTRE_FORCE_INLINE explicit operator std::optional>() const noexcept { + return to_optional_string(); + } + constexpr CTRE_FORCE_INLINE static size_t get_id() noexcept { return Id; } @@ -3472,9 +3553,26 @@ template struct captured_content { }; }; +#if __cpp_concepts >= 202002L +template concept capture_group = requires(const T & cap) { + { T::get_id() } -> std::same_as; + { cap.view() }; + { cap.str() }; + { cap.to_string() }; + { cap.to_view() }; + { cap.unit_size() } -> std::same_as; + { cap.size() } -> std::same_as; + { static_cast(cap) }; + { cap.data() }; + { cap.data_unsafe() }; + { cap.begin() }; + { cap.end() }; +}; +#endif + struct capture_not_exists_tag { }; -static constexpr inline auto capture_not_exists = capture_not_exists_tag{}; +constexpr auto capture_not_exists = capture_not_exists_tag{}; template struct captures; @@ -3596,18 +3694,39 @@ public: // special constructor for deducting constexpr CTRE_FORCE_INLINE regex_results(Iterator, ctll::list) noexcept { } - template ()>> CTRE_FORCE_INLINE constexpr auto get() const noexcept { - return _captures.template select(); + template CTRE_FORCE_INLINE constexpr auto get() const noexcept { + constexpr bool capture_of_provided_id_must_exists = decltype(_captures)::template exists(); + static_assert(capture_of_provided_id_must_exists); + + if constexpr (capture_of_provided_id_must_exists) { + return _captures.template select(); + } else { + return false; + } } - template ()>> CTRE_FORCE_INLINE constexpr auto get() const noexcept { - return _captures.template select(); + template CTRE_FORCE_INLINE constexpr auto get() const noexcept { + constexpr bool capture_of_provided_name_must_exists = decltype(_captures)::template exists(); + static_assert(capture_of_provided_name_must_exists); + + if constexpr (capture_of_provided_name_must_exists) { + return _captures.template select(); + } else { + return false; + } } #if CTRE_CNTTP_COMPILER_CHECK - template ()>> CTRE_FORCE_INLINE constexpr auto get() const noexcept { + template CTRE_FORCE_INLINE constexpr auto get() const noexcept { #else - template ()>> CTRE_FORCE_INLINE constexpr auto get() const noexcept { + template CTRE_FORCE_INLINE constexpr auto get() const noexcept { #endif - return _captures.template select(); + constexpr bool capture_of_provided_name_must_exists = decltype(_captures)::template exists(); + static_assert(capture_of_provided_name_must_exists); + + if constexpr (capture_of_provided_name_must_exists) { + return _captures.template select(); + } else { + return false; + } } static constexpr size_t count() noexcept { return sizeof...(Captures) + 1; @@ -3624,6 +3743,7 @@ public: return bool(_captures.template select<0>()); } + // implicit conversions constexpr CTRE_FORCE_INLINE operator std::basic_string_view() const noexcept { return to_view(); } @@ -3632,28 +3752,55 @@ public: return to_string(); } + constexpr CTRE_FORCE_INLINE operator std::optional>() const noexcept { + return to_optional_view(); + } + + constexpr CTRE_FORCE_INLINE explicit operator std::optional>() const noexcept { + return to_optional_string(); + } + + // conversion to numbers #if __has_include() - template constexpr CTRE_FORCE_INLINE auto to_number(int base = 10) const noexcept -> R { - return _captures.template select<0>().template to_number(base); + template constexpr CTRE_FORCE_INLINE auto to_number(Ts && ... args) const noexcept -> R { + return _captures.template select<0>().template to_number(std::forward(args)...); + } + + template constexpr CTRE_FORCE_INLINE auto to_optional_number(Ts && ... args) const noexcept -> std::optional { + return _captures.template select<0>().template to_optional_number(std::forward(args)...); } #endif + // conversion to basic_string_view constexpr CTRE_FORCE_INLINE auto to_view() const noexcept { return _captures.template select<0>().to_view(); } + constexpr CTRE_FORCE_INLINE auto view() const noexcept { + return _captures.template select<0>().view(); // this should be deprecated (??) + } + + constexpr CTRE_FORCE_INLINE auto to_optional_view() const noexcept { + return _captures.template select<0>().to_optional_view(); + } + + // conversion to basic_string constexpr CTRE_FORCE_INLINE auto to_string() const noexcept { return _captures.template select<0>().to_string(); } - constexpr CTRE_FORCE_INLINE auto view() const noexcept { - return _captures.template select<0>().view(); + constexpr CTRE_FORCE_INLINE auto str() const noexcept { + return _captures.template select<0>().to_string(); // this should be deprecated (??) } - constexpr CTRE_FORCE_INLINE auto str() const noexcept { - return _captures.template select<0>().to_string(); + constexpr CTRE_FORCE_INLINE auto to_optional_string() const noexcept { + return _captures.template select<0>().to_optional_string(); } + + + + constexpr CTRE_FORCE_INLINE size_t size() const noexcept { return _captures.template select<0>().size(); } @@ -3700,7 +3847,13 @@ public: return bool(rhs) ? lhs != rhs.view() : true; } friend CTRE_FORCE_INLINE std::ostream & operator<<(std::ostream & str, const regex_results & rhs) { +#ifdef CTRE_IN_A_MODULE + auto view = rhs.view(); + str.write(view.data(), view.size()); + return str; +#else return str << rhs.view(); +#endif } }; @@ -3710,6 +3863,16 @@ template constexpr auto get template regex_results(Iterator, ctll::list) -> regex_results; +template struct is_regex_results_t: std::false_type { }; + +template struct is_regex_results_t>: std::true_type { }; + +template constexpr bool is_regex_results_v = is_regex_results_t(); + +#if __cpp_concepts >= 201907L +template concept capture_groups = is_regex_results_v; +#endif + template using return_type = decltype(regex_results(std::declval(), find_captures(Pattern{}))); } @@ -3745,100 +3908,100 @@ namespace std { namespace ctre { -template constexpr auto find_captures(Pattern) noexcept { +CTRE_EXPORT template constexpr auto find_captures(Pattern) noexcept { return find_captures(ctll::list(), ctll::list<>()); } -template constexpr auto find_captures(ctll::list<>, ctll::list output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list<>, ctll::list output) noexcept { return output; } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Output output) noexcept { return find_captures(ctll::list(), output); } // , typename = std::enable_if_t<(MatchesCharacter::template value) -template constexpr auto find_captures(ctll::list, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, Output output) noexcept { return find_captures(ctll::list(), output); } -template constexpr auto find_captures(ctll::list, Tail...>, ctll::list) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, ctll::list) noexcept { return find_captures(ctll::list(), ctll::list>()); } -template constexpr auto find_captures(ctll::list, Tail...>, ctll::list) noexcept { +CTRE_EXPORT template constexpr auto find_captures(ctll::list, Tail...>, ctll::list) noexcept { return find_captures(ctll::list(), ctll::list>()); } @@ -4171,7 +4334,7 @@ template constexpr int64_t negative_helper(ctre::character } else { return A; } -} +} template constexpr int64_t negative_helper(ctre::char_range, CB & cb, int64_t start) { if (A != (std::numeric_limits::min)()) { @@ -4184,7 +4347,7 @@ template constexpr int64_t negative_helper(ctre::c } else { return B; } -} +} template constexpr int64_t negative_helper(ctre::enumeration, CB & cb, int64_t start) { int64_t nstart = negative_helper(ctre::character{}, cb, start); @@ -4256,7 +4419,7 @@ template class point_set { auto last = end(); auto it = first; auto count = std::distance(first, last); - while (count != 0) { + while (count != 0) { it = first; auto step = count / 2; std::advance(it, step); @@ -4302,7 +4465,7 @@ public: //insert_point(high, low); } constexpr bool check(int64_t low, int64_t high) { - for (auto r: *this) { + for (const auto & r: *this) { if (r.low <= low && low <= r.high) { return true; } else if (r.low <= high && high <= r.high) { @@ -4326,6 +4489,15 @@ public: constexpr bool check(can_be_anything) { return used > 0; } + template + constexpr bool check(ctre::binary_property) { + return check(can_be_anything{}); + } + + template + constexpr bool check(ctre::property) { + return check(can_be_anything{}); + } template constexpr bool check(ctre::negative_set nset) { bool collision = false; negative_helper(nset, [&](int64_t low, int64_t high){ @@ -4382,7 +4554,9 @@ template constexpr bool collides(ctll::list #endif +#ifndef CTRE_IN_A_MODULE #include +#endif // remove me when MSVC fix the constexpr bug #ifdef _MSC_VER @@ -4943,7 +5117,9 @@ constexpr CTRE_FORCE_INLINE R evaluate(const BeginIterator begin, Iterator curre #ifndef CTRE_V2__CTRE__ITERATOR__HPP #define CTRE_V2__CTRE__ITERATOR__HPP +#ifndef CTRE_IN_A_MODULE #include +#endif namespace ctre { @@ -5178,8 +5354,8 @@ template struct multi_subject_range { struct iterator { using value_type = decltype(RE::exec(std::declval::value_type>())); using iterator_category = std::forward_iterator_tag; - using pointer = void; using reference = const value_type &; + using pointer = const value_type *; using difference_type = int; first_type first{}; @@ -5197,10 +5373,14 @@ template struct multi_subject_range { return {}; } - constexpr CTRE_FORCE_INLINE const value_type & operator*() const noexcept { + constexpr CTRE_FORCE_INLINE reference operator*() const noexcept { return current_result; } + constexpr CTRE_FORCE_INLINE pointer operator->() const noexcept { + return ¤t_result; + } + constexpr CTRE_FORCE_INLINE iterator & operator++() noexcept { ++first; current_result = find_first(); @@ -5247,7 +5427,7 @@ template struct multi_subject_range { Range range{}; constexpr CTRE_FORCE_INLINE multi_subject_range() noexcept = default; - constexpr CTRE_FORCE_INLINE multi_subject_range(Range r) noexcept: range{r} { } + constexpr CTRE_FORCE_INLINE multi_subject_range(Range r) noexcept: range{r} { } constexpr CTRE_FORCE_INLINE auto begin() const noexcept { return iterator{range.begin(), range.end()}; @@ -5275,12 +5455,14 @@ namespace std::ranges { #endif +#ifndef CTRE_IN_A_MODULE #include +#endif namespace ctre { -template struct regular_expression; - +CTRE_EXPORT template struct regular_expression; + struct zero_terminated_string_end_iterator { // this is here only because I want to support std::make_reverse_iterator using self_type = zero_terminated_string_end_iterator; @@ -5289,7 +5471,7 @@ struct zero_terminated_string_end_iterator { using pointer = const char *; using iterator_category = std::bidirectional_iterator_tag; using difference_type = int; - + // it's just sentinel it won't be ever called auto operator++() noexcept -> self_type &; auto operator++(int) noexcept -> self_type; @@ -5297,47 +5479,48 @@ struct zero_terminated_string_end_iterator { auto operator--(int) noexcept -> self_type; friend auto operator==(self_type, self_type) noexcept -> bool; auto operator*() noexcept -> reference; - + constexpr CTRE_FORCE_INLINE friend bool operator==(const char * ptr, zero_terminated_string_end_iterator) noexcept { return *ptr == '\0'; - } + } constexpr CTRE_FORCE_INLINE friend bool operator==(const wchar_t * ptr, zero_terminated_string_end_iterator) noexcept { return *ptr == 0; - } + } constexpr CTRE_FORCE_INLINE friend bool operator!=(const char * ptr, zero_terminated_string_end_iterator) noexcept { return *ptr != '\0'; - } + } constexpr CTRE_FORCE_INLINE friend bool operator!=(const wchar_t * ptr, zero_terminated_string_end_iterator) noexcept { return *ptr != 0; - } + } constexpr CTRE_FORCE_INLINE friend bool operator==(zero_terminated_string_end_iterator, const char * ptr) noexcept { return *ptr == '\0'; - } + } constexpr CTRE_FORCE_INLINE friend bool operator==(zero_terminated_string_end_iterator, const wchar_t * ptr) noexcept { return *ptr == 0; - } + } constexpr CTRE_FORCE_INLINE friend bool operator!=(zero_terminated_string_end_iterator, const char * ptr) noexcept { return *ptr != '\0'; - } + } constexpr CTRE_FORCE_INLINE friend bool operator!=(zero_terminated_string_end_iterator, const wchar_t * ptr) noexcept { return *ptr != 0; - } + } }; template class RangeLikeType { template static auto test(Y *) -> decltype(std::declval().begin(), std::declval().end(), std::true_type()); template static auto test(...) -> std::false_type; + public: - static inline constexpr bool value = decltype(test>>( nullptr ))::value; + static constexpr bool value = decltype(test>>(nullptr))::value; }; struct match_method { template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin orig_begin, IteratorBegin begin, IteratorEnd end, RE) noexcept { using result_iterator = std::conditional_t, IteratorBegin, ResultIterator>; - + return evaluate(orig_begin, begin, end, Modifier{}, return_type{}, ctll::list()); } - + template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end, RE) noexcept { return exec(begin, begin, end, RE{}); } @@ -5346,26 +5529,26 @@ struct match_method { struct search_method { template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin orig_begin, IteratorBegin begin, IteratorEnd end, RE) noexcept { using result_iterator = std::conditional_t, IteratorBegin, ResultIterator>; - + constexpr bool fixed = starts_with_anchor(Modifier{}, ctll::list{}); - + auto it = begin; - + for (; end != it && !fixed; ++it) { if (auto out = evaluate(orig_begin, it, end, Modifier{}, return_type{}, ctll::list())) { return out; } } - + // in case the RE is empty or fixed auto out = evaluate(orig_begin, it, end, Modifier{}, return_type{}, ctll::list()); - + // ALERT: ugly hack // propagate end even if it didn't match (this is needed for split function) if (!out) out.set_end_mark(it); return out; } - + template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end, RE) noexcept { return exec(begin, begin, end, RE{}); } @@ -5376,7 +5559,7 @@ struct starts_with_method { using result_iterator = std::conditional_t, IteratorBegin, ResultIterator>; return evaluate(orig_begin, begin, end, Modifier{}, return_type{}, ctll::list()); } - + template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end, RE) noexcept { return exec(begin, begin, end, RE{}); } @@ -5387,7 +5570,7 @@ struct range_method { template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end, RE) noexcept { using result_iterator = std::conditional_t, IteratorBegin, ResultIterator>; using wrapped_regex = regular_expression; - + return regex_range(begin, end); } }; @@ -5396,7 +5579,7 @@ struct tokenize_method { template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end, RE) noexcept { using result_iterator = std::conditional_t, IteratorBegin, ResultIterator>; using wrapped_regex = regular_expression; - + return regex_range(begin, end); } }; @@ -5405,7 +5588,7 @@ struct split_method { template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end, RE) noexcept { using result_iterator = std::conditional_t, IteratorBegin, ResultIterator>; using wrapped_regex = regular_expression; - + return regex_split_range(begin, end); } }; @@ -5414,7 +5597,7 @@ struct iterator_method { template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end, RE) noexcept { using result_iterator = std::conditional_t, IteratorBegin, ResultIterator>; using wrapped_regex = regular_expression; - + return regex_iterator(begin, end); } constexpr CTRE_FORCE_INLINE static auto exec() noexcept { @@ -5422,10 +5605,10 @@ struct iterator_method { } }; -template struct regular_expression { +CTRE_EXPORT template struct regular_expression { constexpr CTRE_FORCE_INLINE regular_expression() noexcept { } constexpr CTRE_FORCE_INLINE regular_expression(RE) noexcept { } - + template constexpr CTRE_FORCE_INLINE static auto exec_with_result_iterator(IteratorBegin orig_begin, IteratorBegin begin, IteratorEnd end) noexcept { return Method::template exec(orig_begin, begin, end, RE{}); } @@ -5436,7 +5619,7 @@ template struct regular_expres return multi_subject_range{std::forward(range)}; } constexpr CTRE_FORCE_INLINE static auto exec() noexcept { - return Method::template exec(); + return Method::exec(); } template constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin begin, IteratorEnd end) noexcept { return Method::template exec(begin, end, RE{}); @@ -5467,58 +5650,58 @@ template struct regular_expres template ::value>::type> static constexpr CTRE_FORCE_INLINE auto exec(Range && range) noexcept { return exec(std::begin(range), std::end(range)); } - + // another api - template CTRE_FORCE_INLINE constexpr auto operator()(Args && ... args) const noexcept { + template CTRE_FORCE_INLINE constexpr auto operator()(Args &&... args) const noexcept { return exec(std::forward(args)...); } // api for pattern matching - template CTRE_FORCE_INLINE constexpr auto try_extract(Args && ... args) const noexcept { + template CTRE_FORCE_INLINE constexpr auto try_extract(Args &&... args) const noexcept { return exec(std::forward(args)...); } - + // for compatibility with _ctre literal - template static constexpr CTRE_FORCE_INLINE auto match(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto match(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto search(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto search(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto starts_with(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto starts_with(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto range(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto range(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto split(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto split(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto tokenize(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto tokenize(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto iterator(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto iterator(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - - template static constexpr CTRE_FORCE_INLINE auto multiline_match(Args && ... args) noexcept { + + template static constexpr CTRE_FORCE_INLINE auto multiline_match(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto multiline_search(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto multiline_search(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto multiline_starts_with(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto multiline_starts_with(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto multiline_range(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto multiline_range(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto multiline_split(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto multiline_split(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto multiline_tokenize(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto multiline_tokenize(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } - template static constexpr CTRE_FORCE_INLINE auto multiline_iterator(Args && ... args) noexcept { + template static constexpr CTRE_FORCE_INLINE auto multiline_iterator(Args &&... args) noexcept { return regular_expression::exec(std::forward(args)...); } }; @@ -5562,51 +5745,55 @@ template <> struct problem_at_position<~static_cast(0)> { template struct regex_builder { static constexpr auto _input = input; using result = typename ctll::parser::template output>; - + static constexpr auto n = result::is_correct ? ~static_cast(0) : result::position; - + static_assert(result::is_correct && problem_at_position{}, "Regular Expression contains syntax error."); - + using type = ctll::conditional>; }; // case-sensitive -template static constexpr inline auto match = regular_expression::type, match_method, ctll::list>(); +CTRE_EXPORT template constexpr auto match = regular_expression::type, match_method, ctll::list>(); -template static constexpr inline auto search = regular_expression::type, search_method, ctll::list>(); +CTRE_EXPORT template constexpr auto search = regular_expression::type, search_method, ctll::list>(); -template static constexpr inline auto starts_with = regular_expression::type, starts_with_method, ctll::list>(); +CTRE_EXPORT template constexpr auto starts_with = regular_expression::type, starts_with_method, ctll::list>(); -template static constexpr inline auto range = regular_expression::type, range_method, ctll::list>(); +CTRE_EXPORT template constexpr auto search_all = regular_expression::type, range_method, ctll::list>(); -template static constexpr inline auto split = regular_expression::type, split_method, ctll::list>(); +CTRE_EXPORT template [[deprecated("use search_all")]] constexpr auto range = regular_expression::type, range_method, ctll::list>(); -template static constexpr inline auto tokenize = regular_expression::type, tokenize_method, ctll::list>(); +CTRE_EXPORT template constexpr auto split = regular_expression::type, split_method, ctll::list>(); -template static constexpr inline auto iterator = regular_expression::type, iterator_method, ctll::list>(); +CTRE_EXPORT template constexpr auto tokenize = regular_expression::type, tokenize_method, ctll::list>(); -static constexpr inline auto sentinel = regex_end_iterator(); +CTRE_EXPORT template constexpr auto iterator = regular_expression::type, iterator_method, ctll::list>(); + +CTRE_EXPORT constexpr auto sentinel = regex_end_iterator(); // multiline -template static constexpr inline auto multiline_match = regular_expression::type, match_method, ctll::list>(); +CTRE_EXPORT template constexpr auto multiline_match = regular_expression::type, match_method, ctll::list>(); -template static constexpr inline auto multiline_search = regular_expression::type, search_method, ctll::list>(); +CTRE_EXPORT template constexpr auto multiline_search = regular_expression::type, search_method, ctll::list>(); -template static constexpr inline auto multiline_starts_with = regular_expression::type, starts_with_method, ctll::list>(); +CTRE_EXPORT template constexpr auto multiline_starts_with = regular_expression::type, starts_with_method, ctll::list>(); -template static constexpr inline auto multiline_range = regular_expression::type, range_method, ctll::list>(); +CTRE_EXPORT template constexpr auto multiline_search_all = regular_expression::type, range_method, ctll::list>(); -template static constexpr inline auto multiline_split = regular_expression::type, split_method, ctll::list>(); +CTRE_EXPORT template [[deprecated("use multiline_search_all")]] constexpr auto multiline_range = regular_expression::type, range_method, ctll::list>(); -template static constexpr inline auto multiline_tokenize = regular_expression::type, tokenize_method, ctll::list>(); +CTRE_EXPORT template constexpr auto multiline_split = regular_expression::type, split_method, ctll::list>(); -template static constexpr inline auto multiline_iterator = regular_expression::type, iterator_method, ctll::list>(); +CTRE_EXPORT template constexpr auto multiline_tokenize = regular_expression::type, tokenize_method, ctll::list>(); -static constexpr inline auto multiline_sentinel = regex_end_iterator(); +CTRE_EXPORT template constexpr auto multiline_iterator = regular_expression::type, iterator_method, ctll::list>(); -} +CTRE_EXPORT constexpr auto multiline_sentinel = regex_end_iterator(); + +} // namespace ctre #endif