PCRE2 C++ Wrapper 1.2.4
pcre2cpp
Loading...
Searching...
No Matches
pcre2_data.hpp
Go to the documentation of this file.
1/*
2 * pcre2cpp - PCRE2 cpp wrapper
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/pcre2cpp/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 *
9 * PCRE2 library included in this project:
10 * Copyright (c) 2016-2024, University of Cambridge.
11 *
12 * See the LICENSE_PCRE2 file for details: https://github.com/MAIPA01/pcre2cpp/blob/main/LICENSE_PCRE2
13 */
14
15#pragma once
16#ifndef _PCRE2CPP_PCRE2_DATA_HPP_
17 #define _PCRE2CPP_PCRE2_DATA_HPP_
18
19 #include <pcre2cpp/config.hpp>
20
21 #if !_PCRE2CPP_HAS_CXX17
22_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
23 #else
24 #include <pcre2cpp/types.hpp>
25
26namespace pcre2cpp {
31 enum class utf_type : uint8_t {
32 #if _PCRE2CPP_HAS_UTF8
33 UTF_8 = 8,
34 #endif
35 #if _PCRE2CPP_HAS_UTF16
36 UTF_16 = 16,
37 #endif
38 #if _PCRE2CPP_HAS_UTF32
39 UTF_32 = 32
40 #endif
41 };
42} // namespace pcre2cpp
43
44namespace pcre2cpp::utils {
50 template<utf_type utf>
51 struct pcre2_data {};
52
53 #pragma region UTF_8
54 #if _PCRE2CPP_HAS_UTF8
59 template<>
60 struct pcre2_data<utf_type::UTF_8> {
61 #pragma region CODE
63 using code_type = pcre2_code_8;
65 using compile_ctx_type = pcre2_compile_context_8;
67 using general_ctx_type = pcre2_general_context_8;
68 #pragma endregion
69
70 #pragma region MATCH
72 using match_data_type = pcre2_match_data_8;
74 using match_ctx_type = pcre2_match_context_8;
75 #pragma endregion
76
77 #pragma region PCRE2_STRING
79 using sptr_type = PCRE2_SPTR8;
81 using uchar_type = PCRE2_UCHAR8;
82 #pragma endregion
83
84 #pragma region CPP_STRING
85 // #if _PCRE2CPP_HAS_CXX20
86 // using string_type = std::u8string;
87 // using string_view_type = std::u8string_view;
88 // #else
89 // using string_type = std::string;
90 // using string_view_type = std::string_view;
91 // #endif
93 using string_type = std::string;
95 using string_view_type = std::string_view;
97 using string_char_type = string_type::value_type;
98 #pragma endregion
99
100 #pragma region UTF_INFO
104 static _PCRE2CPP_CONSTEXPR17 size_t utf_size = 8;
105 #pragma endregion
106
107 #pragma region CODE_FUNCTIONS
109 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<code_type*(sptr_type, size_t, uint32_t, int*, size_t*, compile_ctx_type*)>
110 compile = pcre2_compile_8;
112 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(code_type*)> code_free = pcre2_code_free_8;
113 #pragma endregion
114
115 #pragma region MATCH_DATA_FUNCTIONS
117 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<match_data_type*(const code_type*, general_ctx_type*)>
118 match_data_from_pattern = pcre2_match_data_create_from_pattern_8;
120 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(match_data_type*)> match_data_free = pcre2_match_data_free_8;
121 #pragma endregion
122
123 #pragma region MATCH_FUNCTIONS
126 mstd::c_func_t<int(const code_type*, sptr_type, size_t, size_t, uint32_t, match_data_type*, match_ctx_type*)>
127 match = pcre2_match_8;
128 #pragma endregion
129
130 #pragma region OVECTOR_FUNCTIONS
132 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<size_t*(match_data_type*)> get_ovector_ptr = pcre2_get_ovector_pointer_8;
134 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<uint32_t(match_data_type*)> get_ovector_count = pcre2_get_ovector_count_8;
135 #pragma endregion
136
137 #pragma region ERROR_FUNCTIONS
139 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(int, uchar_type*, size_t)> get_error_message = pcre2_get_error_message_8;
140 #pragma endregion
141
142 #pragma region PATTERN_INFO_FUNCTIONS
144 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, uint32_t, void*)> get_info = pcre2_pattern_info_8;
145 #pragma endregion
146
147 #pragma region SUBSTRING_FUNCTIONS
149 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, sptr_type)> substring_number_from_name =
150 pcre2_substring_number_from_name_8;
151 #pragma endregion
152 };
153 #endif
154
155 #pragma endregion
156
157 #pragma region UTF_16
158
159 #if _PCRE2CPP_HAS_UTF16
164 template<>
165 struct pcre2_data<utf_type::UTF_16> {
166 #pragma region CODE
168 using code_type = pcre2_code_16;
170 using compile_ctx_type = pcre2_compile_context_16;
172 using general_ctx_type = pcre2_general_context_16;
173 #pragma endregion
174
175 #pragma region MATCH
177 using match_data_type = pcre2_match_data_16;
179 using match_ctx_type = pcre2_match_context_16;
180 #pragma endregion
181
182 #pragma region PCRE2_STRING
184 using sptr_type = PCRE2_SPTR16;
186 using uchar_type = PCRE2_UCHAR16;
187 #pragma endregion
188
189 #pragma region CPP_STRING
191 using string_type = std::u16string;
193 using string_view_type = std::u16string_view;
195 using string_char_type = string_type::value_type;
196 #pragma endregion
197
198 #pragma region UTF_INFO
202 static _PCRE2CPP_CONSTEXPR17 size_t utf_size = 16;
203 #pragma endregion
204
205 #pragma region CODE_FUNCTIONS
207 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<code_type*(sptr_type, size_t, uint32_t, int*, size_t*, compile_ctx_type*)>
208 compile = pcre2_compile_16;
210 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(code_type*)> code_free = pcre2_code_free_16;
211 #pragma endregion
212
213 #pragma region MATCH_DATA_FUNCTIONS
215 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<match_data_type*(const code_type*, general_ctx_type*)>
216 match_data_from_pattern = pcre2_match_data_create_from_pattern_16;
218 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(match_data_type*)> match_data_free = pcre2_match_data_free_16;
219 #pragma endregion
220
221 #pragma region MATCH_FUNCTIONS
224 mstd::c_func_t<int(const code_type*, sptr_type, size_t, size_t, uint32_t, match_data_type*, match_ctx_type*)>
225 match = pcre2_match_16;
226 #pragma endregion
227
228 #pragma region OVECTOR_FUNCTIONS
230 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<size_t*(match_data_type*)> get_ovector_ptr = pcre2_get_ovector_pointer_16;
232 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<uint32_t(match_data_type*)> get_ovector_count = pcre2_get_ovector_count_16;
233 #pragma endregion
234
235 #pragma region ERROR_FUNCTIONS
237 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(int, uchar_type*, size_t)> get_error_message = pcre2_get_error_message_16;
238 #pragma endregion
239
240 #pragma region PATTERN_INFO_FUNCTIONS
242 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, uint32_t, void*)> get_info = pcre2_pattern_info_16;
243 #pragma endregion
244
245 #pragma region SUBSTRING_FUNCTIONS
247 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, sptr_type)> substring_number_from_name =
248 pcre2_substring_number_from_name_16;
249 #pragma endregion
250 };
251 #endif
252
253 #pragma endregion
254
255 #pragma region UTF_32
256
257 #if _PCRE2CPP_HAS_UTF32
262 template<>
263 struct pcre2_data<utf_type::UTF_32> {
264 #pragma region CODE
266 using code_type = pcre2_code_32;
268 using compile_ctx_type = pcre2_compile_context_32;
270 using general_ctx_type = pcre2_general_context_32;
271 #pragma endregion
272
273 #pragma region MATCH
275 using match_data_type = pcre2_match_data_32;
277 using match_ctx_type = pcre2_match_context_32;
278 #pragma endregion
279
280 #pragma region PCRE2_STRING
282 using sptr_type = PCRE2_SPTR32;
284 using uchar_type = PCRE2_UCHAR32;
285 #pragma endregion
286
287 #pragma region CPP_STRING
289 using string_type = std::u32string;
291 using string_view_type = std::u32string_view;
293 using string_char_type = string_type::value_type;
294 #pragma endregion
295
296 #pragma region UTF_INFO
300 static _PCRE2CPP_CONSTEXPR17 size_t utf_size = 32;
301 #pragma endregion
302
303 #pragma region CODE_FUNCTIONS
305 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<code_type*(sptr_type, size_t, uint32_t, int*, size_t*, compile_ctx_type*)>
306 compile = pcre2_compile_32;
308 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(code_type*)> code_free = pcre2_code_free_32;
309 #pragma endregion
310
311 #pragma region MATCH_DATA_FUNCTIONS
313 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<match_data_type*(const code_type*, general_ctx_type*)>
314 match_data_from_pattern = pcre2_match_data_create_from_pattern_32;
316 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<void(match_data_type*)> match_data_free = pcre2_match_data_free_32;
317 #pragma endregion
318
319 #pragma region MATCH_FUNCTIONS
322 mstd::c_func_t<int(const code_type*, sptr_type, size_t, size_t, uint32_t, match_data_type*, match_ctx_type*)>
323 match = pcre2_match_32;
324 #pragma endregion
325
326 #pragma region OVECTOR_FUNCTIONS
328 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<size_t*(match_data_type*)> get_ovector_ptr = pcre2_get_ovector_pointer_32;
330 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<uint32_t(match_data_type*)> get_ovector_count = pcre2_get_ovector_count_32;
331 #pragma endregion
332
333 #pragma region ERROR_FUNCTIONS
335 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(int, uchar_type*, size_t)> get_error_message = pcre2_get_error_message_32;
336 #pragma endregion
337
338 #pragma region PATTERN_INFO_FUNCTIONS
340 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, uint32_t, void*)> get_info = pcre2_pattern_info_32;
341 #pragma endregion
342
343 #pragma region SUBSTRING_FUNCTIONS
345 static _PCRE2CPP_CONSTEXPR17 mstd::c_func_t<int(const code_type*, sptr_type)> substring_number_from_name =
346 pcre2_substring_number_from_name_32;
347 #pragma endregion
348 };
349 #endif
350
351 #pragma endregion
352
353 #if _PCRE2CPP_HAS_UTF8
355 #endif
356 #if _PCRE2CPP_HAS_UTF16
358 #endif
359 #if _PCRE2CPP_HAS_UTF32
361 #endif
362} // namespace pcre2cpp::utils
363 #endif
364#endif
utf_type
Enum with supported utf types.
Definition pcre2cpp.hpp:352
@ UTF_16
Definition pcre2cpp.hpp:357
@ UTF_32
Definition pcre2cpp.hpp:360
@ UTF_8
Definition pcre2cpp.hpp:354
#define _PCRE2CPP_CONSTEXPR17
constexpr for c++17 and higher
Definition config.hpp:239
#define _PCRE2CPP_ERROR(MESSAGE)
compiler error
Definition config.hpp:278
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.
Translation container from pcre2 library to pcre2cpp.
Definition pcre2cpp.hpp:372