1515#pragma once
1616#include " pcre2cpp_types.hpp"
1717#include " pcre2_data.hpp"
18+ #include " regex_compile_options.hpp"
19+ #include " regex_match_options.hpp"
1820
1921namespace pcre2cpp {
2022 template <size_t utf>
@@ -36,14 +38,14 @@ namespace pcre2cpp {
3638 _named_sub_values_table_ptr _named_sub_values = nullptr ;
3739
3840 public:
39- constexpr basic_regex (const _string_char_type* pattern, size_t pattern_size,
40- regex_compile_options opts = regex_compile_options::NONE ) {
41+ constexpr explicit basic_regex (const _string_char_type* pattern, size_t pattern_size,
42+ regex_compile_options opts = static_cast < regex_compile_options>(regex_compile_options_bits ::NONE ) ) {
4143
4244 // Compile Code
4345 int error_code = 0 ;
4446 size_t error_offset = 0 ;
45- _code_type* code = _pcre2_data<utf>::compile (( _string_ptr_type) pattern,
46- pattern_size, ( uint32_t ) opts, &error_code, &error_offset, nullptr );
47+ _code_type* code = _pcre2_data<utf>::compile (reinterpret_cast < _string_ptr_type>( pattern) ,
48+ pattern_size, opts, &error_code, &error_offset, nullptr );
4749
4850 if (code == nullptr ) {
4951 throw basic_regex_exception<utf>(error_code, error_offset);
@@ -69,61 +71,49 @@ namespace pcre2cpp {
6971 while (*entry_end != ' \0 ' && entry_end - entry < name_entry_size - 3 ) {
7072 entry_end += 1 ;
7173 }
72- (*_named_sub_values)[_string_type (entry, entry_end)] = (( size_t ) index) - 1 ;
74+ (*_named_sub_values)[_string_type (entry, entry_end)] = static_cast < size_t >( index) - 1 ;
7375 }
7476
7577 // Create Match Data
7678 _match_data_type* match_data = _pcre2_data<utf>::match_data_from_pattern (_code.get (), nullptr );
7779 _match_data = std::shared_ptr<_match_data_type>(match_data, _pcre2_data<utf>::match_data_free);
7880 }
79- constexpr basic_regex (const _string_type& pattern,
80- regex_compile_options opts = regex_compile_options::NONE )
81+ constexpr explicit basic_regex (const _string_type& pattern,
82+ regex_compile_options opts = static_cast < regex_compile_options>(regex_compile_options_bits ::NONE ))
8183 : basic_regex(pattern.c_str(), pattern.length(), opts) {}
8284 template <size_t N>
83- constexpr basic_regex (const _string_char_type (&pattern)[N],
84- regex_compile_options opts = regex_compile_options::NONE)
85+ constexpr explicit basic_regex (const _string_char_type (&pattern)[N],
86+ regex_compile_options opts = static_cast< regex_compile_options>(regex_compile_options_bits ::NONE ))
8587 : basic_regex(pattern, N - 1 , opts) {}
88+
8689 constexpr basic_regex (const basic_regex<utf>& r) noexcept = default;
90+
8791 virtual ~basic_regex () = default ;
8892
8993 constexpr basic_regex<utf>& operator =(const basic_regex<utf>& r) noexcept = default;
9094
9195#pragma region MATCH
92- constexpr bool match (const _string_char_type* text, size_t text_size,
93- regex_match_options opts, size_t offset = 0 ) const {
96+ constexpr bool match (const _string_char_type* text, size_t text_size, size_t offset = 0 ,
97+ regex_match_options opts = static_cast <regex_match_options>(regex_match_options_bits:: NONE ) ) const {
9498 int match_code =
95- _pcre2_data<utf>::match (_code.get (), ( _string_ptr_type) text,
96- text_size, offset, ( uint32_t ) opts, _match_data.get (), nullptr );
99+ _pcre2_data<utf>::match (_code.get (), reinterpret_cast < _string_ptr_type>( text) ,
100+ text_size, offset, opts, _match_data.get (), nullptr );
97101
98102 return match_code > 0 && match_code != PCRE2_ERROR_NOMATCH ;
99103 }
100- constexpr bool match (const _string_type& text, regex_match_options opts, size_t offset = 0 ) const {
101- return match (text.c_str (), text.length (), opts, offset);
102- }
103- template <size_t N>
104- constexpr bool match (const _string_char_type (&text)[N], regex_match_options opts, size_t offset = 0) const {
105- return match (text, N - 1 , opts, offset);
106- }
107-
108- constexpr bool match (const _string_char_type* text, size_t text_size, size_t offset = 0 ) const {
109- return match (text, text_size, regex_match_options::NONE , offset);
110- }
111- constexpr bool match (const _string_type& text, size_t offset = 0 ) const {
112- return match (text.c_str (), text.length (), offset);
104+ constexpr bool match (const _string_type& text, size_t offset = 0 ,
105+ regex_match_options opts = static_cast <regex_match_options>(regex_match_options_bits::NONE )) const {
106+ return match (text.c_str (), text.length (), offset, opts);
113107 }
114- template <size_t N>
115- constexpr bool match (const _string_char_type (&text)[N], size_t offset = 0) const {
116- return match (text, N - 1 , offset);
117- }
118-
119108#pragma endregion MATCH
120109
121110#pragma region MATCH_WITH_RESULT
122111 constexpr bool match (const _string_char_type* text, size_t text_size,
123- _match_result_type& result, regex_match_options opts, size_t offset = 0 ) const {
112+ _match_result_type& result, size_t offset = 0 ,
113+ regex_match_options opts = static_cast <regex_match_options>(regex_match_options_bits::NONE )) const {
124114 int match_code =
125- _pcre2_data<utf>::match (_code.get (), ( _string_ptr_type) text,
126- text_size, offset, ( uint32_t ) opts, _match_data.get (), nullptr );
115+ _pcre2_data<utf>::match (_code.get (), reinterpret_cast < _string_ptr_type>( text) ,
116+ text_size, offset, static_cast < uint32_t >( opts) , _match_data.get (), nullptr );
127117
128118 if (match_code > 0 && match_code != PCRE2_ERROR_NOMATCH ) {
129119 size_t * ovector = _pcre2_data<utf>::get_ovector_ptr (_match_data.get ());
@@ -147,25 +137,8 @@ namespace pcre2cpp {
147137 return false ;
148138 }
149139 constexpr bool match (const _string_type& text, _match_result_type& result,
150- regex_match_options opts, size_t offset = 0 ) const {
151- return match (text.c_str (), text.length (), result, opts, offset);
152- }
153- template <size_t N>
154- constexpr bool match (const _string_char_type (&text)[N], _match_result_type& result,
155- regex_match_options opts, size_t offset = 0) const {
156- return match (text, N - 1 , result, opts, offset);
157- }
158-
159- constexpr bool match (const _string_char_type* text, size_t text_size,
160- _match_result_type& result, size_t offset = 0 ) const {
161- return match (text, text_size, result, regex_match_options::NONE , offset);
162- }
163- constexpr bool match (const _string_type& text, _match_result_type& result, size_t offset = 0 ) const {
164- return match (text.c_str (), text.length (), result, offset);
165- }
166- template <size_t N>
167- constexpr bool match (const _string_char_type (&text)[N], _match_result_type& result, size_t offset = 0) const {
168- return match (text, N - 1 , result, offset);
140+ size_t offset = 0 , regex_match_options opts = static_cast <regex_match_options>(regex_match_options_bits::NONE )) const {
141+ return match (text.c_str (), text.length (), result, offset, opts);
169142 }
170143#pragma endregion MATCH_WITH_RESULT
171144
@@ -177,10 +150,6 @@ namespace pcre2cpp {
177150 constexpr bool match_at (const _string_type& text, size_t offset = 0 ) const {
178151 return match_at (text.c_str (), text.length (), offset);
179152 }
180- template <size_t N>
181- constexpr bool match_at (const _string_char_type (&text)[N], size_t offset = 0) const {
182- return match_at (text, N - 1 , offset);
183- }
184153#pragma endregion MATCH_AT
185154
186155#pragma region MATCH_AT_WITH_RESULT
@@ -199,10 +168,6 @@ namespace pcre2cpp {
199168 constexpr bool match_at (const _string_type& text, _match_result_type& result, size_t offset = 0 ) const {
200169 return match_at (text.c_str (), text.length (), result, offset);
201170 }
202- template <size_t N>
203- constexpr bool match_at (const _string_char_type (&text)[N], _match_result_type& result, size_t offset = 0) const {
204- return match_at (text, N - 1 , result, offset);
205- }
206171#pragma endregion MATCH_AT_WITH_RESULT
207172
208173#pragma region MATCH_ALL_WITH_RESULT
@@ -224,10 +189,6 @@ namespace pcre2cpp {
224189 constexpr bool match_all (const _string_type& text, std::vector<_match_result_type>& results, size_t offset = 0 ) const {
225190 return match_all (text.c_str (), text.length (), results, offset);
226191 }
227- template <size_t N>
228- constexpr bool match_all (const _string_char_type (&text)[N], std::vector<_match_result_type>& results, size_t offset = 0) const {
229- return match_all (text, N - 1 , results, offset);
230- }
231192
232193 constexpr bool match_all (const _string_char_type* text, size_t text_size, _match_result_type*& results, size_t & results_count, size_t offset = 0 ) const {
233194 std::vector<_match_result_type> temp_results;
@@ -244,10 +205,6 @@ namespace pcre2cpp {
244205 constexpr bool match_all (const _string_type& text, _match_result_type*& results, size_t & results_count, size_t offset = 0 ) const {
245206 return match_all (text.c_str (), text.length (), results, results_count, offset);
246207 }
247- template <size_t N>
248- constexpr bool match_all (const _string_char_type (&text)[N], _match_result_type*& results, size_t& results_count, size_t offset = 0) const {
249- return match_all (text, N - 1 , results, results_count, offset);
250- }
251208#pragma endregion MATCH_ALL_WITH_RESULT
252209 };
253210}
0 commit comments