JPCRE2  10.32.01
C++ wrapper for PCRE2 library
jpcre2.hpp
Go to the documentation of this file.
1 /* *****************************************************************************
2  * ******************* C++ wrapper for PCRE2 Library ****************************
3  * *****************************************************************************
4  * Copyright (c) Md. Jahidul Hamid
5  *
6  * -----------------------------------------------------------------------------
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * * The names of its contributors may not be used to endorse or promote
18  * products derived from this software without specific prior written
19  * permission.
20  *
21  * Disclaimer:
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  * */
35 
47 #ifndef JPCRE2_HPP
48 #define JPCRE2_HPP
49 
50 #ifndef PCRE2_CODE_UNIT_WIDTH
51 
58 #define PCRE2_CODE_UNIT_WIDTH 0
59 #endif
60 
61 //previous inclusion of pcre2.h will be respected and we won't try to include it twice.
62 //Thus one can pre-include pcre2.h from an arbitrary/non-standard path.
63 #ifndef PCRE2_MAJOR
64  #include <pcre2.h> // pcre2 header
65 #endif
66 #include <string> // std::string, std::wstring
67 #include <vector> // std::vector
68 #include <map> // std::map
69 #include <cstdio> // std::fprintf
70 #include <climits> // CHAR_BIT
71 #include <cstdlib> // std::abort()
72 
73 #if __cplusplus >= 201103L || _MSVC_LANG >= 201103L
74  #define JPCRE2_USE_MINIMUM_CXX_11 1
75  #include <utility>
76  #ifndef JPCRE2_USE_FUNCTION_POINTER_CALLBACK
77  #include <functional> // std::function
78  #endif
79 #else
80  #define JPCRE2_USE_MINIMUM_CXX_11 0
81 #endif
82 
83 #define JPCRE2_UNUSED(x) ((void)(x))
84 #if defined(NDEBUG) || defined(JPCRE2_NDEBUG)
85  #define JPCRE2_ASSERT(cond, msg) ((void)0)
86  #define JPCRE2_VECTOR_DATA_ASSERT(cond, name) ((void)0)
87 #else
88  #define JPCRE2_ASSERT(cond, msg) jpcre2::jassert(cond, msg, __FILE__, __LINE__)
89  #define JPCRE2_VECTOR_DATA_ASSERT(cond, name) jpcre2::_jvassert(cond, name, __FILE__, __LINE__)
90 #endif
91 
92 // In Windows, Windows.h defines ERROR macro
93 // It conflicts with our jpcre2::ERROR namespace
94 #ifdef ERROR
95 #undef ERROR
96 #endif
97 
98 
108 namespace jpcre2 {
109 
110 
113 #define JPCRE2_VERSION 103201L
114 
119 namespace INFO {
120  static const char NAME[] = "JPCRE2";
121  static const char FULL_VERSION[] = "10.32.01";
122  static const char VERSION_GENRE[] = "10";
123  static const char VERSION_MAJOR[] = "32";
124  static const char VERSION_MINOR[] = "01";
125  static const char VERSION_PRE_RELEASE[] = "";
126 }
127 
128 
129 typedef PCRE2_SIZE SIZE_T;
130 typedef uint32_t Uint;
131 typedef uint8_t Ush;
132 typedef std::vector<SIZE_T> VecOff;
133 typedef std::vector<Uint> VecOpt;
134 
137 namespace ERROR {
142  enum {
145  };
146 }
147 
148 
151 enum {
152  NONE = 0x0000000u,
153  FIND_ALL = 0x0000002u,
154  JIT_COMPILE = 0x0000004u
155 };
156 
157 
158 //enableif and is_same implementation
159 template<bool B, typename T = void>
160 struct EnableIf{};
161 template<typename T>
162 struct EnableIf<true, T>{typedef T Type;};
163 
164 template<typename T1, typename T2>
165 struct IsSame{ static const bool value = false; };
166 template<typename T>
167 struct IsSame<T,T>{ static const bool value = true; };
168 
169 
176 static inline void jassert(bool cond, const char* msg, const char* f, size_t line){
177  if(!cond) {
178  std::fprintf(stderr,"\n\tE: AssertionFailure\n%s\nAssertion failed in file: %s\t at line: %u\n", msg, f, (unsigned)line);
179  std::abort();
180  }
181 }
182 
183 static inline void _jvassert(bool cond, char const * name, const char* f, size_t line){
184  jassert(cond, (std::string("ValueError: \n\
185  Required data vector of type ")+std::string(name)+" is empty.\n\
186  Your MatchEvaluator callback function is not\n\
187  compatible with existing data!!\n\
188  You are trying to use a vector that does not\n\
189  have any match data. Either call nreplace() or replace()\n\
190  with true or perform a match with appropriate\n\
191  callback function. For more details, refer to\n\
192  the doc in MatchEvaluator section.").c_str(), f, line);
193 }
194 
195 static inline std::string _tostdstring(unsigned x){
196  char buf[128];
197  int written = std::sprintf(buf, "%u", x);
198  return (written > 0) ? std::string(buf, buf + written) : std::string();
199 }
200 
201 
203 
204 //forward declaration
205 
206 template<Ush BS> struct Pcre2Type;
207 template<Ush BS> struct Pcre2Func;
208 
209 //PCRE2 types
210 //These templated types will be used in place of actual types
211 template<Ush BS> struct Pcre2Type {};
212 
213 template<> struct Pcre2Type<8>{
214  //typedefs used
215  typedef PCRE2_UCHAR8 Pcre2Uchar;
216  typedef PCRE2_SPTR8 Pcre2Sptr;
217  typedef pcre2_code_8 Pcre2Code;
218  typedef pcre2_compile_context_8 CompileContext;
219  typedef pcre2_match_data_8 MatchData;
220  typedef pcre2_general_context_8 GeneralContext;
221  typedef pcre2_match_context_8 MatchContext;
222  typedef pcre2_jit_callback_8 JitCallback;
223  typedef pcre2_jit_stack_8 JitStack;
224 };
225 
226 template<> struct Pcre2Type<16>{
227  //typedefs used
228  typedef PCRE2_UCHAR16 Pcre2Uchar;
229  typedef PCRE2_SPTR16 Pcre2Sptr;
230  typedef pcre2_code_16 Pcre2Code;
231  typedef pcre2_compile_context_16 CompileContext;
232  typedef pcre2_match_data_16 MatchData;
233  typedef pcre2_general_context_16 GeneralContext;
234  typedef pcre2_match_context_16 MatchContext;
235  typedef pcre2_jit_callback_16 JitCallback;
236  typedef pcre2_jit_stack_16 JitStack;
237 };
238 
239 template<> struct Pcre2Type<32>{
240  //typedefs used
241  typedef PCRE2_UCHAR32 Pcre2Uchar;
242  typedef PCRE2_SPTR32 Pcre2Sptr;
243  typedef pcre2_code_32 Pcre2Code;
244  typedef pcre2_compile_context_32 CompileContext;
245  typedef pcre2_match_data_32 MatchData;
246  typedef pcre2_general_context_32 GeneralContext;
247  typedef pcre2_match_context_32 MatchContext;
248  typedef pcre2_jit_callback_32 JitCallback;
249  typedef pcre2_jit_stack_32 JitStack;
250 };
251 
252 //wrappers for PCRE2 functions
253 template<Ush BS> struct Pcre2Func{};
254 
255 //8-bit version
256 template<> struct Pcre2Func<8> {
257  static Pcre2Type<8>::CompileContext* compile_context_create(Pcre2Type<8>::GeneralContext *gcontext){
258  return pcre2_compile_context_create_8(gcontext);
259  }
260  static void compile_context_free(Pcre2Type<8>::CompileContext *ccontext){
261  pcre2_compile_context_free_8(ccontext);
262  }
263  static Pcre2Type<8>::CompileContext* compile_context_copy(Pcre2Type<8>::CompileContext* ccontext){
264  return pcre2_compile_context_copy_8(ccontext);
265  }
266  static const unsigned char * maketables(Pcre2Type<8>::GeneralContext* gcontext){
267  return pcre2_maketables_8(gcontext);
268  }
269  static int set_character_tables(Pcre2Type<8>::CompileContext * ccontext, const unsigned char * table){
270  return pcre2_set_character_tables_8(ccontext, table);
271  }
272  static Pcre2Type<8>::Pcre2Code * compile(Pcre2Type<8>::Pcre2Sptr pattern,
273  PCRE2_SIZE length,
274  uint32_t options,
275  int *errorcode,
276  PCRE2_SIZE *erroroffset,
277  Pcre2Type<8>::CompileContext *ccontext){
278  return pcre2_compile_8(pattern, length, options, errorcode, erroroffset, ccontext);
279  }
280  static int jit_compile(Pcre2Type<8>::Pcre2Code *code, uint32_t options){
281  return pcre2_jit_compile_8(code, options);
282  }
283  static int substitute( const Pcre2Type<8>::Pcre2Code *code,
284  Pcre2Type<8>::Pcre2Sptr subject,
285  PCRE2_SIZE length,
286  PCRE2_SIZE startoffset,
287  uint32_t options,
288  Pcre2Type<8>::MatchData *match_data,
289  Pcre2Type<8>::MatchContext *mcontext,
290  Pcre2Type<8>::Pcre2Sptr replacement,
291  PCRE2_SIZE rlength,
292  Pcre2Type<8>::Pcre2Uchar *outputbuffer,
293  PCRE2_SIZE *outlengthptr){
294  return pcre2_substitute_8( code, subject, length, startoffset, options, match_data,
295  mcontext, replacement, rlength, outputbuffer, outlengthptr);
296  }
297  //~ static int substring_get_bynumber(Pcre2Type<8>::MatchData *match_data,
298  //~ uint32_t number,
299  //~ Pcre2Type<8>::Pcre2Uchar **bufferptr,
300  //~ PCRE2_SIZE *bufflen){
301  //~ return pcre2_substring_get_bynumber_8(match_data, number, bufferptr, bufflen);
302  //~ }
303  //~ static int substring_get_byname(Pcre2Type<8>::MatchData *match_data,
304  //~ Pcre2Type<8>::Pcre2Sptr name,
305  //~ Pcre2Type<8>::Pcre2Uchar **bufferptr,
306  //~ PCRE2_SIZE *bufflen){
307  //~ return pcre2_substring_get_byname_8(match_data, name, bufferptr, bufflen);
308  //~ }
309  //~ static void substring_free(Pcre2Type<8>::Pcre2Uchar *buffer){
310  //~ pcre2_substring_free_8(buffer);
311  //~ }
312  //~ static Pcre2Type<8>::Pcre2Code * code_copy(const Pcre2Type<8>::Pcre2Code *code){
313  //~ return pcre2_code_copy_8(code);
314  //~ }
315  static void code_free(Pcre2Type<8>::Pcre2Code *code){
316  pcre2_code_free_8(code);
317  }
318  static int get_error_message( int errorcode,
319  Pcre2Type<8>::Pcre2Uchar *buffer,
320  PCRE2_SIZE bufflen){
321  return pcre2_get_error_message_8(errorcode, buffer, bufflen);
322  }
323  static Pcre2Type<8>::MatchData * match_data_create_from_pattern(
324  const Pcre2Type<8>::Pcre2Code *code,
325  Pcre2Type<8>::GeneralContext *gcontext){
326  return pcre2_match_data_create_from_pattern_8(code, gcontext);
327 
328  }
329  static int match( const Pcre2Type<8>::Pcre2Code *code,
330  Pcre2Type<8>::Pcre2Sptr subject,
331  PCRE2_SIZE length,
332  PCRE2_SIZE startoffset,
333  uint32_t options,
334  Pcre2Type<8>::MatchData *match_data,
335  Pcre2Type<8>::MatchContext *mcontext){
336  return pcre2_match_8(code, subject, length, startoffset, options, match_data, mcontext);
337  }
338  static void match_data_free(Pcre2Type<8>::MatchData *match_data){
339  pcre2_match_data_free_8(match_data);
340  }
341  static PCRE2_SIZE * get_ovector_pointer(Pcre2Type<8>::MatchData *match_data){
342  return pcre2_get_ovector_pointer_8(match_data);
343  }
344  static int pattern_info(const Pcre2Type<8>::Pcre2Code *code, uint32_t what, void *where){
345  return pcre2_pattern_info_8(code, what, where);
346  }
347  static int set_newline(Pcre2Type<8>::CompileContext *ccontext, uint32_t value){
348  return pcre2_set_newline_8(ccontext, value);
349  }
350  //~ static void jit_stack_assign(Pcre2Type<8>::MatchContext *mcontext,
351  //~ Pcre2Type<8>::JitCallback callback_function,
352  //~ void *callback_data){
353  //~ pcre2_jit_stack_assign_8(mcontext, callback_function, callback_data);
354  //~ }
355  //~ static Pcre2Type<8>::JitStack *jit_stack_create(PCRE2_SIZE startsize, PCRE2_SIZE maxsize,
356  //~ Pcre2Type<8>::GeneralContext *gcontext){
357  //~ return pcre2_jit_stack_create_8(startsize, maxsize, gcontext);
358  //~ }
359  //~ static void jit_stack_free(Pcre2Type<8>::JitStack *jit_stack){
360  //~ pcre2_jit_stack_free_8(jit_stack);
361  //~ }
362  //~ static void jit_free_unused_memory(Pcre2Type<8>::GeneralContext *gcontext){
363  //~ pcre2_jit_free_unused_memory_8(gcontext);
364  //~ }
365  //~ static Pcre2Type<8>::MatchContext *match_context_create(Pcre2Type<8>::GeneralContext *gcontext){
366  //~ return pcre2_match_context_create_8(gcontext);
367  //~ }
368  //~ static Pcre2Type<8>::MatchContext *match_context_copy(Pcre2Type<8>::MatchContext *mcontext){
369  //~ return pcre2_match_context_copy_8(mcontext);
370  //~ }
371  //~ static void match_context_free(Pcre2Type<8>::MatchContext *mcontext){
372  //~ pcre2_match_context_free_8(mcontext);
373  //~ }
374  static uint32_t get_ovector_count(Pcre2Type<8>::MatchData *match_data){
375  return pcre2_get_ovector_count_8(match_data);
376  }
377 };
378 
379 //16-bit version
380 template<> struct Pcre2Func<16> {
381  static Pcre2Type<16>::CompileContext* compile_context_create(Pcre2Type<16>::GeneralContext *gcontext){
382  return pcre2_compile_context_create_16(gcontext);
383  }
384  static void compile_context_free(Pcre2Type<16>::CompileContext *ccontext){
385  pcre2_compile_context_free_16(ccontext);
386  }
387  static Pcre2Type<16>::CompileContext* compile_context_copy(Pcre2Type<16>::CompileContext* ccontext){
388  return pcre2_compile_context_copy_16(ccontext);
389  }
390  static const unsigned char * maketables(Pcre2Type<16>::GeneralContext* gcontext){
391  return pcre2_maketables_16(gcontext);
392  }
393  static int set_character_tables(Pcre2Type<16>::CompileContext * ccontext, const unsigned char * table){
394  return pcre2_set_character_tables_16(ccontext, table);
395  }
396  static Pcre2Type<16>::Pcre2Code * compile(Pcre2Type<16>::Pcre2Sptr pattern,
397  PCRE2_SIZE length,
398  uint32_t options,
399  int *errorcode,
400  PCRE2_SIZE *erroroffset,
401  Pcre2Type<16>::CompileContext *ccontext){
402  return pcre2_compile_16(pattern, length, options, errorcode, erroroffset, ccontext);
403  }
404  static int jit_compile(Pcre2Type<16>::Pcre2Code *code, uint32_t options){
405  return pcre2_jit_compile_16(code, options);
406  }
407  static int substitute( const Pcre2Type<16>::Pcre2Code *code,
408  Pcre2Type<16>::Pcre2Sptr subject,
409  PCRE2_SIZE length,
410  PCRE2_SIZE startoffset,
411  uint32_t options,
412  Pcre2Type<16>::MatchData *match_data,
413  Pcre2Type<16>::MatchContext *mcontext,
414  Pcre2Type<16>::Pcre2Sptr replacement,
415  PCRE2_SIZE rlength,
416  Pcre2Type<16>::Pcre2Uchar *outputbuffer,
417  PCRE2_SIZE *outlengthptr){
418  return pcre2_substitute_16( code, subject, length, startoffset, options, match_data,
419  mcontext, replacement, rlength, outputbuffer, outlengthptr);
420  }
421  //~ static int substring_get_bynumber(Pcre2Type<16>::MatchData *match_data,
422  //~ uint32_t number,
423  //~ Pcre2Type<16>::Pcre2Uchar **bufferptr,
424  //~ PCRE2_SIZE *bufflen){
425  //~ return pcre2_substring_get_bynumber_16(match_data, number, bufferptr, bufflen);
426  //~ }
427  //~ static int substring_get_byname(Pcre2Type<16>::MatchData *match_data,
428  //~ Pcre2Type<16>::Pcre2Sptr name,
429  //~ Pcre2Type<16>::Pcre2Uchar **bufferptr,
430  //~ PCRE2_SIZE *bufflen){
431  //~ return pcre2_substring_get_byname_16(match_data, name, bufferptr, bufflen);
432  //~ }
433  //~ static void substring_free(Pcre2Type<16>::Pcre2Uchar *buffer){
434  //~ pcre2_substring_free_16(buffer);
435  //~ }
436  //~ static Pcre2Type<16>::Pcre2Code * code_copy(const Pcre2Type<16>::Pcre2Code *code){
437  //~ return pcre2_code_copy_16(code);
438  //~ }
439  static void code_free(Pcre2Type<16>::Pcre2Code *code){
440  pcre2_code_free_16(code);
441  }
442  static int get_error_message( int errorcode,
443  Pcre2Type<16>::Pcre2Uchar *buffer,
444  PCRE2_SIZE bufflen){
445  return pcre2_get_error_message_16(errorcode, buffer, bufflen);
446  }
447  static Pcre2Type<16>::MatchData * match_data_create_from_pattern(
448  const Pcre2Type<16>::Pcre2Code *code,
449  Pcre2Type<16>::GeneralContext *gcontext){
450  return pcre2_match_data_create_from_pattern_16(code, gcontext);
451 
452  }
453  static int match( const Pcre2Type<16>::Pcre2Code *code,
454  Pcre2Type<16>::Pcre2Sptr subject,
455  PCRE2_SIZE length,
456  PCRE2_SIZE startoffset,
457  uint32_t options,
458  Pcre2Type<16>::MatchData *match_data,
459  Pcre2Type<16>::MatchContext *mcontext){
460  return pcre2_match_16(code, subject, length, startoffset, options, match_data, mcontext);
461  }
462  static void match_data_free(Pcre2Type<16>::MatchData *match_data){
463  pcre2_match_data_free_16(match_data);
464  }
465  static PCRE2_SIZE * get_ovector_pointer(Pcre2Type<16>::MatchData *match_data){
466  return pcre2_get_ovector_pointer_16(match_data);
467  }
468  static int pattern_info(const Pcre2Type<16>::Pcre2Code *code, uint32_t what, void *where){
469  return pcre2_pattern_info_16(code, what, where);
470  }
471  static int set_newline(Pcre2Type<16>::CompileContext *ccontext, uint32_t value){
472  return pcre2_set_newline_16(ccontext, value);
473  }
474  //~ static void jit_stack_assign(Pcre2Type<16>::MatchContext *mcontext,
475  //~ Pcre2Type<16>::JitCallback callback_function,
476  //~ void *callback_data){
477  //~ pcre2_jit_stack_assign_16(mcontext, callback_function, callback_data);
478  //~ }
479  //~ static Pcre2Type<16>::JitStack *jit_stack_create(PCRE2_SIZE startsize, PCRE2_SIZE maxsize,
480  //~ Pcre2Type<16>::GeneralContext *gcontext){
481  //~ return pcre2_jit_stack_create_16(startsize, maxsize, gcontext);
482  //~ }
483  //~ static void jit_stack_free(Pcre2Type<16>::JitStack *jit_stack){
484  //~ pcre2_jit_stack_free_16(jit_stack);
485  //~ }
486  //~ static void jit_free_unused_memory(Pcre2Type<16>::GeneralContext *gcontext){
487  //~ pcre2_jit_free_unused_memory_16(gcontext);
488  //~ }
489  //~ static Pcre2Type<16>::MatchContext *match_context_create(Pcre2Type<16>::GeneralContext *gcontext){
490  //~ return pcre2_match_context_create_16(gcontext);
491  //~ }
492  //~ static Pcre2Type<16>::MatchContext *match_context_copy(Pcre2Type<16>::MatchContext *mcontext){
493  //~ return pcre2_match_context_copy_16(mcontext);
494  //~ }
495  //~ static void match_context_free(Pcre2Type<16>::MatchContext *mcontext){
496  //~ pcre2_match_context_free_16(mcontext);
497  //~ }
498  static uint32_t get_ovector_count(Pcre2Type<16>::MatchData *match_data){
499  return pcre2_get_ovector_count_16(match_data);
500  }
501 };
502 
503 //32-bit version
504 template<> struct Pcre2Func<32> {
505  static Pcre2Type<32>::CompileContext* compile_context_create(Pcre2Type<32>::GeneralContext *gcontext){
506  return pcre2_compile_context_create_32(gcontext);
507  }
508  static void compile_context_free(Pcre2Type<32>::CompileContext *ccontext){
509  pcre2_compile_context_free_32(ccontext);
510  }
511  static Pcre2Type<32>::CompileContext* compile_context_copy(Pcre2Type<32>::CompileContext* ccontext){
512  return pcre2_compile_context_copy_32(ccontext);
513  }
514  static const unsigned char * maketables(Pcre2Type<32>::GeneralContext* gcontext){
515  return pcre2_maketables_32(gcontext);
516  }
517  static int set_character_tables(Pcre2Type<32>::CompileContext * ccontext, const unsigned char * table){
518  return pcre2_set_character_tables_32(ccontext, table);
519  }
520  static Pcre2Type<32>::Pcre2Code * compile(Pcre2Type<32>::Pcre2Sptr pattern,
521  PCRE2_SIZE length,
522  uint32_t options,
523  int *errorcode,
524  PCRE2_SIZE *erroroffset,
525  Pcre2Type<32>::CompileContext *ccontext){
526  return pcre2_compile_32(pattern, length, options, errorcode, erroroffset, ccontext);
527  }
528  static int jit_compile(Pcre2Type<32>::Pcre2Code *code, uint32_t options){
529  return pcre2_jit_compile_32(code, options);
530  }
531  static int substitute( const Pcre2Type<32>::Pcre2Code *code,
532  Pcre2Type<32>::Pcre2Sptr subject,
533  PCRE2_SIZE length,
534  PCRE2_SIZE startoffset,
535  uint32_t options,
536  Pcre2Type<32>::MatchData *match_data,
537  Pcre2Type<32>::MatchContext *mcontext,
538  Pcre2Type<32>::Pcre2Sptr replacement,
539  PCRE2_SIZE rlength,
540  Pcre2Type<32>::Pcre2Uchar *outputbuffer,
541  PCRE2_SIZE *outlengthptr){
542  return pcre2_substitute_32( code, subject, length, startoffset, options, match_data,
543  mcontext, replacement, rlength, outputbuffer, outlengthptr);
544  }
545  //~ static int substring_get_bynumber(Pcre2Type<32>::MatchData *match_data,
546  //~ uint32_t number,
547  //~ Pcre2Type<32>::Pcre2Uchar **bufferptr,
548  //~ PCRE2_SIZE *bufflen){
549  //~ return pcre2_substring_get_bynumber_32(match_data, number, bufferptr, bufflen);
550  //~ }
551  //~ static int substring_get_byname(Pcre2Type<32>::MatchData *match_data,
552  //~ Pcre2Type<32>::Pcre2Sptr name,
553  //~ Pcre2Type<32>::Pcre2Uchar **bufferptr,
554  //~ PCRE2_SIZE *bufflen){
555  //~ return pcre2_substring_get_byname_32(match_data, name, bufferptr, bufflen);
556  //~ }
557  //~ static void substring_free(Pcre2Type<32>::Pcre2Uchar *buffer){
558  //~ pcre2_substring_free_32(buffer);
559  //~ }
560  //~ static Pcre2Type<32>::Pcre2Code * code_copy(const Pcre2Type<32>::Pcre2Code *code){
561  //~ return pcre2_code_copy_32(code);
562  //~ }
563  static void code_free(Pcre2Type<32>::Pcre2Code *code){
564  pcre2_code_free_32(code);
565  }
566  static int get_error_message( int errorcode,
567  Pcre2Type<32>::Pcre2Uchar *buffer,
568  PCRE2_SIZE bufflen){
569  return pcre2_get_error_message_32(errorcode, buffer, bufflen);
570  }
571  static Pcre2Type<32>::MatchData * match_data_create_from_pattern(
572  const Pcre2Type<32>::Pcre2Code *code,
573  Pcre2Type<32>::GeneralContext *gcontext){
574  return pcre2_match_data_create_from_pattern_32(code, gcontext);
575 
576  }
577  static int match( const Pcre2Type<32>::Pcre2Code *code,
578  Pcre2Type<32>::Pcre2Sptr subject,
579  PCRE2_SIZE length,
580  PCRE2_SIZE startoffset,
581  uint32_t options,
582  Pcre2Type<32>::MatchData *match_data,
583  Pcre2Type<32>::MatchContext *mcontext){
584  return pcre2_match_32(code, subject, length, startoffset, options, match_data, mcontext);
585  }
586  static void match_data_free(Pcre2Type<32>::MatchData *match_data){
587  pcre2_match_data_free_32(match_data);
588  }
589  static PCRE2_SIZE * get_ovector_pointer(Pcre2Type<32>::MatchData *match_data){
590  return pcre2_get_ovector_pointer_32(match_data);
591  }
592  static int pattern_info(const Pcre2Type<32>::Pcre2Code *code, uint32_t what, void *where){
593  return pcre2_pattern_info_32(code, what, where);
594  }
595  static int set_newline(Pcre2Type<32>::CompileContext *ccontext, uint32_t value){
596  return pcre2_set_newline_32(ccontext, value);
597  }
598  //~ static void jit_stack_assign(Pcre2Type<32>::MatchContext *mcontext,
599  //~ Pcre2Type<32>::JitCallback callback_function,
600  //~ void *callback_data){
601  //~ pcre2_jit_stack_assign_32(mcontext, callback_function, callback_data);
602  //~ }
603  //~ static Pcre2Type<32>::JitStack *jit_stack_create(PCRE2_SIZE startsize, PCRE2_SIZE maxsize,
604  //~ Pcre2Type<32>::GeneralContext *gcontext){
605  //~ return pcre2_jit_stack_create_32(startsize, maxsize, gcontext);
606  //~ }
607  //~ static void jit_stack_free(Pcre2Type<32>::JitStack *jit_stack){
608  //~ pcre2_jit_stack_free_32(jit_stack);
609  //~ }
610  //~ static void jit_free_unused_memory(Pcre2Type<32>::GeneralContext *gcontext){
611  //~ pcre2_jit_free_unused_memory_32(gcontext);
612  //~ }
613  //~ static Pcre2Type<32>::MatchContext *match_context_create(Pcre2Type<32>::GeneralContext *gcontext){
614  //~ return pcre2_match_context_create_32(gcontext);
615  //~ }
616  //~ static Pcre2Type<32>::MatchContext *match_context_copy(Pcre2Type<32>::MatchContext *mcontext){
617  //~ return pcre2_match_context_copy_32(mcontext);
618  //~ }
619  //~ static void match_context_free(Pcre2Type<32>::MatchContext *mcontext){
620  //~ pcre2_match_context_free_32(mcontext);
621  //~ }
622  static uint32_t get_ovector_count(Pcre2Type<32>::MatchData *match_data){
623  return pcre2_get_ovector_count_32(match_data);
624  }
625 };
626 
628 
629 
634 class Modifier{
635  std::string mod;
636 
637  public:
640 
643  Modifier(std::string const& x):mod(x){}
644 
647  Modifier(char const *x):mod(x?x:""){}
648 
651  std::string str() const { return mod; }
652 
655  char const * c_str() const { return mod.c_str(); }
656 
659  SIZE_T length() const{ return mod.length(); }
660 
664  char operator[](SIZE_T i) const { return mod[i]; }
665 };
666 
667 
668 // Namespace for modifier constants.
669 // For each modifier constant there is a jpcre2::Uint option value.
670 // Some modifiers may have multiple values set together (ORed in bitwise operation) and
671 // thus they may include other modifiers. Such an example is the 'n' modifier. It is combined together with 'u'.
672 namespace MOD {
673 
674  // Define modifiers for compile
675  // String of compile modifier characters for PCRE2 options
676  static const char C_N[] = "eijmnsuxADJU";
677  // Array of compile modifier values for PCRE2 options
678  // Uint is being used in getModifier() in for loop to get the number of element in this array,
679  // be sure to chnage there if you change here.
680  static const jpcre2::Uint C_V[12] = { PCRE2_MATCH_UNSET_BACKREF, // Modifier e
681  PCRE2_CASELESS, // Modifier i
682  PCRE2_ALT_BSUX | PCRE2_MATCH_UNSET_BACKREF, // Modifier j
683  PCRE2_MULTILINE, // Modifier m
684  PCRE2_UTF | PCRE2_UCP, // Modifier n (includes u)
685  PCRE2_DOTALL, // Modifier s
686  PCRE2_UTF, // Modifier u
687  PCRE2_EXTENDED, // Modifier x
688  PCRE2_ANCHORED, // Modifier A
689  PCRE2_DOLLAR_ENDONLY, // Modifier D
690  PCRE2_DUPNAMES, // Modifier J
691  PCRE2_UNGREEDY // Modifier U
692  };
693 
694 
695  // String of compile modifier characters for JPCRE2 options
696  static const char CJ_N[] = "S";
697  // Array of compile modifier values for JPCRE2 options
698  static const jpcre2::Uint CJ_V[1] = { JIT_COMPILE, // Modifier S
699  };
700 
701 
702  // Define modifiers for replace
703  // String of action (replace) modifier characters for PCRE2 options
704  static const char R_N[] = "eEgx";
705  // Array of action (replace) modifier values for PCRE2 options
706  static const jpcre2::Uint R_V[4] = { PCRE2_SUBSTITUTE_UNSET_EMPTY, // Modifier e
707  PCRE2_SUBSTITUTE_UNKNOWN_UNSET | PCRE2_SUBSTITUTE_UNSET_EMPTY, // Modifier E (includes e)
708  PCRE2_SUBSTITUTE_GLOBAL, // Modifier g
709  PCRE2_SUBSTITUTE_EXTENDED // Modifier x
710  };
711 
712 
713  // String of action (replace) modifier characters for JPCRE2 options
714  static const char RJ_N[] = "";
715  // Array of action (replace) modifier values for JPCRE2 options
716  static const jpcre2::Uint RJ_V[1] = { NONE //placeholder
717  };
718 
719  // Define modifiers for match
720  // String of action (match) modifier characters for PCRE2 options
721  static const char M_N[] = "A";
722  // Array of action (match) modifier values for PCRE2 options
723  static const jpcre2::Uint M_V[1] = { PCRE2_ANCHORED // Modifier A
724  };
725 
726 
727  // String of action (match) modifier characters for JPCRE2 options
728  static const char MJ_N[] = "g";
729  // Array of action (match) modifier values for JPCRE2 options
730  static const jpcre2::Uint MJ_V[1] = { FIND_ALL, // Modifier g
731  };
732 
733  static inline void toOption(Modifier const& mod, bool x,
734  Uint const * J_V, char const * J_N, SIZE_T SJ,
735  Uint const * V, char const * N, SIZE_T S,
736  Uint* po, Uint* jo,
737  int* en, SIZE_T* eo
738  ){
739  //loop through mod
740  SIZE_T n = mod.length();
741  for (SIZE_T i = 0; i < n; ++i) {
742  //First check for JPCRE2 mods
743  for(SIZE_T j = 0; j < SJ; ++j){
744  if(J_N[j] == mod[i]) {
745  if(x) *jo |= J_V[j];
746  else *jo &= ~J_V[j];
747  goto endfor;
748  }
749  }
750 
751  //Now check for PCRE2 mods
752  for(SIZE_T j = 0; j< S; ++j){
753  if(N[j] == mod[i]){
754  if(x) *po |= V[j];
755  else *po &= ~V[j];
756  goto endfor;
757  }
758  }
759 
760  //Modifier didn't match, invalid modifier
761  *en = (int)ERROR::INVALID_MODIFIER;
762  *eo = (int)mod[i];
763 
764  endfor:;
765  }
766  }
767 
768  static inline void toMatchOption(Modifier const& mod, bool x, Uint* po, Uint* jo, int* en, SIZE_T* eo){
769  toOption(mod, x,
770  MJ_V, MJ_N, sizeof(MJ_V)/sizeof(Uint),
771  M_V, M_N, sizeof(M_V)/sizeof(Uint),
772  po, jo, en, eo);
773  }
774 
775  static inline void toReplaceOption(Modifier const& mod, bool x, Uint* po, Uint* jo, int* en, SIZE_T* eo){
776  toOption(mod, x,
777  RJ_V, RJ_N, sizeof(RJ_V)/sizeof(Uint),
778  R_V, R_N, sizeof(R_V)/sizeof(Uint),
779  po, jo, en, eo);
780  }
781 
782  static inline void toCompileOption(Modifier const& mod, bool x, Uint* po, Uint* jo, int* en, SIZE_T* eo){
783  toOption(mod, x,
784  CJ_V, CJ_N, sizeof(CJ_V)/sizeof(Uint),
785  C_V, C_N, sizeof(C_V)/sizeof(Uint),
786  po, jo, en, eo);
787  }
788 
789  static inline std::string fromOption(Uint const * J_V, char const * J_N, SIZE_T SJ,
790  Uint const * V, char const * N, SIZE_T S,
791  Uint po, Uint jo
792  ){
793  std::string mod;
794  //Calculate PCRE2 mod
795  for(SIZE_T i = 0; i < S; ++i){
796  if( (V[i] & po) != 0 &&
797  (V[i] & po) == V[i]) //One option can include other
798  mod += N[i];
799  }
800  //Calculate JPCRE2 mod
801  for(SIZE_T i = 0; i < SJ; ++i){
802  if( (J_V[i] & jo) != 0 &&
803  (J_V[i] & jo) == J_V[i]) //One option can include other
804  mod += J_N[i];
805  }
806  return mod;
807  }
808 
809  static inline std::string fromMatchOption(Uint po, Uint jo){
810  return fromOption(MJ_V, MJ_N, sizeof(MJ_V)/sizeof(Uint),
811  M_V, M_N, sizeof(M_V)/sizeof(Uint),
812  po, jo);
813  }
814 
815  static inline std::string fromReplaceOption(Uint po, Uint jo){
816  return fromOption(RJ_V, RJ_N, sizeof(RJ_V)/sizeof(Uint),
817  R_V, R_N, sizeof(R_V)/sizeof(Uint),
818  po, jo);
819  }
820 
821  static inline std::string fromCompileOption(Uint po, Uint jo){
822  return fromOption(CJ_V, CJ_N, sizeof(CJ_V)/sizeof(Uint),
823  C_V, C_N, sizeof(C_V)/sizeof(Uint),
824  po, jo);
825  }
826 
827 } //MOD namespace ends
828 
833 
834  std::string tabjms;
835  std::string tabms;
836  std::string tabjrs;
837  std::string tabrs;
838  std::string tabjcs;
839  std::string tabcs;
840  VecOpt tabjmv;
841  VecOpt tabmv;
842  VecOpt tabjrv;
843  VecOpt tabrv;
844  VecOpt tabjcv;
845  VecOpt tabcv;
846 
847  void toOption(Modifier const& mod, bool x,
848  VecOpt const& J_V, std::string const& J_N,
849  VecOpt const& V, std::string const& N,
850  Uint* po, Uint* jo, int* en, SIZE_T* eo
851  ) const{
852  SIZE_T SJ = J_V.size();
853  SIZE_T S = V.size();
854  JPCRE2_ASSERT(SJ == J_N.length(), ("ValueError: Modifier character and value table must be of the same size (" + _tostdstring(SJ) + " == " + _tostdstring(J_N.length()) + ").").c_str());
855  JPCRE2_ASSERT(S == N.length(), ("ValueError: Modifier character and value table must be of the same size (" + _tostdstring(S) + " == " + _tostdstring(N.length()) + ").").c_str());
856  MOD::toOption(mod, x,
857  J_V.empty()?0:&J_V[0], J_N.c_str(), SJ,
858  V.empty()?0:&V[0], N.c_str(), S,
859  po, jo, en, eo
860  );
861  }
862 
863  std::string fromOption(VecOpt const& J_V, std::string const& J_N,
864  VecOpt const& V, std::string const& N,
865  Uint po, Uint jo) const{
866  SIZE_T SJ = J_V.size();
867  SIZE_T S = V.size();
868  JPCRE2_ASSERT(SJ == J_N.length(), ("ValueError: Modifier character and value table must be of the same size (" + _tostdstring(SJ) + " == " + _tostdstring(J_N.length()) + ").").c_str());
869  JPCRE2_ASSERT(S == N.length(), ("ValueError: Modifier character and value table must be of the same size (" + _tostdstring(S) + " == " + _tostdstring(N.length()) + ").").c_str());
870  return MOD::fromOption(J_V.empty()?0:&J_V[0], J_N.c_str(), SJ,
871  V.empty()?0:&V[0], N.c_str(), S,
872  po, jo);
873  }
874 
875  void parseModifierTable(std::string& tabjs, VecOpt& tabjv,
876  std::string& tab_s, VecOpt& tab_v,
877  std::string const& tabs, VecOpt const& tabv);
878  public:
879 
882 
885  ModifierTable(bool deflt){
886  if(deflt) setAllToDefault();
887  }
888 
892  std::string().swap(tabjms);
893  std::string().swap(tabms);
894  VecOpt().swap(tabjmv);
895  VecOpt().swap(tabmv);
896  return *this;
897  }
898 
902  std::string().swap(tabjrs);
903  std::string().swap(tabrs);
904  VecOpt().swap(tabjrv);
905  VecOpt().swap(tabrv);
906  return *this;
907  }
908 
912  std::string().swap(tabjcs);
913  std::string().swap(tabcs);
914  VecOpt().swap(tabjcv);
915  VecOpt().swap(tabcv);
916  return *this;
917  }
918 
925  return *this;
926  }
927 
932  tabjms.clear();
933  tabms.clear();
934  tabjmv.clear();
935  tabmv.clear();
936  return *this;
937  }
938 
943  tabjrs.clear();
944  tabrs.clear();
945  tabjrv.clear();
946  tabrv.clear();
947  return *this;
948  }
949 
954  tabjcs.clear();
955  tabcs.clear();
956  tabjcv.clear();
957  tabcv.clear();
958  return *this;
959  }
960 
968  return *this;
969  }
970 
978  void toMatchOption(Modifier const& mod, bool x, Uint* po, Uint* jo, int* en, SIZE_T* eo) const {
979  toOption(mod, x,tabjmv,tabjms,tabmv, tabms,po,jo,en,eo);
980  }
981 
989  void toReplaceOption(Modifier const& mod, bool x, Uint* po, Uint* jo, int* en, SIZE_T* eo) const {
990  return toOption(mod, x,tabjrv,tabjrs,tabrv,tabrs,po,jo,en,eo);
991  }
992 
1000  void toCompileOption(Modifier const& mod, bool x, Uint* po, Uint* jo, int* en, SIZE_T* eo) const {
1001  return toOption(mod, x,tabjcv,tabjcs,tabcv,tabcs,po,jo,en,eo);
1002  }
1003 
1008  std::string fromMatchOption(Uint po, Uint jo) const {
1009  return fromOption(tabjmv,tabjms,tabmv,tabms,po,jo);
1010  }
1011 
1016  std::string fromReplaceOption(Uint po, Uint jo) const {
1017  return fromOption(tabjrv,tabjrs,tabrv,tabrs,po,jo);
1018  }
1019 
1024  std::string fromCompileOption(Uint po, Uint jo) const {
1025  return fromOption(tabjcv,tabjcs,tabcv,tabcs,po,jo);
1026  }
1027 
1033  ModifierTable& setMatchModifierTable(std::string const& tabs, VecOpt const& tabv){
1034  parseModifierTable(tabjms, tabjmv, tabms, tabmv, tabs, tabv);
1035  return *this;
1036  }
1037 
1043  ModifierTable& setMatchModifierTable(std::string const& tabs, const Uint* tabvp){
1044  if(tabvp) {
1045  VecOpt tabv(tabvp, tabvp + tabs.length());
1046  setMatchModifierTable(tabs, tabv);
1047  } else clearMatchModifierTable();
1048  return *this;
1049  }
1050 
1059  ModifierTable& setMatchModifierTable(const char* tabsp, const Uint* tabvp){
1060  if(tabsp && tabvp) {
1061  std::string tabs(tabsp);
1062  VecOpt tabv(tabvp, tabvp + tabs.length());
1063  setMatchModifierTable(tabs, tabv);
1064  } else clearMatchModifierTable();
1065  return *this;
1066  }
1067 
1073  ModifierTable& setReplaceModifierTable(std::string const& tabs, VecOpt const& tabv){
1074  parseModifierTable(tabjrs, tabjrv, tabrs, tabrv, tabs, tabv);
1075  return *this;
1076  }
1077 
1083  ModifierTable& setReplaceModifierTable(std::string const& tabs, const Uint* tabvp){
1084  if(tabvp) {
1085  VecOpt tabv(tabvp, tabvp + tabs.length());
1086  setReplaceModifierTable(tabs, tabv);
1087  } else clearReplaceModifierTable();
1088  return *this;
1089  }
1090 
1099  ModifierTable& setReplaceModifierTable(const char* tabsp, const Uint* tabvp){
1100  if(tabsp && tabvp) {
1101  std::string tabs(tabsp);
1102  VecOpt tabv(tabvp, tabvp + tabs.length());
1103  setReplaceModifierTable(tabs, tabv);
1104  } else clearReplaceModifierTable();
1105  return *this;
1106  }
1107 
1113  ModifierTable& setCompileModifierTable(std::string const& tabs, VecOpt const& tabv){
1114  parseModifierTable(tabjcs, tabjcv, tabcs, tabcv, tabs, tabv);
1115  return *this;
1116  }
1117 
1123  ModifierTable& setCompileModifierTable(std::string const& tabs, const Uint* tabvp){
1124  if(tabvp) {
1125  VecOpt tabv(tabvp, tabvp + tabs.length());
1126  setCompileModifierTable(tabs, tabv);
1127  } else clearCompileModifierTable();
1128  return *this;
1129  }
1130 
1139  ModifierTable& setCompileModifierTable(const char* tabsp, const Uint* tabvp){
1140  if(tabsp && tabvp) {
1141  std::string tabs(tabsp);
1142  VecOpt tabv(tabvp, tabvp + tabs.length());
1143  setCompileModifierTable(tabs, tabv);
1144  } else clearCompileModifierTable();
1145  return *this;
1146  }
1147 
1151  tabjms = std::string(MOD::MJ_N, MOD::MJ_N + sizeof(MOD::MJ_V)/sizeof(Uint));
1152  tabms = std::string(MOD::M_N, MOD::M_N + sizeof(MOD::M_V)/sizeof(Uint));
1153  tabjmv = VecOpt(MOD::MJ_V, MOD::MJ_V + sizeof(MOD::MJ_V)/sizeof(Uint));
1154  tabmv = VecOpt(MOD::M_V, MOD::M_V + sizeof(MOD::M_V)/sizeof(Uint));
1155  return *this;
1156  }
1157 
1161  tabjrs = std::string(MOD::RJ_N, MOD::RJ_N + sizeof(MOD::RJ_V)/sizeof(Uint));
1162  tabrs = std::string(MOD::R_N, MOD::R_N + sizeof(MOD::R_V)/sizeof(Uint));
1163  tabjrv = VecOpt(MOD::RJ_V, MOD::RJ_V + sizeof(MOD::RJ_V)/sizeof(Uint));
1164  tabrv = VecOpt(MOD::R_V, MOD::R_V + sizeof(MOD::R_V)/sizeof(Uint));
1165  return *this;
1166  }
1167 
1171  tabjcs = std::string(MOD::CJ_N, MOD::CJ_N + sizeof(MOD::CJ_V)/sizeof(Uint));
1172  tabcs = std::string(MOD::C_N, MOD::C_N + sizeof(MOD::C_V)/sizeof(Uint));
1173  tabjcv = VecOpt(MOD::CJ_V, MOD::CJ_V + sizeof(MOD::CJ_V)/sizeof(Uint));
1174  tabcv = VecOpt(MOD::C_V, MOD::C_V + sizeof(MOD::C_V)/sizeof(Uint));
1175  return *this;
1176  }
1177 
1184  return *this;
1185  }
1186 };
1187 
1188 
1189 //These message strings are used for error/warning message construction.
1190 //take care to prevent multiple definition
1191 template<typename Char_T> struct MSG{
1192  static std::basic_string<Char_T> INVALID_MODIFIER(void);
1193  static std::basic_string<Char_T> INSUFFICIENT_OVECTOR(void);
1194 };
1195 //specialization
1196 template<> inline std::basic_string<char> MSG<char>::INVALID_MODIFIER(){ return "Invalid modifier: "; }
1197 template<> inline std::basic_string<wchar_t> MSG<wchar_t>::INVALID_MODIFIER(){ return L"Invalid modifier: "; }
1198 template<> inline std::basic_string<char> MSG<char>::INSUFFICIENT_OVECTOR(){ return "ovector wasn't big enough"; }
1199 template<> inline std::basic_string<wchar_t> MSG<wchar_t>::INSUFFICIENT_OVECTOR(){ return L"ovector wasn't big enough"; }
1200 #if JPCRE2_USE_MINIMUM_CXX_11
1201 template<> inline std::basic_string<char16_t> MSG<char16_t>::INVALID_MODIFIER(){ return u"Invalid modifier: "; }
1202 template<> inline std::basic_string<char32_t> MSG<char32_t>::INVALID_MODIFIER(){ return U"Invalid modifier: "; }
1203 template<> inline std::basic_string<char16_t> MSG<char16_t>::INSUFFICIENT_OVECTOR(){ return u"ovector wasn't big enough"; }
1204 template<> inline std::basic_string<char32_t> MSG<char32_t>::INSUFFICIENT_OVECTOR(){ return U"ovector wasn't big enough"; }
1205 #endif
1206 
1233 #if JPCRE2_USE_MINIMUM_CXX_11
1234 template<typename Char_T, template<typename...> class Map=std::map>
1235 #else
1236 template<typename Char_T>
1237 #endif
1238 struct select{
1239 
1241  typedef Char_T Char;
1242 
1243  //typedef Char_T Char;
1253  typedef typename std::basic_string<Char_T> String;
1254 
1255  #if JPCRE2_USE_MINIMUM_CXX_11
1256  typedef class Map<String, String> MapNas;
1259  typedef class Map<String, SIZE_T> MapNtN;
1260  #else
1261  typedef typename std::map<String, String> MapNas;
1264  typedef typename std::map<String, SIZE_T> MapNtN;
1265  #endif
1266 
1268  typedef MapNtN MapNtn;
1269 
1271  typedef typename std::vector<String> NumSub;
1273  typedef typename std::vector<MapNas> VecNas;
1275  typedef typename std::vector<MapNtN> VecNtN;
1277  typedef VecNtN VecNtn;
1279  typedef typename std::vector<NumSub> VecNum;
1280 
1281  //These are to shorten the code
1282  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::Pcre2Uchar Pcre2Uchar;
1283  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::Pcre2Sptr Pcre2Sptr;
1284  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::Pcre2Code Pcre2Code;
1285  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::CompileContext CompileContext;
1286  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::MatchData MatchData;
1287  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::GeneralContext GeneralContext;
1288  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::MatchContext MatchContext;
1289  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::JitCallback JitCallback;
1290  typedef typename Pcre2Type<sizeof( Char_T ) * CHAR_BIT>::JitStack JitStack;
1291 
1292  template<typename T>
1293  static String toString(T); //prevent implicit type conversion of T
1294 
1298  static String toString(Char a){
1299  return a?String(1, a):String();
1300  }
1301 
1307  static String toString(Char const *a){
1308  return a?String(a):String();
1309  }
1310 
1316  static String toString(Char* a){
1317  return a?String(a):String();
1318  }
1319 
1325  static String toString(Pcre2Uchar* a) {
1326  return a?String((Char*) a):String();
1327  }
1328 
1332  static String getPcre2ErrorMessage(int err_num) {
1333  Pcre2Uchar buffer[sizeof(Char)*CHAR_BIT*1024];
1334  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::get_error_message(err_num, buffer, sizeof(buffer));
1335  return toString((Pcre2Uchar*) buffer);
1336  }
1337 
1342  static String getErrorMessage(int err_num, int err_off) {
1343  if(err_num == (int)ERROR::INVALID_MODIFIER){
1344  return MSG<Char>::INVALID_MODIFIER() + toString((Char)err_off);
1345  } else if(err_num == (int)ERROR::INSUFFICIENT_OVECTOR){
1347  } else if(err_num != 0) {
1348  return getPcre2ErrorMessage((int) err_num);
1349  } else return String();
1350  }
1351 
1352  //forward declaration
1353  class Regex;
1354  class RegexMatch;
1355  class RegexReplace;
1356  class MatchEvaluator;
1357 
1375  class RegexMatch {
1376 
1377  private:
1378 
1379  friend class MatchEvaluator;
1380 
1381  Regex const *re;
1382 
1383  String m_subject;
1384  String const *m_subject_ptr;
1385  Uint match_opts;
1386  Uint jpcre2_match_opts;
1387  MatchContext *mcontext;
1388  ModifierTable const * modtab;
1389  MatchData * mdata;
1390 
1391  PCRE2_SIZE _start_offset; //name collision, use _ at start
1392 
1393  VecNum* vec_num;
1394  VecNas* vec_nas;
1395  VecNtN* vec_ntn;
1396 
1397  VecOff* vec_soff;
1398  VecOff* vec_eoff;
1399 
1400  bool getNumberedSubstrings(int, Pcre2Sptr, PCRE2_SIZE*, uint32_t);
1401 
1402  bool getNamedSubstrings(int, int, Pcre2Sptr, Pcre2Sptr, PCRE2_SIZE*);
1403 
1404  void init_vars() {
1405  re = 0;
1406  vec_num = 0;
1407  vec_nas = 0;
1408  vec_ntn = 0;
1409  vec_soff = 0;
1410  vec_eoff = 0;
1411  match_opts = 0;
1412  jpcre2_match_opts = 0;
1413  error_number = 0;
1414  error_offset = 0;
1415  _start_offset = 0;
1416  m_subject_ptr = &m_subject;
1417  mcontext = 0;
1418  modtab = 0;
1419  mdata = 0;
1420  }
1421 
1422  void onlyCopy(RegexMatch const &rm){
1423  re = rm.re; //only pointer should be copied
1424 
1425  //pointer to subject may point to m_subject or other user data
1426  m_subject_ptr = (rm.m_subject_ptr == &rm.m_subject) ? &m_subject //not &rm.m_subject
1427  : rm.m_subject_ptr;
1428 
1429  //underlying data of vectors are not handled by RegexMatch
1430  //thus it's safe to just copy the pointers.
1431  vec_num = rm.vec_num;
1432  vec_nas = rm.vec_nas;
1433  vec_ntn = rm.vec_ntn;
1434  vec_soff = rm.vec_soff;
1435  vec_eoff = rm.vec_eoff;
1436 
1437  match_opts = rm.match_opts;
1438  jpcre2_match_opts = rm.jpcre2_match_opts;
1439  error_number = rm.error_number;
1440  error_offset = rm.error_offset;
1441  _start_offset = rm._start_offset;
1442  mcontext = rm.mcontext;
1443  modtab = rm.modtab;
1444  mdata = rm.mdata;
1445  }
1446 
1447  void deepCopy(RegexMatch const &rm){
1448  m_subject = rm.m_subject;
1449  onlyCopy(rm);
1450  }
1451 
1452  #if JPCRE2_USE_MINIMUM_CXX_11
1453  void deepMove(RegexMatch& rm){
1454  m_subject = std::move_if_noexcept(rm.m_subject);
1455  onlyCopy(rm);
1456  }
1457  #endif
1458 
1459  friend class Regex;
1460 
1461  protected:
1462 
1463  int error_number;
1464  PCRE2_SIZE error_offset;
1465 
1466  public:
1467 
1470  init_vars();
1471  }
1472 
1478  RegexMatch(Regex const *r) {
1479  init_vars();
1480  re = r;
1481  }
1482 
1488  init_vars();
1489  deepCopy(rm);
1490  }
1491 
1495  virtual RegexMatch& operator=(RegexMatch const &rm){
1496  if(this == &rm) return *this;
1497  deepCopy(rm);
1498  return *this;
1499  }
1500 
1501  #if JPCRE2_USE_MINIMUM_CXX_11
1502  RegexMatch(RegexMatch&& rm){
1510  init_vars();
1511  deepMove(rm);
1512  }
1513 
1523  if(this == &rm) return *this;
1524  deepMove(rm);
1525  return *this;
1526  }
1527  #endif
1528 
1531  virtual ~RegexMatch() {}
1532 
1537  virtual RegexMatch& reset() {
1538  String().swap(m_subject); //not ptr , external string won't be modified.
1539  init_vars();
1540  return *this;
1541  }
1542 
1547  virtual RegexMatch& clear(){
1548  m_subject.clear(); //not ptr , external string won't be modified.
1549  init_vars();
1550  return *this;
1551  }
1552 
1562  error_number = 0;
1563  error_offset = 0;
1564  return *this;
1565  }
1566 
1569  virtual int getErrorNumber() const {
1570  return error_number;
1571  }
1572 
1575  virtual int getErrorOffset() const {
1576  return (int)error_offset;
1577  }
1578 
1581  virtual String getErrorMessage() const {
1582  #if JPCRE2_USE_MINIMUM_CXX_11
1583  return select<Char, Map>::getErrorMessage(error_number, error_offset);
1584  #else
1585  return select<Char>::getErrorMessage(error_number, error_offset);
1586  #endif
1587  }
1588 
1592  virtual String getSubject() const {
1593  return *m_subject_ptr;
1594  }
1595 
1600  virtual String const * getSubjectPointer() const {
1601  return m_subject_ptr;
1602  }
1603 
1604 
1619  virtual std::string getModifier() const {
1620  return modtab ? modtab->fromMatchOption(match_opts, jpcre2_match_opts)
1621  : MOD::fromMatchOption(match_opts, jpcre2_match_opts);
1622  }
1623 
1627  return modtab;
1628  }
1629 
1630 
1635  virtual Uint getPcre2Option() const {
1636  return match_opts;
1637  }
1638 
1643  virtual Uint getJpcre2Option() const {
1644  return jpcre2_match_opts;
1645  }
1646 
1649  virtual PCRE2_SIZE getStartOffset() const {
1650  return _start_offset;
1651  }
1652 
1657  virtual VecOff const* getMatchStartOffsetVector() const {
1658  return vec_soff;
1659  }
1660 
1665  virtual VecOff const* getMatchEndOffsetVector() const {
1666  return vec_eoff;
1667  }
1668 
1672  virtual Regex const * getRegexObject() const {
1673  return re;
1674  }
1675 
1678  virtual VecNum const* getNumberedSubstringVector() const {
1679  return vec_num;
1680  }
1681 
1684  virtual VecNas const* getNamedSubstringVector() const {
1685  return vec_nas;
1686  }
1687 
1690  virtual VecNtN const* getNameToNumberMapVector() const {
1691  return vec_ntn;
1692  }
1693 
1699  virtual RegexMatch& setRegexObject(Regex const *r){
1700  re = r;
1701  return *this;
1702  }
1703 
1711  vec_num = v;
1712  return *this;
1713  }
1714 
1722  vec_nas = v;
1723  return *this;
1724  }
1725 
1733  vec_ntn = v;
1734  return *this;
1735  }
1736 
1743  vec_soff = v;
1744  return *this;
1745  }
1746 
1753  vec_eoff = v;
1754  return *this;
1755  }
1756 
1762  virtual RegexMatch& setSubject(String const &s) {
1763  m_subject = s;
1764  m_subject_ptr = &m_subject; //must overwrite
1765  return *this;
1766  }
1767 
1774  virtual RegexMatch& setSubject(String const *s) {
1775  if(s) m_subject_ptr = s;
1776  else {
1777  m_subject.clear();
1778  m_subject_ptr = &m_subject;
1779  }
1780  return *this;
1781  }
1782 
1783 
1790  virtual RegexMatch& setModifier(Modifier const& s) {
1791  match_opts = 0;
1792  jpcre2_match_opts = 0;
1793  changeModifier(s, true);
1794  return *this;
1795  }
1796 
1801  modtab = mdt;
1802  return *this;
1803  }
1804 
1811  jpcre2_match_opts = x;
1812  return *this;
1813  }
1814 
1821  match_opts = x;
1822  return *this;
1823  }
1824 
1828  virtual RegexMatch& setFindAll(bool x) {
1829  jpcre2_match_opts = x?jpcre2_match_opts | FIND_ALL:jpcre2_match_opts & ~FIND_ALL;
1830  return *this;
1831  }
1832 
1837  virtual RegexMatch& setFindAll() {
1838  return setFindAll(true);
1839  }
1840 
1846  virtual RegexMatch& setStartOffset(PCRE2_SIZE offset) {
1847  _start_offset = offset;
1848  return *this;
1849  }
1850 
1857  virtual RegexMatch& setMatchContext(MatchContext *match_context){
1858  mcontext = match_context;
1859  return *this;
1860  }
1861 
1865  virtual MatchContext* getMatchContext(){
1866  return mcontext;
1867  }
1868 
1874  virtual RegexMatch& setMatchDataBlock(MatchData* madt){
1875  mdata = madt;
1876  return *this;
1877  }
1878 
1882  virtual MatchData* getMatchDataBlock(){
1883  return mdata;
1884  }
1885 
1898  virtual RegexMatch& changeModifier(Modifier const& mod, bool x){
1899  modtab ? modtab->toMatchOption(mod, x, &match_opts, &jpcre2_match_opts, &error_number, &error_offset)
1900  : MOD::toMatchOption(mod, x, &match_opts, &jpcre2_match_opts, &error_number, &error_offset);
1901  return *this;
1902  }
1903 
1910  virtual RegexMatch& changeJpcre2Option(Uint opt, bool x) {
1911  jpcre2_match_opts = x ? jpcre2_match_opts | opt : jpcre2_match_opts & ~opt;
1912  return *this;
1913  }
1914 
1921  virtual RegexMatch& changePcre2Option(Uint opt, bool x) {
1922  match_opts = x ? match_opts | opt : match_opts & ~opt;
1923  return *this;
1924  }
1925 
1932  virtual RegexMatch& addModifier(Modifier const& mod){
1933  return changeModifier(mod, true);
1934  }
1935 
1942  jpcre2_match_opts |= x;
1943  return *this;
1944  }
1945 
1952  match_opts |= x;
1953  return *this;
1954  }
1955 
1956 
1962  virtual SIZE_T match(void);
1963  };
1964 
1965 
1998  template<typename T1, typename T2, typename T3>
2000  #if !defined JPCRE2_USE_FUNCTION_POINTER_CALLBACK && JPCRE2_USE_MINIMUM_CXX_11
2001  typedef std::function<String (T1,T2,T3)> Callback;
2002  #else
2003  typedef String (*Callback)(T1,T2,T3);
2004  #endif
2005  };
2006 
2012  struct callback{
2022  static String eraseFill(NumSub const &num, MapNas const &nas, MapNtN const &ntn){
2023  return String();
2024  }
2025 
2036  static String erase(void*, void*, void*){
2037  return String();
2038  }
2039 
2046  static String fill(NumSub const &num, MapNas const &nas, MapNtn const &ntn){
2047  return num[0];
2048  }
2049 
2050  private:
2051  //prevent object instantiation.
2052  callback();
2053  callback(callback const &);
2054  #if JPCRE2_USE_MINIMUM_CXX_11
2055  callback(callback&&);
2056  #endif
2057  ~callback();
2058  };
2059 
2135  class MatchEvaluator: virtual public RegexMatch{
2136  private:
2137  friend class RegexReplace;
2138 
2139  VecNum vec_num;
2140  VecNas vec_nas;
2141  VecNtN vec_ntn;
2142  VecOff vec_soff;
2143  VecOff vec_eoff;
2144  int callbackn;
2153  //Q: Why the callback names seem random? is it random?
2154  //A: No, it's not random, NumSub = 1, MapNas = 2, MapNtn = 4, thus:
2155  // NumSub + MapNas = 3
2156  // NumSub + MapNtn = 5
2157  // MapNas + MapNtn = 6
2158  // NumSub + MapNas + MapNtn = 7
2159  //Q: Why is it like this?
2160  //A: It's historical. Once, there was not this many callback declaration, there was only one (a templated one).
2161  // The nreplace function itself used to calculate a mode value according to available vectors
2162  // and determine what kind of callback function needed to be called.
2163  //Q: Why the history changed?
2164  //A: We had some compatibility issues with the single templated callback.
2165  // Also, this approach proved to be more readable and robust.
2166 
2167  PCRE2_SIZE buffer_size;
2168 
2169 
2170  void init(){
2171  callbackn = 0;
2172  callback0 = callback::erase;
2173  callback1 = 0;
2174  callback2 = 0;
2175  callback3 = 0;
2176  callback4 = 0;
2177  callback5 = 0;
2178  callback6 = 0;
2179  callback7 = 0;
2180  setMatchStartOffsetVector(&vec_soff);
2181  setMatchEndOffsetVector(&vec_eoff);
2182  buffer_size = 0;
2183  }
2184 
2185  void setVectorPointersAccordingToCallback(){
2186  switch(callbackn){
2187  case 0: break;
2188  case 1: setNumberedSubstringVector(&vec_num);break;
2189  case 2: setNamedSubstringVector(&vec_nas);break;
2190  case 3: setNumberedSubstringVector(&vec_num).setNamedSubstringVector(&vec_nas);break;
2191  case 4: setNameToNumberMapVector(&vec_ntn);break;
2192  case 5: setNumberedSubstringVector(&vec_num).setNameToNumberMapVector(&vec_ntn);break;
2193  case 6: setNamedSubstringVector(&vec_nas).setNameToNumberMapVector(&vec_ntn);break;
2194  case 7: setNumberedSubstringVector(&vec_num).setNamedSubstringVector(&vec_nas).setNameToNumberMapVector(&vec_ntn);break;
2195  }
2196  }
2197 
2198  void onlyCopy(MatchEvaluator const &me){
2199  callbackn = me.callbackn;
2200  callback0 = me.callback0;
2201  callback1 = me.callback1;
2202  callback2 = me.callback2;
2203  callback3 = me.callback3;
2204  callback4 = me.callback4;
2205  callback5 = me.callback5;
2206  callback6 = me.callback6;
2207  callback7 = me.callback7;
2208  //must update the pointers to point to this class vectors.
2209  setVectorPointersAccordingToCallback();
2210  buffer_size = me.buffer_size;
2211  }
2212 
2213  void deepCopy(MatchEvaluator const &me) {
2214  vec_num = me.vec_num;
2215  vec_nas = me.vec_nas;
2216  vec_ntn = me.vec_ntn;
2217  vec_soff = me.vec_soff;
2218  vec_eoff = me.vec_eoff;
2219  onlyCopy(me);
2220  }
2221 
2222  #if JPCRE2_USE_MINIMUM_CXX_11
2223  void deepMove(MatchEvaluator& me){
2224  vec_num = std::move_if_noexcept(me.vec_num);
2225  vec_nas = std::move_if_noexcept(me.vec_nas);
2226  vec_ntn = std::move_if_noexcept(me.vec_ntn);
2227  vec_soff = std::move_if_noexcept(me.vec_soff);
2228  vec_eoff = std::move_if_noexcept(me.vec_eoff);
2229  onlyCopy(me);
2230  }
2231  #endif
2232 
2233  //prevent public access to some funcitons
2234  MatchEvaluator& setNumberedSubstringVector(VecNum* v){
2236  return *this;
2237  }
2238  MatchEvaluator& setNamedSubstringVector(VecNas* v){
2240  return *this;
2241  }
2242  MatchEvaluator& setNameToNumberMapVector(VecNtN* v){
2244  return *this;
2245  }
2246  MatchEvaluator& setMatchStartOffsetVector(VecOff* v){
2248  return *this;
2249  }
2250  MatchEvaluator& setMatchEndOffsetVector(VecOff* v){
2252  return *this;
2253  }
2254 
2255  public:
2256 
2271  explicit
2273  init();
2274  }
2275 
2284  explicit
2286  init();
2287  }
2288 
2294  explicit
2296  init();
2297  setCallback(mef);
2298  }
2299 
2304  explicit
2306  init();
2307  setCallback(mef);
2308  }
2309 
2314  explicit
2316  init();
2317  setCallback(mef);
2318  }
2319 
2324  explicit
2326  init();
2327  setCallback(mef);
2328  }
2329 
2334  explicit
2336  init();
2337  setCallback(mef);
2338  }
2339 
2344  explicit
2346  init();
2347  setCallback(mef);
2348  }
2349 
2350 
2355  explicit
2357  init();
2358  setCallback(mef);
2359  }
2360 
2361 
2362 
2367  explicit
2369  init();
2370  setCallback(mef);
2371  }
2372 
2373 
2374 
2380  init();
2381  deepCopy(me);
2382  }
2383 
2388  if(this == &me) return *this;
2390  deepCopy(me);
2391  return *this;
2392  }
2393 
2394  #if JPCRE2_USE_MINIMUM_CXX_11
2395 
2404  init();
2405  deepMove(me);
2406  }
2407 
2418  if(this == &me) return *this;
2420  deepMove(me);
2421  return *this;
2422  }
2423 
2424  #endif
2425 
2426  virtual ~MatchEvaluator(){}
2427 
2435  callback0 = mef;
2436  callbackn = 0;
2437  return *this;
2438  }
2439 
2447  callback1 = mef;
2448  callbackn = 1;
2449  setNumberedSubstringVector(&vec_num);
2450  return *this;
2451  }
2452 
2470  callback3 = mef;
2471  callbackn = 3;
2472  setNumberedSubstringVector(&vec_num);
2473  setNamedSubstringVector(&vec_nas);
2474  return *this;
2475  }
2476 
2494  callback5 = mef;
2495  callbackn = 5;
2496  setNumberedSubstringVector(&vec_num);
2497  setNameToNumberMapVector(&vec_ntn);
2498  return *this;
2499  }
2500 
2501 
2519  callback7 = mef;
2520  callbackn = 7;
2521  setNumberedSubstringVector(&vec_num);
2522  setNamedSubstringVector(&vec_nas);
2523  setNameToNumberMapVector(&vec_ntn);
2524  return *this;
2525  }
2526 
2544  callback2 = mef;
2545  callbackn = 2;
2546  setNamedSubstringVector(&vec_nas);
2547  return *this;
2548  }
2549 
2567  callback6 = mef;
2568  callbackn = 6;
2569  setNamedSubstringVector(&vec_nas);
2570  setNameToNumberMapVector(&vec_ntn);
2571  return *this;
2572  }
2573 
2591  callback4 = mef;
2592  callbackn = 4;
2593  setNameToNumberMapVector(&vec_ntn);
2594  return *this;
2595  }
2596 
2603  vec_num.clear();
2604  vec_nas.clear();
2605  vec_ntn.clear();
2606  vec_soff.clear();
2607  vec_eoff.clear();
2608  return *this;
2609  }
2610 
2616  VecNum().swap(vec_num);
2617  VecNas().swap(vec_nas);
2618  VecNtN().swap(vec_ntn);
2619  VecOff().swap(vec_soff);
2620  VecOff().swap(vec_eoff);
2621  return *this;
2622  }
2623 
2624 
2629  resetMatchData();
2630  init();
2631  return *this;
2632  }
2633 
2639  clearMatchData();
2640  init();
2641  return *this;
2642  }
2643 
2648  return *this;
2649  }
2650 
2656  return *this;
2657  }
2658 
2664  return *this;
2665  }
2666 
2672  return *this;
2673  }
2674 
2680  return *this;
2681  }
2682 
2688  return *this;
2689  }
2690 
2696  return *this;
2697  }
2698 
2704  return *this;
2705  }
2706 
2712  return *this;
2713  }
2714 
2719  return *this;
2720  }
2721 
2725  MatchEvaluator& setStartOffset (PCRE2_SIZE offset){
2727  return *this;
2728  }
2729 
2733  MatchEvaluator& setMatchContext (MatchContext *match_context){
2734  RegexMatch::setMatchContext(match_context);
2735  return *this;
2736  }
2737 
2743  return *this;
2744  }
2745 
2753  buffer_size = x;
2754  return *this;
2755  }
2756 
2759  PCRE2_SIZE getBufferSize(){
2760  return buffer_size;
2761  }
2762 
2767  MatchEvaluator& changeModifier (Modifier const& mod, bool x){
2769  return *this;
2770  }
2771 
2778  return *this;
2779  }
2780 
2787  return *this;
2788  }
2789 
2795  return *this;
2796  }
2797 
2803  return *this;
2804  }
2805 
2811  return *this;
2812  }
2813 
2819  SIZE_T match(void){
2820  //remove bad matching options
2821  RegexMatch::changePcre2Option(PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT, false);
2822  return RegexMatch::match();
2823  }
2824 
2849  String nreplace(bool do_match=true, Uint jro=0, SIZE_T* counter=0);
2850 
2870  String replace(bool do_match=true, Uint ro=0, SIZE_T* counter=0);
2871  };
2872 
2891 
2892  private:
2893 
2894  friend class Regex;
2895 
2896  Regex const *re;
2897 
2898  String r_subject;
2899  String *r_subject_ptr; //preplace method modifies it in-place
2900  String r_replw;
2901  String const *r_replw_ptr;
2902  Uint replace_opts;
2903  Uint jpcre2_replace_opts;
2904  PCRE2_SIZE buffer_size;
2905  PCRE2_SIZE _start_offset;
2906  MatchData *mdata;
2907  MatchContext *mcontext;
2908  ModifierTable const * modtab;
2909  SIZE_T last_replace_count;
2910  SIZE_T* last_replace_counter;
2911 
2912  void init_vars() {
2913  re = 0;
2914  r_subject_ptr = &r_subject;
2915  r_replw_ptr = &r_replw;
2916  replace_opts = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH;
2917  jpcre2_replace_opts = 0;
2918  buffer_size = 0;
2919  error_number = 0;
2920  error_offset = 0;
2921  _start_offset = 0;
2922  mdata = 0;
2923  mcontext = 0;
2924  modtab = 0;
2925  last_replace_count = 0;
2926  last_replace_counter = &last_replace_count;
2927  }
2928 
2929  void onlyCopy(RegexReplace const &rr){
2930  re = rr.re; //only pointer should be copied.
2931 
2932  //rr.r_subject_ptr may point to rr.r_subject or other user data
2933  r_subject_ptr = (rr.r_subject_ptr == &rr.r_subject) ? &r_subject //not rr.r_subject
2934  : rr.r_subject_ptr; //other user data
2935 
2936  r_replw = rr.r_replw;
2937  //rr.r_replw_ptr may point to rr.r_replw or other user data
2938  r_replw_ptr = (rr.r_replw_ptr == &rr.r_replw) ? &r_replw //not rr.r_replw
2939  : rr.r_replw_ptr; //other user data
2940 
2941  replace_opts = rr.replace_opts;
2942  jpcre2_replace_opts = rr.jpcre2_replace_opts;
2943  buffer_size = rr.buffer_size;
2944  error_number = rr.error_number;
2945  error_offset = rr.error_offset;
2946  _start_offset = rr._start_offset;
2947  mdata = rr.mdata;
2948  mcontext = rr.mcontext;
2949  modtab = rr.modtab;
2950  last_replace_count = rr.last_replace_count;
2951  last_replace_counter = (rr.last_replace_counter == &rr.last_replace_count) ? &last_replace_count
2952  : rr.last_replace_counter;
2953  }
2954 
2955  void deepCopy(RegexReplace const &rr){
2956  r_subject = rr.r_subject;
2957  onlyCopy(rr);
2958  }
2959 
2960  #if JPCRE2_USE_MINIMUM_CXX_11
2961  void deepMove(RegexReplace& rr){
2962  r_subject = std::move_if_noexcept(rr.r_subject);
2963  onlyCopy(rr);
2964  }
2965  #endif
2966 
2967 
2968  protected:
2969 
2970  int error_number;
2971  PCRE2_SIZE error_offset;
2972 
2973  public:
2974 
2977  init_vars();
2978  }
2979 
2985  RegexReplace(Regex const *r) {
2986  init_vars();
2987  re = r;
2988  }
2989 
2995  init_vars();
2996  deepCopy(rr);
2997  }
2998 
3003  if(this == &rr) return *this;
3004  deepCopy(rr);
3005  return *this;
3006  }
3007 
3008  #if JPCRE2_USE_MINIMUM_CXX_11
3009 
3018  init_vars();
3019  deepMove(rr);
3020  }
3021 
3031  if(this == &rr) return *this;
3032  deepMove(rr);
3033  return *this;
3034  }
3035 
3036  #endif
3037 
3038  virtual ~RegexReplace() {}
3039 
3043  String().swap(r_subject);
3044  String().swap(r_replw);
3045  init_vars();
3046  return *this;
3047  }
3048 
3052  r_subject.clear();
3053  r_replw.clear();
3054  init_vars();
3055  return *this;
3056  }
3057 
3063  error_number = 0;
3064  error_offset = 0;
3065  return *this;
3066  }
3067 
3070  int getErrorNumber() const {
3071  return error_number;
3072  }
3073 
3076  int getErrorOffset() const {
3077  return (int)error_offset;
3078  }
3079 
3083  #if JPCRE2_USE_MINIMUM_CXX_11
3084  return select<Char, Map>::getErrorMessage(error_number, error_offset);
3085  #else
3086  return select<Char>::getErrorMessage(error_number, error_offset);
3087  #endif
3088  }
3089 
3093  return *r_replw_ptr;
3094  }
3095 
3098  String const * getReplaceWithPointer() const {
3099  return r_replw_ptr;
3100  }
3101 
3105  String getSubject() const {
3106  return *r_subject_ptr;
3107  }
3108 
3112  String const * getSubjectPointer() const {
3113  return r_subject_ptr;
3114  }
3115 
3116 
3131  std::string getModifier() const {
3132  return modtab ? modtab->fromReplaceOption(replace_opts, jpcre2_replace_opts)
3133  : MOD::fromReplaceOption(replace_opts, jpcre2_replace_opts);
3134  }
3135 
3139  return modtab;
3140  }
3141 
3144  PCRE2_SIZE getStartOffset() const {
3145  return _start_offset;
3146  }
3147 
3153  return replace_opts;
3154  }
3155 
3161  return jpcre2_replace_opts;
3162  }
3163 
3167  Regex const * getRegexObject() const {
3168  return re;
3169  }
3170 
3174  MatchContext* getMatchContext(){
3175  return mcontext;
3176  }
3177 
3181  virtual MatchData* getMatchDataBlock(){
3182  return mdata;
3183  }
3184 
3187  PCRE2_SIZE getBufferSize(){
3188  return buffer_size;
3189  }
3190 
3197  return *last_replace_counter;
3198  }
3199 
3207  last_replace_count = 0;
3208  last_replace_counter = counter ? counter : &last_replace_count;
3209  return *this;
3210  }
3211 
3217  re = r;
3218  return *this;
3219  }
3220 
3228  r_subject = s;
3229  r_subject_ptr = &r_subject; //must overwrite
3230  return *this;
3231  }
3232 
3241  if(s) r_subject_ptr = s;
3242  else {
3243  r_subject.clear();
3244  r_subject_ptr = &r_subject;
3245  }
3246  return *this;
3247  }
3248 
3262  r_replw = s;
3263  r_replw_ptr = &r_replw; //must overwrite
3264  return *this;
3265  }
3266 
3272  if(s) r_replw_ptr = s;
3273  else {
3274  r_replw.clear();
3275  r_replw_ptr = &r_replw;
3276  }
3277  return *this;
3278  }
3279 
3286  replace_opts = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH; /* must not be initialized to 0 */
3287  jpcre2_replace_opts = 0;
3288  return changeModifier(s, true);
3289  }
3290 
3295  modtab = mdt;
3296  return *this;
3297  }
3298 
3302  RegexReplace& setBufferSize(PCRE2_SIZE x) {
3303  buffer_size = x;
3304  return *this;
3305  }
3306 
3311  RegexReplace& setStartOffset(PCRE2_SIZE start_offset){
3312  _start_offset = start_offset;
3313  return *this;
3314  }
3315 
3321 
3323  jpcre2_replace_opts = x;
3324  return *this;
3325  }
3326 
3332 
3334  replace_opts = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH | x;
3335  return *this;
3336  }
3337 
3344  RegexReplace& setMatchContext(MatchContext * match_context){
3345  mcontext = match_context;
3346  return *this;
3347  }
3348 
3355  RegexReplace& setMatchDataBlock(MatchData *match_data){
3356  mdata = match_data;
3357  return *this;
3358  }
3359 
3372  RegexReplace& changeModifier(Modifier const& mod, bool x){
3373  modtab ? modtab->toReplaceOption(mod, x, &replace_opts, &jpcre2_replace_opts, &error_number, &error_offset)
3374  : MOD::toReplaceOption(mod, x, &replace_opts, &jpcre2_replace_opts, &error_number, &error_offset);
3375  return *this;
3376  }
3377 
3386  jpcre2_replace_opts = x ? jpcre2_replace_opts | opt : jpcre2_replace_opts & ~opt;
3387  return *this;
3388  }
3389 
3397  replace_opts = x ? replace_opts | opt : replace_opts & ~opt;
3398  //replace_opts |= PCRE2_SUBSTITUTE_OVERFLOW_LENGTH; /* It's important, but let user override it. */
3399  return *this;
3400  }
3401 
3410  return changeModifier(mod, true);
3411  }
3412 
3419  jpcre2_replace_opts |= x;
3420  return *this;
3421  }
3422 
3429  replace_opts |= x;
3430  return *this;
3431  }
3432 
3444  String replace(void);
3445 
3452  *r_subject_ptr = replace();
3453  return *last_replace_counter;
3454  }
3455 
3467  *r_subject_ptr = me.setRegexObject(getRegexObject())
3468  .setSubject(r_subject_ptr) //do not use method
3469  .setFindAll((getPcre2Option() & PCRE2_SUBSTITUTE_GLOBAL)!=0)
3470  .setMatchContext(getMatchContext())
3471  .setMatchDataBlock(getMatchDataBlock())
3472  .setBufferSize(getBufferSize())
3473  .setStartOffset(getStartOffset())
3474  .replace(true, getPcre2Option(), last_replace_counter);
3475  return *last_replace_counter;
3476  }
3477 
3506  return me.setRegexObject(getRegexObject())
3507  .setSubject(getSubjectPointer())
3508  .setFindAll((getPcre2Option() & PCRE2_SUBSTITUTE_GLOBAL)!=0)
3509  .setMatchContext(getMatchContext())
3510  .setMatchDataBlock(getMatchDataBlock())
3511  .setStartOffset(getStartOffset())
3512  .nreplace(true, getJpcre2Option(), last_replace_counter);
3513  }
3514 
3524  return me.setRegexObject(getRegexObject())
3525  .setSubject(getSubjectPointer())
3526  .setFindAll((getPcre2Option() & PCRE2_SUBSTITUTE_GLOBAL)!=0)
3527  .setMatchContext(getMatchContext())
3528  .setMatchDataBlock(getMatchDataBlock())
3529  .setBufferSize(getBufferSize())
3530  .setStartOffset(getStartOffset())
3531  .replace(true, getPcre2Option(), last_replace_counter);
3532  }
3533  };
3534 
3535 
3550  class Regex {
3551 
3552  private:
3553 
3554  friend class RegexMatch;
3555  friend class RegexReplace;
3556  friend class MatchEvaluator;
3557 
3558  String pat_str;
3559  String const *pat_str_ptr;
3560  Pcre2Code *code;
3561  Uint compile_opts;
3562  Uint jpcre2_compile_opts;
3563  ModifierTable const * modtab;
3564 
3565  CompileContext *ccontext;
3566  std::vector<unsigned char> tabv;
3567 
3568 
3569  void init_vars() {
3570  jpcre2_compile_opts = 0;
3571  compile_opts = 0;
3572  error_number = 0;
3573  error_offset = 0;
3574  code = 0;
3575  pat_str_ptr = &pat_str;
3576  ccontext = 0;
3577  modtab = 0;
3578  }
3579 
3580  void freeRegexMemory(void) {
3581  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::code_free(code);
3582  code = 0; //we may use it again
3583  }
3584 
3585  void freeCompileContext(){
3586  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::compile_context_free(ccontext);
3587  ccontext = 0;
3588  }
3589 
3590  void onlyCopy(Regex const &r){
3591  //r.pat_str_ptr may point to other user data
3592  pat_str_ptr = (r.pat_str_ptr == &r.pat_str) ? &pat_str //not r.pat_str
3593  : r.pat_str_ptr; //other user data
3594 
3595  compile_opts = r.compile_opts;
3596  jpcre2_compile_opts = r.jpcre2_compile_opts;
3597  error_number = r.error_number;
3598  error_offset = r.error_offset;
3599  modtab = r.modtab;
3600  }
3601 
3602  void deepCopy(Regex const &r) {
3603  pat_str = r.pat_str; //must not use setPattern() here
3604 
3605  onlyCopy(r);
3606 
3607  //copy tables
3608  tabv = r.tabv;
3609  //copy ccontext if it's not null
3610  freeCompileContext();
3611  ccontext = (r.ccontext) ? Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::compile_context_copy(r.ccontext) : 0;
3612  //if tabv is not empty and ccontext is ok (not null) set the table pointer to ccontext
3613  if(ccontext && !tabv.empty()) Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::set_character_tables(ccontext, &tabv[0]);
3614 
3615  //table pointer must be updated in the compiled code itself, jit memory copy is not available.
3616  //copy is not going to work, we need a recompile.
3617  //as all vars are already copied, we can just call compile()
3618  r.code ? compile() //compile frees previous memory.
3619  : freeRegexMemory();
3620  }
3621 
3622  #if JPCRE2_USE_MINIMUM_CXX_11
3623 
3624  void deepMove(Regex& r) {
3625  pat_str = std::move_if_noexcept(r.pat_str);
3626 
3627  onlyCopy(r);
3628 
3629  //steal tables
3630  tabv = std::move_if_noexcept(r.tabv);
3631 
3632  //steal ccontext
3633  freeCompileContext();
3634  ccontext = r.ccontext; r.ccontext = 0; //must set this to 0
3635  if(ccontext && !tabv.empty()) Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::set_character_tables(ccontext, &tabv[0]);
3636 
3637  //steal the code
3638  freeRegexMemory();
3639  code = r.code; r.code = 0; //must set this to 0
3640  }
3641 
3642  #endif
3643 
3644  protected:
3645 
3646  int error_number;
3647  PCRE2_SIZE error_offset;
3648 
3649  public:
3650 
3654  Regex() {
3655  init_vars();
3656  }
3657 
3660  Regex(String const &re) {
3661  init_vars();
3662  compile(re);
3663  }
3664 
3667  Regex(String const *re) {
3668  init_vars();
3669  compile(re);
3670  }
3671 
3675  Regex(String const &re, Modifier const& mod) {
3676  init_vars();
3677  compile(re, mod);
3678  }
3679 
3683  Regex(String const *re, Modifier const& mod) {
3684  init_vars();
3685  compile(re, mod);
3686  }
3687 
3691  Regex(String const &re, Uint po) {
3692  init_vars();
3693  compile(re, po);
3694  }
3695 
3699  Regex(String const *re, Uint po) {
3700  init_vars();
3701  compile(re, po);
3702  }
3703 
3708  Regex(String const &re, Uint po, Uint jo) {
3709  init_vars();
3710  compile(re, po, jo);
3711  }
3712 
3717  Regex(String const *re, Uint po, Uint jo) {
3718  init_vars();
3719  compile(re, po, jo);
3720  }
3721 
3728  Regex(Regex const &r) {
3729  init_vars();
3730  deepCopy(r);
3731  }
3732 
3736  Regex& operator=(Regex const &r) {
3737  if (this == &r) return *this;
3738  deepCopy(r);
3739  return *this;
3740  }
3741 
3742 
3743  #if JPCRE2_USE_MINIMUM_CXX_11
3744 
3745 
3753  Regex(Regex&& r) {
3754  init_vars();
3755  deepMove(r);
3756  }
3757 
3767  if (this == &r) return *this;
3768  deepMove(r);
3769  return *this;
3770  }
3771 
3794  explicit operator bool() const {
3795  return (code != 0);
3796  }
3797  #endif
3798 
3824  bool operator!() const {
3825  return (code == 0);
3826  }
3827 
3828  virtual ~Regex() {
3829  freeRegexMemory();
3830  freeCompileContext();
3831  }
3832 
3836  freeRegexMemory();
3837  freeCompileContext();
3838  String().swap(pat_str);
3839  init_vars();
3840  return *this;
3841  }
3842 
3846  freeRegexMemory();
3847  freeCompileContext();
3848  pat_str.clear();
3849  init_vars();
3850  return *this;
3851  }
3852 
3858  error_number = 0;
3859  error_offset = 0;
3860  return *this;
3861  }
3862 
3871  const unsigned char* tables = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::maketables(0); //must pass 0, we are using free() to free the tables.
3872  tabv = std::vector<unsigned char>(tables, tables+1088);
3873  ::free((void*)tables); //must free memory
3874  if(!ccontext)
3875  ccontext = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::compile_context_create(0);
3876  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::set_character_tables(ccontext, &tabv[0]);
3877  return *this;
3878  }
3879 
3882  Pcre2Code const* getPcre2Code() const{
3883  return code;
3884  }
3885 
3888  String getPattern() const {
3889  return *pat_str_ptr;
3890  }
3891 
3894  String const * getPatternPointer() const {
3895  return pat_str_ptr;
3896  }
3897 
3898 
3911  std::string getModifier() const {
3912  return modtab ? modtab->fromCompileOption(compile_opts, jpcre2_compile_opts)
3913  : MOD::fromCompileOption(compile_opts, jpcre2_compile_opts);
3914  }
3915 
3921  return compile_opts;
3922  }
3923 
3929  return jpcre2_compile_opts;
3930  }
3931 
3934  int getErrorNumber() const {
3935  return error_number;
3936  }
3937 
3940  int getErrorOffset() const {
3941  return (int)error_offset;
3942  }
3943 
3947  #if JPCRE2_USE_MINIMUM_CXX_11
3948  return select<Char, Map>::getErrorMessage(error_number, error_offset);
3949  #else
3950  return select<Char>::getErrorMessage(error_number, error_offset);
3951  #endif
3952  }
3953 
3964  if(!code) return 0;
3965  Uint newline = 0;
3966  int ret = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::pattern_info(code, PCRE2_INFO_NEWLINE, &newline);
3967  if(ret < 0) error_number = ret;
3968  return newline;
3969  }
3970 
3974  return modtab;
3975  }
3976 
3977 
3989  if(!ccontext)
3990  ccontext = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::compile_context_create(0);
3991  int ret = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::set_newline(ccontext, value);
3992  if(ret < 0) error_number = ret;
3993  return *this;
3994  }
3995 
3999  Regex& setPattern(String const &re) {
4000  pat_str = re;
4001  pat_str_ptr = &pat_str; //must overwrite
4002  return *this;
4003  }
4004 
4008  Regex& setPattern(String const *re) {
4009  if(re) pat_str_ptr = re;
4010  else {
4011  pat_str.clear();
4012  pat_str_ptr = &pat_str;
4013  }
4014  return *this;
4015  }
4016 
4025  compile_opts = 0;
4026  jpcre2_compile_opts = 0;
4027  return changeModifier(x, true);
4028  }
4029 
4034  modtab = mdt;
4035  return *this;
4036  }
4037 
4044  jpcre2_compile_opts = x;
4045  return *this;
4046  }
4047 
4054  compile_opts = x;
4055  return *this;
4056  }
4057 
4070  Regex& changeModifier(Modifier const& mod, bool x){
4071  modtab ? modtab->toCompileOption(mod, x, &compile_opts, &jpcre2_compile_opts, &error_number, &error_offset)
4072  : MOD::toCompileOption(mod, x, &compile_opts, &jpcre2_compile_opts, &error_number, &error_offset);
4073  return *this;
4074  }
4075 
4083  jpcre2_compile_opts = x ? jpcre2_compile_opts | opt : jpcre2_compile_opts & ~opt;
4084  return *this;
4085  }
4086 
4093  Regex& changePcre2Option(Uint opt, bool x) {
4094  compile_opts = x ? compile_opts | opt : compile_opts & ~opt;
4095  return *this;
4096  }
4097 
4106  return changeModifier(mod, true);
4107  }
4108 
4115  jpcre2_compile_opts |= x;
4116  return *this;
4117  }
4118 
4125  compile_opts |= x;
4126  return *this;
4127  }
4128 
4134  void compile(void);
4135 
4142  void compile(String const &re, Uint po, Uint jo) {
4144  compile();
4145  }
4146 
4147 
4152  void compile(String const *re, Uint po, Uint jo) {
4154  compile();
4155  }
4156 
4160  void compile(String const &re, Uint po) {
4161  setPattern(re).setPcre2Option(po);
4162  compile();
4163  }
4164 
4168  void compile(String const *re, Uint po) {
4169  setPattern(re).setPcre2Option(po);
4170  compile();
4171  }
4172 
4176  void compile(String const &re, Modifier const& mod) {
4177  setPattern(re).setModifier(mod);
4178  compile();
4179  }
4180 
4184  void compile(String const *re, Modifier const& mod) {
4185  setPattern(re).setModifier(mod);
4186  compile();
4187  }
4188 
4191  void compile(String const &re) {
4192  setPattern(re);
4193  compile();
4194  }
4195 
4198  void compile(String const *re) {
4199  setPattern(re);
4200  compile();
4201  }
4202 
4208  RegexMatch rm(this);
4209  rm.setModifierTable(modtab);
4210  return rm;
4211  }
4212 
4216  return initMatch();
4217  }
4218 
4227  SIZE_T match(String const &s, Modifier const& mod, PCRE2_SIZE start_offset=0) {
4228  return initMatch().setStartOffset(start_offset).setSubject(s).setModifier(mod).match();
4229  }
4230 
4237  SIZE_T match(String const *s, Modifier const& mod, PCRE2_SIZE start_offset=0) {
4238  return initMatch().setStartOffset(start_offset).setSubject(s).setModifier(mod).match();
4239  }
4240 
4247  SIZE_T match(String const &s, PCRE2_SIZE start_offset=0) {
4248  return initMatch().setStartOffset(start_offset).setSubject(s).match();
4249  }
4250 
4257  SIZE_T match(String const *s, PCRE2_SIZE start_offset=0) {
4258  return initMatch().setStartOffset(start_offset).setSubject(s).match();
4259  }
4260 
4265  RegexReplace rr(this);
4266  rr.setModifierTable(modtab);
4267  return rr;
4268  }
4269 
4273  return initReplace();
4274  }
4275 
4285  String replace(String const &mains, String const &repl, Modifier const& mod="", SIZE_T* counter=0) {
4286  return initReplace().setSubject(mains).setReplaceWith(repl).setModifier(mod).setReplaceCounter(counter).replace();
4287  }
4288 
4296  String replace(String *mains, String const &repl, Modifier const& mod="", SIZE_T* counter=0) {
4297  return initReplace().setSubject(mains).setReplaceWith(repl).setModifier(mod).setReplaceCounter(counter).replace();
4298  }
4299 
4308  String replace(String const &mains, String const *repl, Modifier const& mod="", SIZE_T* counter=0) {
4309  return initReplace().setSubject(mains).setReplaceWith(repl).setModifier(mod).setReplaceCounter(counter).replace();
4310  }
4311 
4320  String replace(String *mains, String const *repl, Modifier const& mod="", SIZE_T* counter=0) {
4321  return initReplace().setSubject(mains).setReplaceWith(repl).setModifier(mod).setReplaceCounter(counter).replace();
4322  }
4323 
4332  SIZE_T preplace(String * mains, String const& repl, Modifier const& mod=""){
4333  SIZE_T counter = 0;
4334  if(mains) *mains = initReplace().setSubject(mains).setReplaceWith(repl).setModifier(mod).setReplaceCounter(&counter).replace();
4335  return counter;
4336  }
4337 
4348  SIZE_T preplace(String * mains, String const* repl, Modifier const& mod=""){
4349  SIZE_T counter = 0;
4350  if(mains) *mains = initReplace().setSubject(mains).setReplaceWith(repl).setModifier(mod).setReplaceCounter(&counter).replace();
4351  return counter;
4352  }
4353 
4364  SIZE_T preplace(String const& mains, String const& repl, Modifier const& mod=""){
4365  SIZE_T counter = 0;
4367  return counter;
4368  }
4369 
4380  SIZE_T preplace(String const& mains, String const* repl, Modifier const& mod=""){
4381  SIZE_T counter = 0;
4383  return counter;
4384  }
4385  };
4386 
4387  private:
4388  //prevent object instantiation of select class
4389  select();
4390  select(select const &);
4391  #if JPCRE2_USE_MINIMUM_CXX_11
4392  select(select&&);
4393  #endif
4394  ~select();
4395 };//struct select
4396 }//jpcre2 namespace
4397 
4398 
4399 inline void jpcre2::ModifierTable::parseModifierTable(std::string& tabjs, VecOpt& tabjv,
4400  std::string& tab_s, VecOpt& tab_v,
4401  std::string const& tabs, VecOpt const& tabv){
4402  SIZE_T n = tabs.length();
4403  JPCRE2_ASSERT(n == tabv.size(), ("ValueError: Could not set Modifier table.\
4404  Modifier character and value tables are not of the same size (" + _tostdstring(n) + " == " + _tostdstring(tabv.size()) + ").").c_str());
4405  tabjs.clear();
4406  tab_s.clear(); tab_s.reserve(n);
4407  tabjv.clear();
4408  tab_v.clear(); tab_v.reserve(n);
4409  for(SIZE_T i=0;i<n;++i){
4410  switch(tabv[i]){
4411  case JIT_COMPILE:
4412  case FIND_ALL: //JPCRE2 options are unique, so it's not necessary to check if it's compile or replace or match.
4413  tabjs.push_back(tabs[i]); tabjv.push_back(tabv[i]);break;
4414  default: tab_s.push_back(tabs[i]); tab_v.push_back(tabv[i]); break;
4415  }
4416  }
4417 }
4418 
4419 
4420 #if JPCRE2_USE_MINIMUM_CXX_11
4421 template<typename Char_T, template<typename...> class Map>
4423 #else
4424 template<typename Char_T>
4426 #endif
4427  //Get c_str of pattern
4428  Pcre2Sptr c_pattern = (Pcre2Sptr) pat_str_ptr->c_str();
4429  int err_number = 0;
4430  PCRE2_SIZE err_offset = 0;
4431 
4432  /**************************************************************************
4433  * Compile the regular expression pattern, and handle
4434  * any errors that are detected.
4435  *************************************************************************/
4436 
4437  //first release any previous memory
4438  freeRegexMemory();
4439  code = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::compile( c_pattern, /* the pattern */
4440  PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
4441  compile_opts, /* default options */
4442  &err_number, /* for error number */
4443  &err_offset, /* for error offset */
4444  ccontext); /* use compile context */
4445 
4446  if (code == 0) {
4447  /* Compilation failed */
4448  //must not free regex memory, the only function has that right is the destructor
4449  error_number = err_number;
4450  error_offset = err_offset;
4451  return;
4452  } else if ((jpcre2_compile_opts & JIT_COMPILE) != 0) {
4454  int jit_ret = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::jit_compile(code, PCRE2_JIT_COMPLETE);
4455  if(jit_ret < 0) error_number = jit_ret;
4456  }
4457  //everything's OK
4458 }
4459 
4460 
4461 #if JPCRE2_USE_MINIMUM_CXX_11
4462 template<typename Char_T, template<typename...> class Map>
4464 #else
4465 template<typename Char_T>
4466 typename jpcre2::select<Char_T>::String jpcre2::select<Char_T>::MatchEvaluator::replace(bool do_match, Uint replace_opts, SIZE_T * counter) {
4467 #endif
4468  if(counter) *counter = 0;
4469 
4470  replace_opts |= PCRE2_SUBSTITUTE_OVERFLOW_LENGTH;
4471  replace_opts &= ~PCRE2_SUBSTITUTE_GLOBAL;
4472  Regex const * re = RegexMatch::getRegexObject();
4473  // If re or re->code is null, return the subject string unmodified.
4474  if (!re || re->code == 0)
4475  return RegexMatch::getSubject();
4476 
4477  Pcre2Sptr r_subject_ptr = (Pcre2Sptr) RegexMatch::getSubjectPointer()->c_str();
4478  //~ SIZE_T totlen = RegexMatch::getSubjectPointer()->length();
4479 
4480  if(do_match) match();
4481  SIZE_T mcount = vec_soff.size();
4482  // if mcount is 0, return the subject string. (there's no need to worry about re)
4483  if(!mcount) return RegexMatch::getSubject();
4484  SIZE_T current_offset = 0; //needs to be zero, not start_offset, because it's from where unmatched parts will be copied.
4485  String res, tmp;
4486 
4487  //A check, this check is not fullproof.
4488  SIZE_T last = vec_eoff.size();
4489  last = (last>0)?last-1:0;
4490  JPCRE2_ASSERT(vec_eoff[last] <= RegexMatch::getSubject().size(), "ValueError: subject string is not of the required size, may be it's changed!!!\
4491  If you are using esisting match data, try a new match.");
4492 
4493  //loop through the matches
4494  for(SIZE_T i=0;i<mcount;++i){
4495  //first copy the unmatched part.
4496  //Matches that use \K to end before they start are not supported.
4497  if(vec_soff[i] < current_offset || vec_eoff[i] < vec_soff[i]){
4498  RegexMatch::error_number = PCRE2_ERROR_BADSUBSPATTERN;
4499  return RegexMatch::getSubject();
4500  } else {
4501  //~ res += RegexMatch::getSubject().substr(current_offset, vec_soff[i]-current_offset);
4502  res += String(r_subject_ptr+current_offset, r_subject_ptr+vec_soff[i]);
4503  }
4504  //now process the matched part
4505  switch(callbackn){
4506  case 0: tmp = callback0((void*)0, (void*)0, (void*)0); break;
4507  case 1: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount, "VecNum");
4508  tmp = callback1(vec_num[i], (void*)0, (void*)0); break;
4509  case 2: JPCRE2_VECTOR_DATA_ASSERT(vec_nas.size() == mcount, "VecNas");
4510  tmp = callback2((void*)0, vec_nas[i], (void*)0); break;
4511  case 3: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount && vec_nas.size() == mcount, "VecNum or VecNas");
4512  tmp = callback3(vec_num[i], vec_nas[i], (void*)0); break;
4513  case 4: JPCRE2_VECTOR_DATA_ASSERT(vec_ntn.size() == mcount, "VecNtn");
4514  tmp = callback4((void*)0, (void*)0, vec_ntn[i]); break;
4515  case 5: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount && vec_ntn.size() == mcount, "VecNum or VecNtn");
4516  tmp = callback5(vec_num[i], (void*)0, vec_ntn[i]); break;
4517  case 6: JPCRE2_VECTOR_DATA_ASSERT(vec_nas.size() == mcount && vec_ntn.size() == mcount, "VecNas or VecNtn");
4518  tmp = callback6((void*)0, vec_nas[i], vec_ntn[i]); break;
4519  case 7: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount && vec_nas.size() == mcount && vec_ntn.size() == mcount, "VecNum\n or VecNas or VecNtn");
4520  tmp = callback7(vec_num[i], vec_nas[i], vec_ntn[i]); break;
4521  default: JPCRE2_ASSERT(2 == 1, "Invalid callbackn. Please file a bug report (must include the line number from below)."); break;
4522  }
4523  //reset the current offset
4524  current_offset = vec_eoff[i];
4525 
4526  //second part
4528  //~ Pcre2Sptr subject = (Pcre2Sptr) RegexMatch::getSubjectPointer()->c_str();
4529  //substr(vec_soff[i], vec_eoff[i] - vec_soff[i]).c_str();//->substr(vec_soff[i], vec_eoff[i]-vec_soff[i]);
4530  Pcre2Sptr subject = r_subject_ptr + vec_soff[i];
4531  PCRE2_SIZE subject_length = vec_eoff[i] - vec_soff[i];
4532 
4534  Pcre2Sptr replace = (Pcre2Sptr) tmp.c_str();
4535  PCRE2_SIZE replace_length = tmp.length();
4536  bool retry = true;
4537  int ret = 0;
4538  PCRE2_SIZE outlengthptr = 0;
4539  Pcre2Uchar* output_buffer = new Pcre2Uchar[outlengthptr + 1]();
4540 
4541  while (true) {
4542  ret = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::substitute(
4543  re->code, /*Points to the compiled pattern*/
4544  subject, /*Points to the subject string*/
4545  subject_length, /*Length of the subject string*/
4546  0, /*Offset in the subject at which to start matching*/ //must be zero
4547  replace_opts, /*Option bits*/
4548  RegexMatch::mdata, /*Points to a match data block, or is NULL*/
4549  RegexMatch::mcontext, /*Points to a match context, or is NULL*/
4550  replace, /*Points to the replacement string*/
4551  replace_length, /*Length of the replacement string*/
4552  output_buffer, /*Points to the output buffer*/
4553  &outlengthptr /*Points to the length of the output buffer*/
4554  );
4555 
4556  if (ret < 0) {
4557  //Handle errors
4558  if ((replace_opts & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0
4559  && ret == (int) PCRE2_ERROR_NOMEMORY && retry) {
4560  retry = false;
4563  delete[] output_buffer;
4564  output_buffer = new Pcre2Uchar[outlengthptr + 1]();
4565  // Go and try to perform the substitute again
4566  continue;
4567  } else {
4568  RegexMatch::error_number = ret;
4569  delete[] output_buffer;
4570  return RegexMatch::getSubject();
4571  }
4572  }
4573  //If everything's ok exit the loop
4574  break;
4575  }
4576  res += String((Char*) output_buffer,(Char*) (output_buffer + outlengthptr) );
4577  delete[] output_buffer;
4578  if(counter) *counter += ret;
4579  //if FIND_ALL is not set, single match will be performed
4580  if((RegexMatch::getJpcre2Option() & FIND_ALL) == 0) break;
4581  }
4582  //All matched parts have been dealt with.
4583  //now copy rest of the string from current_offset
4584  res += RegexMatch::getSubject().substr(current_offset, String::npos);
4585  return res;
4586 }
4587 
4588 
4589 #if JPCRE2_USE_MINIMUM_CXX_11
4590 template<typename Char_T, template<typename...> class Map>
4592 #else
4593 template<typename Char_T>
4595 #endif
4596  if(counter) *counter = 0;
4597  if(do_match) match();
4598  SIZE_T mcount = vec_soff.size();
4599  // if mcount is 0, return the subject string. (there's no need to worry about re)
4600  if(!mcount) return RegexMatch::getSubject();
4601  SIZE_T current_offset = 0; //no need for worrying about start offset, it's handled by match and we get valid offsets out of it.
4602  String res;
4603 
4604  //A check, this check is not fullproof
4605  SIZE_T last = vec_eoff.size();
4606  last = (last>0)?last-1:0;
4607  JPCRE2_ASSERT(vec_eoff[last] <= RegexMatch::getSubject().size(), "ValueError: subject string is not of the required size, may be it's changed!!!\
4608  If you are using esisting match data, try a new match.");
4609 
4610  //loop through the matches
4611  for(SIZE_T i=0;i<mcount;++i){
4612  //first copy the unmatched part.
4613  //Matches that use \K to end before they start are not supported.
4614  if(vec_soff[i] < current_offset){
4615  RegexMatch::error_number = PCRE2_ERROR_BADSUBSPATTERN;
4616  return RegexMatch::getSubject();
4617  } else {
4618  res += RegexMatch::getSubject().substr(current_offset, vec_soff[i]-current_offset);
4619  }
4620  //now process the matched part
4621  switch(callbackn){
4622  case 0: res += callback0((void*)0, (void*)0, (void*)0); break;
4623  case 1: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount, "VecNum");
4624  res += callback1(vec_num[i], (void*)0, (void*)0); break;
4625  case 2: JPCRE2_VECTOR_DATA_ASSERT(vec_nas.size() == mcount, "VecNas");
4626  res += callback2((void*)0, vec_nas[i], (void*)0); break;
4627  case 3: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount && vec_nas.size() == mcount, "VecNum or VecNas");
4628  res += callback3(vec_num[i], vec_nas[i], (void*)0); break;
4629  case 4: JPCRE2_VECTOR_DATA_ASSERT(vec_ntn.size() == mcount, "VecNtn");
4630  res += callback4((void*)0, (void*)0, vec_ntn[i]); break;
4631  case 5: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount && vec_ntn.size() == mcount, "VecNum or VecNtn");
4632  res += callback5(vec_num[i], (void*)0, vec_ntn[i]); break;
4633  case 6: JPCRE2_VECTOR_DATA_ASSERT(vec_nas.size() == mcount && vec_ntn.size() == mcount, "VecNas or VecNtn");
4634  res += callback6((void*)0, vec_nas[i], vec_ntn[i]); break;
4635  case 7: JPCRE2_VECTOR_DATA_ASSERT(vec_num.size() == mcount && vec_nas.size() == mcount && vec_ntn.size() == mcount, "VecNum\n or VecNas or VecNtn");
4636  res += callback7(vec_num[i], vec_nas[i], vec_ntn[i]); break;
4637  default: JPCRE2_ASSERT(2 == 1, "Invalid callbackn. Please file a bug report (must include the line number from below)."); break;
4638  }
4639  //reset the current offset
4640  current_offset = vec_eoff[i];
4641  if(counter) *counter += 1;
4642  //if FIND_ALL is not set, single match will be performd
4643  if((RegexMatch::getJpcre2Option() & FIND_ALL) == 0) break;
4644  }
4645  //All matched parts have been dealt with.
4646  //now copy rest of the string from current_offset
4647  res += RegexMatch::getSubject().substr(current_offset, String::npos);
4648  return res;
4649 }
4650 
4651 
4652 #if JPCRE2_USE_MINIMUM_CXX_11
4653 template<typename Char_T, template<typename...> class Map>
4655 #else
4656 template<typename Char_T>
4658 #endif
4659  *last_replace_counter = 0;
4660 
4661  // If re or re->code is null, return the subject string unmodified.
4662  if (!re || re->code == 0)
4663  return *r_subject_ptr;
4664 
4665  Pcre2Sptr subject = (Pcre2Sptr) r_subject_ptr->c_str();
4666  PCRE2_SIZE subject_length = r_subject_ptr->length();
4667  Pcre2Sptr replace = (Pcre2Sptr) r_replw_ptr->c_str();
4668  PCRE2_SIZE replace_length = r_replw_ptr->length();
4669  PCRE2_SIZE outlengthptr = (PCRE2_SIZE) buffer_size;
4670  bool retry = true;
4671  int ret = 0;
4672  Pcre2Uchar* output_buffer = new Pcre2Uchar[outlengthptr + 1]();
4673 
4674  while (true) {
4675  ret = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::substitute(
4676  re->code, /*Points to the compiled pattern*/
4677  subject, /*Points to the subject string*/
4678  subject_length, /*Length of the subject string*/
4679  _start_offset, /*Offset in the subject at which to start matching*/
4680  replace_opts, /*Option bits*/
4681  mdata, /*Points to a match data block, or is NULL*/
4682  mcontext, /*Points to a match context, or is NULL*/
4683  replace, /*Points to the replacement string*/
4684  replace_length, /*Length of the replacement string*/
4685  output_buffer, /*Points to the output buffer*/
4686  &outlengthptr /*Points to the length of the output buffer*/
4687  );
4688 
4689  if (ret < 0) {
4690  //Handle errors
4691  if ((replace_opts & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0
4692  && ret == (int) PCRE2_ERROR_NOMEMORY && retry) {
4693  retry = false;
4696  delete[] output_buffer;
4697  output_buffer = new Pcre2Uchar[outlengthptr + 1]();
4698  // Go and try to perform the substitute again
4699  continue;
4700  } else {
4701  error_number = ret;
4702  delete[] output_buffer;
4703  return *r_subject_ptr;
4704  }
4705  }
4706  //If everything's ok exit the loop
4707  break;
4708  }
4709  *last_replace_counter += ret;
4710  String result = String((Char*) output_buffer,(Char*) (output_buffer + outlengthptr) );
4711  delete[] output_buffer;
4712  return result;
4713 }
4714 
4715 
4716 #if JPCRE2_USE_MINIMUM_CXX_11
4717 template<typename Char_T, template<typename...> class Map>
4718 bool jpcre2::select<Char_T, Map>::RegexMatch::getNumberedSubstrings(int rc, Pcre2Sptr subject, PCRE2_SIZE* ovector, uint32_t ovector_count) {
4719 #else
4720 template<typename Char_T>
4721 bool jpcre2::select<Char_T>::RegexMatch::getNumberedSubstrings(int rc, Pcre2Sptr subject, PCRE2_SIZE* ovector, uint32_t ovector_count) {
4722 #endif
4723  NumSub num_sub;
4724  uint32_t rcu = rc;
4725  num_sub.reserve(rcu); //we know exactly how many elements it will have.
4726  uint32_t i;
4727  for (i = 0u; i < rcu; i++)
4728  num_sub.push_back(String((Char*)(subject + ovector[2*i]), ovector[2*i+1] - ovector[2*i]));
4729  for (uint32_t j = i; j < ovector_count; j++)
4730  num_sub.push_back(String());
4731  vec_num->push_back(num_sub); //this function shouldn't be called if this vector is null
4732  return true;
4733 }
4734 
4735 
4736 #if JPCRE2_USE_MINIMUM_CXX_11
4737 template<typename Char_T, template<typename...> class Map>
4738 bool jpcre2::select<Char_T, Map>::RegexMatch::getNamedSubstrings(int namecount, int name_entry_size,
4739  Pcre2Sptr name_table,
4740  Pcre2Sptr subject, PCRE2_SIZE* ovector ) {
4741 #else
4742 template<typename Char_T>
4743 bool jpcre2::select<Char_T>::RegexMatch::getNamedSubstrings(int namecount, int name_entry_size,
4744  Pcre2Sptr name_table,
4745  Pcre2Sptr subject, PCRE2_SIZE* ovector ) {
4746 #endif
4747  Pcre2Sptr tabptr = name_table;
4748  String key;
4749  MapNas map_nas;
4750  MapNtN map_ntn;
4751  for (int i = 0; i < namecount; i++) {
4752  int n;
4753  if(sizeof( Char_T ) * CHAR_BIT == 8){
4754  n = (int)((tabptr[0] << 8) | tabptr[1]);
4755  key = toString((Char*) (tabptr + 2));
4756  }
4757  else{
4758  n = (int)tabptr[0];
4759  key = toString((Char*) (tabptr + 1));
4760  }
4761  //Use of tabptr is finished for this iteration, let's increment it now.
4762  tabptr += name_entry_size;
4763  String value((Char*)(subject + ovector[2*n]), ovector[2*n+1] - ovector[2*n]); //n, not i.
4764  if(vec_nas) map_nas[key] = value;
4765  if(vec_ntn) map_ntn[key] = n;
4766  }
4767  //push the maps into vectors:
4768  if(vec_nas) vec_nas->push_back(map_nas);
4769  if(vec_ntn) vec_ntn->push_back(map_ntn);
4770  return true;
4771 }
4772 
4773 
4774 #if JPCRE2_USE_MINIMUM_CXX_11
4775 template<typename Char_T, template<typename...> class Map>
4777 #else
4778 template<typename Char_T>
4780 #endif
4781 
4782  // If re or re->code is null, return 0 as the match count
4783  if (!re || re->code == 0)
4784  return 0;
4785 
4786  Pcre2Sptr subject = (Pcre2Sptr) m_subject_ptr->c_str();
4787  Pcre2Sptr name_table = 0;
4788  int crlf_is_newline = 0;
4789  int namecount = 0;
4790  int name_entry_size = 0;
4791  int rc = 0;
4792  uint32_t ovector_count = 0;
4793  int utf = 0;
4794  SIZE_T count = 0;
4795  Uint option_bits;
4796  Uint newline = 0;
4797  PCRE2_SIZE *ovector = 0;
4798  SIZE_T subject_length = 0;
4799  MatchData *match_data = 0;
4800  subject_length = m_subject_ptr->length();
4801  bool mdc = false; //mdata created.
4802 
4803 
4804  if (vec_num) vec_num->clear();
4805  if (vec_nas) vec_nas->clear();
4806  if (vec_ntn) vec_ntn->clear();
4807  if(vec_soff) vec_soff->clear();
4808  if(vec_eoff) vec_eoff->clear();
4809 
4810 
4811  /* Using this function ensures that the block is exactly the right size for
4812  the number of capturing parentheses in the pattern. */
4813  if(mdata) match_data = mdata;
4814  else {
4815  match_data = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::match_data_create_from_pattern(re->code, 0);
4816  mdc = true;
4817  }
4818 
4819  rc = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::match( re->code, /* the compiled pattern */
4820  subject, /* the subject string */
4821  subject_length, /* the length of the subject */
4822  _start_offset, /* start at offset 'start_offset' in the subject */
4823  match_opts, /* default options */
4824  match_data, /* block for storing the result */
4825  mcontext); /* use default match context */
4826 
4827  /* Matching failed: handle error cases */
4828 
4829  if (rc < 0) {
4830  if(mdc)
4831  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::match_data_free(match_data); /* Release memory used for the match */
4832  //must not free code. This function has no right to modify regex
4833  switch (rc) {
4834  case PCRE2_ERROR_NOMATCH:
4835  return count;
4836  /*
4837  Handle other special cases if you like
4838  */
4839  default:;
4840  }
4841  error_number = rc;
4842  return count;
4843  }
4844 
4845  ++count; //Increment the counter
4846  /* Match succeded. Get a pointer to the output vector, where string offsets are
4847  stored. */
4848  ovector = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::get_ovector_pointer(match_data);
4849  ovector_count = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::get_ovector_count(match_data);
4850 
4851  /************************************************************************//*
4852  * We have found the first match within the subject string. If the output *
4853  * vector wasn't big enough, say so. Then output any substrings that were *
4854  * captured. *
4855  *************************************************************************/
4856 
4857  /* The output vector wasn't big enough. This should not happen, because we used
4858  pcre2_match_data_create_from_pattern() above. */
4859 
4860  if (rc == 0) {
4861  //ovector was not big enough for all the captured substrings;
4862  error_number = (int)ERROR::INSUFFICIENT_OVECTOR;
4863  rc = ovector_count;
4864  // TODO: We may throw exception at this point.
4865  }
4866  //match succeeded at offset ovector[0]
4867  if(vec_soff) vec_soff->push_back(ovector[0]);
4868  if(vec_eoff) vec_eoff->push_back(ovector[1]);
4869 
4870  // Get numbered substrings if vec_num isn't null
4871  if (vec_num) { //must do null check
4872  if(!getNumberedSubstrings(rc, subject, ovector, ovector_count))
4873  return count;
4874  }
4875 
4876  //get named substrings if either vec_nas or vec_ntn is given.
4877  if (vec_nas || vec_ntn) {
4878  /* See if there are any named substrings, and if so, show them by name. First
4879  we have to extract the count of named parentheses from the pattern. */
4880 
4881  (void) Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::pattern_info( re->code, /* the compiled pattern */
4882  PCRE2_INFO_NAMECOUNT, /* get the number of named substrings */
4883  &namecount); /* where to put the answer */
4884 
4885  if (namecount <= 0); /*No named substrings*/
4886 
4887  else {
4888  /* Before we can access the substrings, we must extract the table for
4889  translating names to numbers, and the size of each entry in the table. */
4890 
4891  (void) Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::pattern_info( re->code, /* the compiled pattern */
4892  PCRE2_INFO_NAMETABLE, /* address of the table */
4893  &name_table); /* where to put the answer */
4894 
4895  (void) Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::pattern_info( re->code, /* the compiled pattern */
4896  PCRE2_INFO_NAMEENTRYSIZE, /* size of each entry in the table */
4897  &name_entry_size); /* where to put the answer */
4898 
4899  /* Now we can scan the table and, for each entry, print the number, the name,
4900  and the substring itself. In the 8-bit library the number is held in two
4901  bytes, most significant first. */
4902 
4903 
4904  // Get named substrings if vec_nas isn't null.
4905  // Get name to number map if vec_ntn isn't null.
4906  }
4907  //the following must be outside the above if-else
4908  if(!getNamedSubstrings(namecount, name_entry_size, name_table, subject, ovector))
4909  return count;
4910  }
4911 
4912  /***********************************************************************//*
4913  * If the "g" modifier was given, we want to continue *
4914  * to search for additional matches in the subject string, in a similar *
4915  * way to the /g option in Perl. This turns out to be trickier than you *
4916  * might think because of the possibility of matching an empty string. *
4917  * What happens is as follows: *
4918  * *
4919  * If the previous match was NOT for an empty string, we can just start *
4920  * the next match at the end of the previous one. *
4921  * *
4922  * If the previous match WAS for an empty string, we can't do that, as it *
4923  * would lead to an infinite loop. Instead, a call of pcre2_match() is *
4924  * made with the PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set. The *
4925  * first of these tells PCRE2 that an empty string at the start of the *
4926  * subject is not a valid match; other possibilities must be tried. The *
4927  * second flag restricts PCRE2 to one match attempt at the initial string *
4928  * position. If this match succeeds, an alternative to the empty string *
4929  * match has been found, and we can print it and proceed round the loop, *
4930  * advancing by the length of whatever was found. If this match does not *
4931  * succeed, we still stay in the loop, advancing by just one character. *
4932  * In UTF-8 mode, which can be set by (*UTF) in the pattern, this may be *
4933  * more than one byte. *
4934  * *
4935  * However, there is a complication concerned with newlines. When the *
4936  * newline convention is such that CRLF is a valid newline, we must *
4937  * advance by two characters rather than one. The newline convention can *
4938  * be set in the regex by (*CR), etc.; if not, we must find the default. *
4939  *************************************************************************/
4940 
4941  if ((jpcre2_match_opts & FIND_ALL) == 0) {
4942  if(mdc)
4943  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::match_data_free(match_data); /* Release the memory that was used */
4944  // Must not free code. This function has no right to modify regex.
4945  return count; /* Exit the program. */
4946  }
4947 
4948  /* Before running the loop, check for UTF-8 and whether CRLF is a valid newline
4949  sequence. First, find the options with which the regex was compiled and extract
4950  the UTF state. */
4951 
4952  (void) Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::pattern_info(re->code, PCRE2_INFO_ALLOPTIONS, &option_bits);
4953  utf = ((option_bits & PCRE2_UTF) != 0);
4954 
4955  /* Now find the newline convention and see whether CRLF is a valid newline
4956  sequence. */
4957 
4958  (void) Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::pattern_info(re->code, PCRE2_INFO_NEWLINE, &newline);
4959  crlf_is_newline = newline == PCRE2_NEWLINE_ANY
4960  || newline == PCRE2_NEWLINE_CRLF
4961  || newline == PCRE2_NEWLINE_ANYCRLF;
4962 
4965  for (;;) {
4966 
4967  Uint options = match_opts; /* Normally no options */
4968  PCRE2_SIZE start_offset = ovector[1]; /* Start at end of previous match */
4969 
4970  /* If the previous match was for an empty string, we are finished if we are
4971  at the end of the subject. Otherwise, arrange to run another match at the
4972  same point to see if a non-empty match can be found. */
4973 
4974  if (ovector[0] == ovector[1]) {
4975  if (ovector[0] == subject_length)
4976  break;
4977  options |= PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
4978  }
4979 
4981 
4982  rc = Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::match( re->code, /* the compiled pattern */
4983  subject, /* the subject string */
4984  subject_length, /* the length of the subject */
4985  start_offset, /* starting offset in the subject */
4986  options, /* options */
4987  match_data, /* block for storing the result */
4988  mcontext); /* use match context */
4989 
4990  /* This time, a result of NOMATCH isn't an error. If the value in "options"
4991  is zero, it just means we have found all possible matches, so the loop ends.
4992  Otherwise, it means we have failed to find a non-empty-string match at a
4993  point where there was a previous empty-string match. In this case, we do what
4994  Perl does: advance the matching position by one character, and continue. We
4995  do this by setting the "end of previous match" offset, because that is picked
4996  up at the top of the loop as the point at which to start again.
4997 
4998  There are two complications: (a) When CRLF is a valid newline sequence, and
4999  the current position is just before it, advance by an extra byte. (b)
5000  Otherwise we must ensure that we skip an entire UTF character if we are in
5001  UTF mode. */
5002 
5003  if (rc == PCRE2_ERROR_NOMATCH) {
5004  if (options == 0)
5005  break; /* All matches found */
5006  ovector[1] = start_offset + 1; /* Advance one code unit */
5007  if (crlf_is_newline && /* If CRLF is newline & */
5008  start_offset < subject_length - 1 && /* we are at CRLF, */
5009  subject[start_offset] == '\r' && subject[start_offset + 1] == '\n')
5010  ovector[1] += 1; /* Advance by one more. */
5011  else if (utf) { /* advance a whole UTF (8 or 16), for UTF-32, it's not needed */
5012  while (ovector[1] < subject_length) {
5013  if(sizeof( Char_T ) * CHAR_BIT == 8 && (subject[ovector[1]] & 0xc0) != 0x80) break;
5014  else if(sizeof( Char_T ) * CHAR_BIT == 16 && (subject[ovector[1]] & 0xfc00) != 0xdc00) break;
5015  else if(sizeof( Char_T ) * CHAR_BIT == 32) break; //must be else if
5016  ovector[1] += 1;
5017  }
5018  }
5019  continue; /* Go round the loop again */
5020  }
5021 
5022  /* Other matching errors are not recoverable. */
5023 
5024  if (rc < 0) {
5025  if(mdc)
5026  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::match_data_free(match_data);
5027  // Must not free code. This function has no right to modify regex.
5028  error_number = rc;
5029  return count;
5030  }
5031 
5032  /* match succeeded */
5033  ++count; //Increment the counter
5034 
5035  if (rc == 0) {
5036  /* The match succeeded, but the output vector wasn't big enough. This
5037  should not happen. */
5038  error_number = (int)ERROR::INSUFFICIENT_OVECTOR;
5039  rc = ovector_count;
5040  // TODO: We may throw exception at this point.
5041  }
5042 
5043  //match succeded at ovector[0]
5044  if(vec_soff) vec_soff->push_back(ovector[0]);
5045  if(vec_eoff) vec_eoff->push_back(ovector[1]);
5046 
5047  /* As before, get substrings stored in the output vector by number, and then
5048  also any named substrings. */
5049 
5050  // Get numbered substrings if vec_num isn't null
5051  if (vec_num) { //must do null check
5052  if(!getNumberedSubstrings(rc, subject, ovector, ovector_count))
5053  return count;
5054  }
5055 
5056  if (vec_nas || vec_ntn) {
5057  //must call this whether we have named substrings or not:
5058  if(!getNamedSubstrings(namecount, name_entry_size, name_table, subject, ovector))
5059  return count;
5060  }
5061  } /* End of loop to find second and subsequent matches */
5062 
5063  if(mdc)
5064  Pcre2Func<sizeof( Char_T ) * CHAR_BIT>::match_data_free(match_data);
5065  // Must not free code. This function has no right to modify regex.
5066  return count;
5067 }
5068 
5069 #undef JPCRE2_VECTOR_DATA_ASSERT
5070 #undef JPCRE2_UNUSED
5071 #undef JPCRE2_USE_MINIMUM_CXX_11
5072 
5073 //some macro documentation for doxygen
5074 
5075 #ifdef __DOXYGEN__
5076 
5077 
5078 #ifndef JPCRE2_USE_FUNCTION_POINTER_CALLBACK
5079 #define JPCRE2_USE_FUNCTION_POINTER_CALLBACK
5080 #endif
5081 
5082 #ifndef JPCRE2_NDEBUG
5083 #define JPCRE2_NDEBUG
5084 #endif
5085 
5086 
5097 
5098 
5105 
5106 
5115 
5116 #endif
5117 
5118 
5119 #endif
jpcre2::ModifierTable::setMatchModifierTable
ModifierTable & setMatchModifierTable(const char *tabsp, const Uint *tabvp)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1059
jpcre2::select::Regex::replace
String replace(String const &mains, String const &repl, Modifier const &mod="", SIZE_T *counter=0)
Perform regex replace and return the replaced string using a temporary replace object.
Definition: jpcre2.hpp:4285
jpcre2::ModifierTable::ModifierTable
ModifierTable(bool deflt)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:885
jpcre2::select::Regex::getJpcre2Option
Uint getJpcre2Option() const
Get JPCRE2 option.
Definition: jpcre2.hpp:3928
jpcre2::select::RegexMatch::setMatchEndOffsetVector
virtual RegexMatch & setMatchEndOffsetVector(VecOff *v)
Set the pointer to a vector to store the offsets where matches end in the subject.
Definition: jpcre2.hpp:1752
jpcre2::select::RegexMatch::setNameToNumberMapVector
virtual RegexMatch & setNameToNumberMapVector(VecNtN *v)
Set a pointer to the name to number map vector.
Definition: jpcre2.hpp:1732
jpcre2::jassert
static void jassert(bool cond, const char *msg, const char *f, size_t line)
JPCRE2 assert function.
Definition: jpcre2.hpp:176
jpcre2::select::Regex::getModifierTable
ModifierTable const * getModifierTable()
Get the modifier table that is set,.
Definition: jpcre2.hpp:3973
jpcre2::ModifierTable::ModifierTable
ModifierTable()
Default constructor that creates an empty modifier table.
Definition: jpcre2.hpp:881
jpcre2::select::RegexMatch::changeModifier
virtual RegexMatch & changeModifier(Modifier const &mod, bool x)
Parse modifier and add/remove equivalent PCRE2 and JPCRE2 options.
Definition: jpcre2.hpp:1898
jpcre2::select::Regex::reset
Regex & reset()
Reset all class variables to its default (initial) state including memory.
Definition: jpcre2.hpp:3835
jpcre2::select::RegexMatch::addPcre2Option
virtual RegexMatch & addPcre2Option(Uint x)
Add option to existing PCRE2 options for match.
Definition: jpcre2.hpp:1951
jpcre2::select::RegexMatch::changeJpcre2Option
virtual RegexMatch & changeJpcre2Option(Uint opt, bool x)
Add or remove a JPCRE2 option.
Definition: jpcre2.hpp:1910
jpcre2::select::MatchEvaluator::changePcre2Option
MatchEvaluator & changePcre2Option(Uint opt, bool x)
Call RegexMatch::changePcre2Option(Uint opt, bool x).
Definition: jpcre2.hpp:2785
jpcre2::select::RegexReplace::getMatchContext
MatchContext * getMatchContext()
Return pointer to the match context that was previously set with setMatchContext().
Definition: jpcre2.hpp:3174
jpcre2::select::Regex::getReplaceObject
RegexReplace getReplaceObject()
Synonym for initReplace()
Definition: jpcre2.hpp:4272
jpcre2::select::Regex::getNewLine
Uint getNewLine()
Get new line convention from compiled code.
Definition: jpcre2.hpp:3963
jpcre2::select::RegexReplace::setJpcre2Option
RegexReplace & setJpcre2Option(Uint x)
Set JPCRE2 option for replace (overwrite existing option)
Definition: jpcre2.hpp:3322
jpcre2::select::RegexMatch::setNamedSubstringVector
virtual RegexMatch & setNamedSubstringVector(VecNas *v)
Set a pointer to the named substring vector.
Definition: jpcre2.hpp:1721
jpcre2::select::Regex::getMatchObject
RegexMatch getMatchObject()
Synonym for initMatch()
Definition: jpcre2.hpp:4215
jpcre2::select::RegexReplace::resetErrors
RegexReplace & resetErrors()
Reset replace related errors to zero.
Definition: jpcre2.hpp:3062
jpcre2::select::RegexMatch::getNumberedSubstringVector
virtual VecNum const * getNumberedSubstringVector() const
Get pointer to numbered substring vector.
Definition: jpcre2.hpp:1678
jpcre2::ModifierTable::toMatchOption
void toMatchOption(Modifier const &mod, bool x, Uint *po, Uint *jo, int *en, SIZE_T *eo) const
Modifier parser for match related options.
Definition: jpcre2.hpp:978
jpcre2::select::MatchEvaluator::setSubject
MatchEvaluator & setSubject(String const *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2670
jpcre2::select::Regex::match
SIZE_T match(String const &s, Modifier const &mod, PCRE2_SIZE start_offset=0)
Perform regex match and return match count using a temporary match object.
Definition: jpcre2.hpp:4227
jpcre2::select::RegexMatch::getRegexObject
virtual Regex const * getRegexObject() const
Get a pointer to the associated Regex object.
Definition: jpcre2.hpp:1672
jpcre2::select::Regex::compile
void compile(String const *re, Modifier const &mod)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4184
jpcre2::select::Regex::preplace
SIZE_T preplace(String *mains, String const &repl, Modifier const &mod="")
Perl compatible replace method.
Definition: jpcre2.hpp:4332
jpcre2::select::Regex::compile
void compile(String const &re, Uint po)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4160
jpcre2::select::RegexMatch::addModifier
virtual RegexMatch & addModifier(Modifier const &mod)
Parse modifier string and add equivalent PCRE2 and JPCRE2 options.
Definition: jpcre2.hpp:1932
jpcre2::select::MatchEvaluator::clearMatchData
MatchEvaluator & clearMatchData()
Clear match data.
Definition: jpcre2.hpp:2602
jpcre2::select::Regex::resetCharacterTables
Regex & resetCharacterTables()
Recreate character tables used by PCRE2.
Definition: jpcre2.hpp:3870
jpcre2::select::RegexReplace::changePcre2Option
RegexReplace & changePcre2Option(Uint opt, bool x)
Add or remove a PCRE2 option.
Definition: jpcre2.hpp:3396
jpcre2::INFO::VERSION_MINOR
static const char VERSION_MINOR[]
Minor version, includes bug fix or minor feature upgrade.
Definition: jpcre2.hpp:124
jpcre2::ModifierTable::resetCompileModifierTable
ModifierTable & resetCompileModifierTable()
Reset the compile modifier table to its initial (empty) state including memory.
Definition: jpcre2.hpp:911
jpcre2::ModifierTable::clear
ModifierTable & clear()
Clear the modifier tables to their initial (empty) state.
Definition: jpcre2.hpp:964
jpcre2::select::RegexReplace::setModifierTable
RegexReplace & setModifierTable(ModifierTable const *mdt)
Set a custom modifier table to be used.
Definition: jpcre2.hpp:3294
jpcre2::select::RegexMatch::getMatchContext
virtual MatchContext * getMatchContext()
Return pointer to the match context that was previously set with setMatchContext().
Definition: jpcre2.hpp:1865
jpcre2::ModifierTable::setMatchModifierTable
ModifierTable & setMatchModifierTable(std::string const &tabs, const Uint *tabvp)
Set modifier table for match.
Definition: jpcre2.hpp:1043
jpcre2::select::RegexMatch::setMatchDataBlock
virtual RegexMatch & setMatchDataBlock(MatchData *madt)
Set the match data block to be used.
Definition: jpcre2.hpp:1874
jpcre2::select::MatchEvaluator::setRegexObject
MatchEvaluator & setRegexObject(Regex const *r)
Call RegexMatch::setRegexObject(r).
Definition: jpcre2.hpp:2654
jpcre2::ModifierTable::reset
ModifierTable & reset()
Reset the modifier tables to their initial (empty) state including memory.
Definition: jpcre2.hpp:921
jpcre2::select::Regex::match
SIZE_T match(String const *s, Modifier const &mod, PCRE2_SIZE start_offset=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4237
jpcre2::select::RegexMatch::setSubject
virtual RegexMatch & setSubject(String const &s)
Set the subject string for match.
Definition: jpcre2.hpp:1762
jpcre2::select::MatchEvaluator::operator=
MatchEvaluator & operator=(MatchEvaluator const &me)
Overloaded copy-assignment operator.
Definition: jpcre2.hpp:2387
jpcre2::select::callback::fill
static String fill(NumSub const &num, MapNas const &nas, MapNtn const &ntn)
Callback function for populating match vectors that does not modify the subject string.
Definition: jpcre2.hpp:2046
jpcre2::ModifierTable::setCompileModifierTable
ModifierTable & setCompileModifierTable(std::string const &tabs, VecOpt const &tabv)
Set modifier table for compile.
Definition: jpcre2.hpp:1113
jpcre2::select::RegexMatch::getPcre2Option
virtual Uint getPcre2Option() const
Get PCRE2 option.
Definition: jpcre2.hpp:1635
jpcre2::select::RegexMatch::setModifierTable
virtual RegexMatch & setModifierTable(ModifierTable const *mdt)
Set a custom modifier table to be used.
Definition: jpcre2.hpp:1800
jpcre2::select::MatchEvaluator::resetMatchData
MatchEvaluator & resetMatchData()
Reset match data to initial state.
Definition: jpcre2.hpp:2615
jpcre2::select::MatchEvaluator::nreplace
String nreplace(bool do_match=true, Uint jro=0, SIZE_T *counter=0)
Perform regex replace with this match evaluator.
Definition: jpcre2.hpp:4591
jpcre2::select::Regex::getErrorNumber
int getErrorNumber() const
Returns the last error number.
Definition: jpcre2.hpp:3934
jpcre2::select::MatchEvaluator::setStartOffset
MatchEvaluator & setStartOffset(PCRE2_SIZE offset)
Call RegexMatch::setStartOffset (PCRE2_SIZE offset).
Definition: jpcre2.hpp:2725
jpcre2::select::RegexReplace::operator=
RegexReplace & operator=(RegexReplace const &rr)
Overloaded Copy assignment operator.
Definition: jpcre2.hpp:3002
jpcre2::select::Regex::setPcre2Option
Regex & setPcre2Option(Uint x)
Set PCRE2 option for compile (overwrites existing option)
Definition: jpcre2.hpp:4053
jpcre2::select::RegexReplace::setReplaceCounter
RegexReplace & setReplaceCounter(SIZE_T *counter)
Set an external counter variable to store the replacement count.
Definition: jpcre2.hpp:3206
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< NumSub const &, void *, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2325
jpcre2::select::RegexReplace::setMatchDataBlock
RegexReplace & setMatchDataBlock(MatchData *match_data)
Set the match data block to be used.
Definition: jpcre2.hpp:3355
jpcre2::select::MatchEvaluator::addModifier
MatchEvaluator & addModifier(Modifier const &mod)
Call RegexMatch::addModifier(Modifier const& mod).
Definition: jpcre2.hpp:2793
jpcre2::select::VecNtn
VecNtN VecNtn
Allow spelling mistake of VecNtN as VecNtn.
Definition: jpcre2.hpp:1277
jpcre2::select::RegexMatch::getModifier
virtual std::string getModifier() const
Calculate modifier string from PCRE2 and JPCRE2 options and return it.
Definition: jpcre2.hpp:1619
jpcre2::NONE
@ NONE
Option 0 (zero)
Definition: jpcre2.hpp:152
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< void *, void *, void * >::Callback mef)
Member function to set a callback function with no vector reference.
Definition: jpcre2.hpp:2434
jpcre2::ModifierTable::setReplaceModifierTable
ModifierTable & setReplaceModifierTable(std::string const &tabs, const Uint *tabvp)
Set modifier table for replace.
Definition: jpcre2.hpp:1083
jpcre2::select::MapNtN
class Map< String, SIZE_T > MapNtN
Substring name to Substring number map.
Definition: jpcre2.hpp:1259
jpcre2::select::RegexReplace::getErrorMessage
String getErrorMessage() const
Returns the last error message.
Definition: jpcre2.hpp:3082
jpcre2::select::MatchEvaluator::setSubject
MatchEvaluator & setSubject(String const &s)
Call RegexMatch::setSubject(String const &s).
Definition: jpcre2.hpp:2662
jpcre2::ModifierTable::setMatchModifierTable
ModifierTable & setMatchModifierTable(std::string const &tabs, VecOpt const &tabv)
Set modifier table for match.
Definition: jpcre2.hpp:1033
jpcre2::select::RegexReplace::setSubject
RegexReplace & setSubject(String *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3240
jpcre2::INFO::VERSION_MAJOR
static const char VERSION_MAJOR[]
Major version, updated when API change is made.
Definition: jpcre2.hpp:123
jpcre2::select::RegexReplace::replace
String replace(void)
Perform regex replace by retrieving subject string, replacement string, modifier and other options fr...
Definition: jpcre2.hpp:4654
jpcre2::select::RegexReplace::getBufferSize
PCRE2_SIZE getBufferSize()
Get the initial buffer size that is being used by internal function pcre2_substitute.
Definition: jpcre2.hpp:3187
jpcre2::INFO::VERSION_GENRE
static const char VERSION_GENRE[]
Generation, depends on original PCRE2 version.
Definition: jpcre2.hpp:122
jpcre2::INFO::FULL_VERSION
static const char FULL_VERSION[]
Full version string.
Definition: jpcre2.hpp:121
jpcre2::select::RegexMatch::setRegexObject
virtual RegexMatch & setRegexObject(Regex const *r)
Set the associated regex object.
Definition: jpcre2.hpp:1699
jpcre2::select::MatchEvaluator::operator=
MatchEvaluator & operator=(MatchEvaluator &&me)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2417
jpcre2::select::RegexMatch::RegexMatch
RegexMatch(RegexMatch const &rm)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1487
jpcre2::select::Regex::setPattern
Regex & setPattern(String const &re)
Set the pattern string to compile.
Definition: jpcre2.hpp:3999
jpcre2::select::Regex::operator=
Regex & operator=(Regex &&r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3766
jpcre2::select::RegexMatch::RegexMatch
RegexMatch(Regex const *r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1478
jpcre2::select::Regex::addModifier
Regex & addModifier(Modifier const &mod)
Parse modifier string and add equivalent PCRE2 and JPCRE2 options.
Definition: jpcre2.hpp:4105
jpcre2::select::Regex::compile
void compile(String const *re, Uint po, Uint jo)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4152
jpcre2::select::Regex::operator=
Regex & operator=(Regex const &r)
Overloaded assignment operator.
Definition: jpcre2.hpp:3736
jpcre2::select::MatchEvaluator::setMatchContext
MatchEvaluator & setMatchContext(MatchContext *match_context)
Call RegexMatch::setMatchContext(MatchContext *match_context).
Definition: jpcre2.hpp:2733
jpcre2::select::Regex::initMatch
RegexMatch initMatch()
Returns a default constructed RegexMatch object by value.
Definition: jpcre2.hpp:4207
jpcre2::select::RegexReplace::getLastReplaceCount
SIZE_T getLastReplaceCount()
Get the number of replacement in last replace operation.
Definition: jpcre2.hpp:3196
jpcre2::select::Regex::replace
String replace(String *mains, String const &repl, Modifier const &mod="", SIZE_T *counter=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4296
jpcre2::select::Regex::compile
void compile(String const &re)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4191
jpcre2::select::RegexReplace::getReplaceWith
String getReplaceWith() const
Get replacement string.
Definition: jpcre2.hpp:3092
jpcre2::select::MatchEvaluator::setFindAll
MatchEvaluator & setFindAll()
Call RegexMatch::setFindAll().
Definition: jpcre2.hpp:2717
jpcre2::select::RegexReplace::replace
String replace(MatchEvaluator me)
PCRE2 compatible replace function that takes a MatchEvaluator.
Definition: jpcre2.hpp:3523
jpcre2::select::toString
static String toString(Pcre2Uchar *a)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1325
jpcre2::ERROR::INVALID_MODIFIER
@ INVALID_MODIFIER
Invalid modifier was detected.
Definition: jpcre2.hpp:143
jpcre2::select::RegexMatch::reset
virtual RegexMatch & reset()
Reset all class variables to its default (initial) state including memory.
Definition: jpcre2.hpp:1537
jpcre2::select::getPcre2ErrorMessage
static String getPcre2ErrorMessage(int err_num)
Retruns error message from PCRE2 error number.
Definition: jpcre2.hpp:1332
jpcre2::select::RegexReplace::getErrorOffset
int getErrorOffset() const
Returns the last error offset.
Definition: jpcre2.hpp:3076
jpcre2::ModifierTable::resetReplaceModifierTable
ModifierTable & resetReplaceModifierTable()
Reset the replace modifier table to its initial (empty) state including memory.
Definition: jpcre2.hpp:901
jpcre2::select::MatchEvaluator::setJpcre2Option
MatchEvaluator & setJpcre2Option(Uint x)
Call RegexMatch::setJpcre2Option(Uint x).
Definition: jpcre2.hpp:2694
jpcre2::select::Regex::match
SIZE_T match(String const *s, PCRE2_SIZE start_offset=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4257
jpcre2::select::RegexReplace::RegexReplace
RegexReplace()
Default constructor.
Definition: jpcre2.hpp:2976
jpcre2::select::RegexMatch::getSubject
virtual String getSubject() const
Get subject string (by value).
Definition: jpcre2.hpp:1592
jpcre2::SIZE_T
PCRE2_SIZE SIZE_T
Used for match count and vector size.
Definition: jpcre2.hpp:129
jpcre2::select::Regex::replace
String replace(String *mains, String const *repl, Modifier const &mod="", SIZE_T *counter=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4320
jpcre2::select::MatchEvaluator::addJpcre2Option
MatchEvaluator & addJpcre2Option(Uint x)
Call RegexMatch::addJpcre2Option(Uint x).
Definition: jpcre2.hpp:2801
jpcre2::select::MatchEvaluator::reset
MatchEvaluator & reset()
Reset MatchEvaluator to initial state including memory.
Definition: jpcre2.hpp:2627
jpcre2::select::callback::eraseFill
static String eraseFill(NumSub const &num, MapNas const &nas, MapNtN const &ntn)
Callback function that removes the matched part/s in the subject string and takes all match vectors a...
Definition: jpcre2.hpp:2022
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< void *, MapNas const &, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2356
jpcre2::select::Regex::Regex
Regex(String const *re, Modifier const &mod)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3683
jpcre2::ModifierTable
Lets you create custom modifier tables.
Definition: jpcre2.hpp:832
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< void *, void *, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2368
jpcre2::select::RegexReplace::setMatchContext
RegexReplace & setMatchContext(MatchContext *match_context)
Set the match context to be used.
Definition: jpcre2.hpp:3344
jpcre2::select::RegexReplace::setReplaceWith
RegexReplace & setReplaceWith(String const &s)
Set the replacement string.
Definition: jpcre2.hpp:3261
jpcre2::select::RegexMatch::getModifierTable
virtual ModifierTable const * getModifierTable()
Get the modifier table that is set,.
Definition: jpcre2.hpp:1626
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< NumSub const &, void *, void * >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2446
jpcre2::select::Regex::getPcre2Option
Uint getPcre2Option() const
Get PCRE2 option.
Definition: jpcre2.hpp:3920
jpcre2::select::Regex::Regex
Regex(String const &re, Modifier const &mod)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3675
jpcre2::select::MatchEvaluatorCallback
This class contains a typedef of a function pointer or a templated function wrapper (std::function) t...
Definition: jpcre2.hpp:1999
jpcre2::select::RegexReplace::nreplace
String nreplace(MatchEvaluator me)
JPCRE2 native replace function.
Definition: jpcre2.hpp:3505
jpcre2::select::Regex::setNewLine
Regex & setNewLine(Uint value)
Set new line convention.
Definition: jpcre2.hpp:3988
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< void *, MapNas const &, void * >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2543
jpcre2::select::Regex::compile
void compile(String const &re, Modifier const &mod)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4176
jpcre2::select::Regex::compile
void compile(String const *re, Uint po)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4168
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< NumSub const &, void *, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2493
jpcre2::select::MapNtn
MapNtN MapNtn
Allow spelling mistake of MapNtN as MapNtn.
Definition: jpcre2.hpp:1268
jpcre2::select::RegexReplace::RegexReplace
RegexReplace(Regex const *r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2985
jpcre2::select::Regex::changePcre2Option
Regex & changePcre2Option(Uint opt, bool x)
Add or remove a PCRE2 option.
Definition: jpcre2.hpp:4093
jpcre2::select::Regex::preplace
SIZE_T preplace(String const &mains, String const *repl, Modifier const &mod="")
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4380
jpcre2::select::Regex::compile
void compile(String const &re, Uint po, Uint jo)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4142
jpcre2::select::RegexMatch::setModifier
virtual RegexMatch & setModifier(Modifier const &s)
Set the modifier (resets all JPCRE2 and PCRE2 options) by calling RegexMatch::changeModifier().
Definition: jpcre2.hpp:1790
jpcre2::select::Regex::addPcre2Option
Regex & addPcre2Option(Uint x)
Add option to existing PCRE2 options for compile.
Definition: jpcre2.hpp:4124
jpcre2::select::VecNum
std::vector< NumSub > VecNum
Vector of matches with numbered substrings.
Definition: jpcre2.hpp:1279
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator()
Default constructor.
Definition: jpcre2.hpp:2272
jpcre2::select::RegexReplace::RegexReplace
RegexReplace(RegexReplace const &rr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2994
jpcre2::ModifierTable::fromCompileOption
std::string fromCompileOption(Uint po, Uint jo) const
Take compile related option value and convert to modifier string.
Definition: jpcre2.hpp:1024
jpcre2::select::MatchEvaluator::replace
String replace(bool do_match=true, Uint ro=0, SIZE_T *counter=0)
PCRE2 compatible replace function that uses this MatchEvaluator.
Definition: jpcre2.hpp:4463
jpcre2::select::RegexReplace::setBufferSize
RegexReplace & setBufferSize(PCRE2_SIZE x)
Set the initial buffer size to be allocated for replaced string (used by PCRE2)
Definition: jpcre2.hpp:3302
jpcre2::select::Regex::clear
Regex & clear()
Clear all class variables to its default (initial) state (some memory may retain for further use).
Definition: jpcre2.hpp:3845
jpcre2::ModifierTable::toReplaceOption
void toReplaceOption(Modifier const &mod, bool x, Uint *po, Uint *jo, int *en, SIZE_T *eo) const
Modifier parser for replace related options.
Definition: jpcre2.hpp:989
jpcre2::select::RegexReplace::getMatchDataBlock
virtual MatchData * getMatchDataBlock()
Get the pointer to the match data block that was set previously with setMatchData() Handling memory i...
Definition: jpcre2.hpp:3181
jpcre2::select::RegexReplace
Provides public constructors to create RegexReplace objects.
Definition: jpcre2.hpp:2890
jpcre2::Modifier::str
std::string str() const
Returns the modifier string.
Definition: jpcre2.hpp:651
jpcre2::JIT_COMPILE
@ JIT_COMPILE
Perform JIT compilation for optimization.
Definition: jpcre2.hpp:154
jpcre2::select::RegexMatch::getErrorNumber
virtual int getErrorNumber() const
Returns the last error number.
Definition: jpcre2.hpp:1569
jpcre2::select::RegexMatch::setJpcre2Option
virtual RegexMatch & setJpcre2Option(Uint x)
Set JPCRE2 option for match (resets all)
Definition: jpcre2.hpp:1810
jpcre2::select::MatchEvaluator::setFindAll
MatchEvaluator & setFindAll(bool x)
Call RegexMatch::setFindAll(bool x).
Definition: jpcre2.hpp:2710
jpcre2::select::RegexReplace::setRegexObject
RegexReplace & setRegexObject(Regex const *r)
Set the associated Regex object.
Definition: jpcre2.hpp:3216
jpcre2::select::RegexReplace::RegexReplace
RegexReplace(RegexReplace &&rr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3017
jpcre2::select::Regex::Regex
Regex(Regex const &r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3728
jpcre2::Ush
uint8_t Ush
8 bit unsigned integer.
Definition: jpcre2.hpp:131
jpcre2::select::Regex::changeJpcre2Option
Regex & changeJpcre2Option(Uint opt, bool x)
Add or remove a JPCRE2 option.
Definition: jpcre2.hpp:4082
JPCRE2_ASSERT
#define JPCRE2_ASSERT(cond, msg)
jpcre2::Modifier::operator[]
char operator[](SIZE_T i) const
operator[] overload to access character by index.
Definition: jpcre2.hpp:664
jpcre2::select::Regex::getPatternPointer
String const * getPatternPointer() const
Get pointer to pattern string.
Definition: jpcre2.hpp:3894
jpcre2::select::callback
Provides some default static callback functions.
Definition: jpcre2.hpp:2012
jpcre2::select::RegexReplace::getSubjectPointer
String const * getSubjectPointer() const
Get pointer to subject string.
Definition: jpcre2.hpp:3112
jpcre2::select::RegexReplace::clear
RegexReplace & clear()
Clear all class variables to its default (initial) state (some memory may retain for further use).
Definition: jpcre2.hpp:3051
jpcre2::select::Regex::replace
String replace(String const &mains, String const *repl, Modifier const &mod="", SIZE_T *counter=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4308
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< NumSub const &, MapNas const &, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2518
jpcre2::select::Regex::setModifierTable
Regex & setModifierTable(ModifierTable const *mdt)
Set a custom modifier table to be used.
Definition: jpcre2.hpp:4033
jpcre2
jpcre2::select::RegexMatch::setPcre2Option
virtual RegexMatch & setPcre2Option(Uint x)
Set PCRE2 option match (overwrite existing option)
Definition: jpcre2.hpp:1820
jpcre2::ModifierTable::clearCompileModifierTable
ModifierTable & clearCompileModifierTable()
Clear the compile modifier table to its initial (empty) state.
Definition: jpcre2.hpp:953
jpcre2::select::MatchEvaluator::resetErrors
MatchEvaluator & resetErrors()
Call RegexMatch::resetErrors().
Definition: jpcre2.hpp:2646
jpcre2::ModifierTable::setReplaceModifierTable
ModifierTable & setReplaceModifierTable(std::string const &tabs, VecOpt const &tabv)
Set modifier table for replace.
Definition: jpcre2.hpp:1073
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(Regex const *r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2285
jpcre2::select::MapNas
class Map< String, String > MapNas
Map for Named substrings.
Definition: jpcre2.hpp:1257
jpcre2::ModifierTable::setReplaceModifierTable
ModifierTable & setReplaceModifierTable(const char *tabsp, const Uint *tabvp)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1099
jpcre2::ModifierTable::setAllToDefault
ModifierTable & setAllToDefault()
Set all tables to default.
Definition: jpcre2.hpp:1180
jpcre2::select::toString
static String toString(Char *a)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1316
jpcre2::select::MatchEvaluator::clear
MatchEvaluator & clear()
Clears MatchEvaluator.
Definition: jpcre2.hpp:2637
jpcre2::FIND_ALL
@ FIND_ALL
Find all during match (global match)
Definition: jpcre2.hpp:153
jpcre2::select::RegexMatch::resetErrors
virtual RegexMatch & resetErrors()
reset match related errors to zero.
Definition: jpcre2.hpp:1561
jpcre2::select::Regex::match
SIZE_T match(String const &s, PCRE2_SIZE start_offset=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4247
jpcre2::VecOff
std::vector< SIZE_T > VecOff
vector of size_t.
Definition: jpcre2.hpp:132
jpcre2::select::RegexReplace::preplace
SIZE_T preplace(MatchEvaluator me)
Perl compatible replace method with match evaluator.
Definition: jpcre2.hpp:3466
jpcre2::select::RegexReplace::operator=
RegexReplace & operator=(RegexReplace &&rr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3030
jpcre2::select::RegexMatch::getMatchDataBlock
virtual MatchData * getMatchDataBlock()
Get the pointer to the match data block that was set previously with setMatchData() Handling memory i...
Definition: jpcre2.hpp:1882
jpcre2::ModifierTable::setCompileModifierTable
ModifierTable & setCompileModifierTable(const char *tabsp, const Uint *tabvp)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1139
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< void *, void *, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2590
jpcre2::select::RegexMatch::RegexMatch
RegexMatch()
Default constructor.
Definition: jpcre2.hpp:1469
jpcre2::select::RegexMatch::match
virtual SIZE_T match(void)
Perform match operation using info from class variables and return the match count and store the resu...
Definition: jpcre2.hpp:4776
jpcre2::select::MatchEvaluator::setPcre2Option
MatchEvaluator & setPcre2Option(Uint x)
Call RegexMatch::setPcre2Option (Uint x).
Definition: jpcre2.hpp:2702
jpcre2::ModifierTable::fromMatchOption
std::string fromMatchOption(Uint po, Uint jo) const
Take match related option value and convert to modifier string.
Definition: jpcre2.hpp:1008
jpcre2::select::Regex::preplace
SIZE_T preplace(String *mains, String const *repl, Modifier const &mod="")
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4348
jpcre2::select::RegexMatch::setStartOffset
virtual RegexMatch & setStartOffset(PCRE2_SIZE offset)
Set offset from where match starts.
Definition: jpcre2.hpp:1846
jpcre2::Modifier
Class to take a std::string modifier value with null safety.
Definition: jpcre2.hpp:634
jpcre2::select::RegexReplace::getSubject
String getSubject() const
Get subject string.
Definition: jpcre2.hpp:3105
jpcre2::select::RegexReplace::getReplaceWithPointer
String const * getReplaceWithPointer() const
Get pointer to replacement string.
Definition: jpcre2.hpp:3098
jpcre2::select::RegexMatch::addJpcre2Option
virtual RegexMatch & addJpcre2Option(Uint x)
Add option to existing JPCRE2 options for match.
Definition: jpcre2.hpp:1941
jpcre2::select::Regex::getModifier
std::string getModifier() const
Calculate modifier string from PCRE2 and JPCRE2 options and return it.
Definition: jpcre2.hpp:3911
jpcre2::ModifierTable::fromReplaceOption
std::string fromReplaceOption(Uint po, Uint jo) const
Take replace related option value and convert to modifier string.
Definition: jpcre2.hpp:1016
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< NumSub const &, MapNas const &, void * >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2315
jpcre2::select::Regex::Regex
Regex(String const &re, Uint po)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3691
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< void *, MapNas const &, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2566
jpcre2::select::Regex::getPattern
String getPattern() const
Get pattern string.
Definition: jpcre2.hpp:3888
jpcre2::select::Regex::setJpcre2Option
Regex & setJpcre2Option(Uint x)
Set JPCRE2 option for compile (overwrites existing option)
Definition: jpcre2.hpp:4043
jpcre2::select::RegexMatch::getErrorMessage
virtual String getErrorMessage() const
Returns the last error message.
Definition: jpcre2.hpp:1581
jpcre2::select::Regex::operator!
bool operator!() const
Provides boolean check for the status of the object.
Definition: jpcre2.hpp:3824
jpcre2::select::RegexMatch::setMatchContext
virtual RegexMatch & setMatchContext(MatchContext *match_context)
Set the match context.
Definition: jpcre2.hpp:1857
jpcre2::select::String
std::basic_string< Char_T > String
Typedef for string (std::string, std::wstring, std::u16string, std::u32string).
Definition: jpcre2.hpp:1253
jpcre2::select::MatchEvaluator::match
SIZE_T match(void)
Perform match and return the match count.
Definition: jpcre2.hpp:2819
jpcre2::ModifierTable::setCompileModifierTableToDefault
ModifierTable & setCompileModifierTableToDefault()
Set compile modifier table to default.
Definition: jpcre2.hpp:1170
jpcre2::select::RegexReplace::setSubject
RegexReplace & setSubject(String const &s)
Set the subject string for replace.
Definition: jpcre2.hpp:3227
jpcre2::select::RegexMatch::~RegexMatch
virtual ~RegexMatch()
Destructor Frees all internal memories that were used.
Definition: jpcre2.hpp:1531
jpcre2::select::RegexMatch::getJpcre2Option
virtual Uint getJpcre2Option() const
Get JPCRE2 option.
Definition: jpcre2.hpp:1643
jpcre2::select::Regex::Regex
Regex(String const &re, Uint po, Uint jo)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3708
jpcre2::select::RegexReplace::getErrorNumber
int getErrorNumber() const
Returns the last error number.
Definition: jpcre2.hpp:3070
jpcre2::ModifierTable::setMatchModifierTableToDefault
ModifierTable & setMatchModifierTableToDefault()
Set match modifie table to default.
Definition: jpcre2.hpp:1150
jpcre2::select::RegexMatch::setFindAll
virtual RegexMatch & setFindAll()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1837
jpcre2::select::toString
static String toString(Char const *a)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1307
jpcre2::select::MatchEvaluator::setBufferSize
MatchEvaluator & setBufferSize(PCRE2_SIZE x)
Set the buffer size that will be used by pcre2_substitute (replace()).
Definition: jpcre2.hpp:2752
jpcre2::select::Regex
Provides public constructors to create Regex object.
Definition: jpcre2.hpp:3550
jpcre2::select::RegexReplace::getJpcre2Option
Uint getJpcre2Option() const
Get JPCRE2 option.
Definition: jpcre2.hpp:3160
jpcre2::select::MatchEvaluator::changeJpcre2Option
MatchEvaluator & changeJpcre2Option(Uint opt, bool x)
Call RegexMatch::changeJpcre2Option(Uint opt, bool x).
Definition: jpcre2.hpp:2776
jpcre2::select::Regex::getPcre2Code
Pcre2Code const * getPcre2Code() const
Get Pcre2 raw compiled code pointer.
Definition: jpcre2.hpp:3882
jpcre2::select::Regex::getErrorMessage
String getErrorMessage() const
Returns the last error message.
Definition: jpcre2.hpp:3946
jpcre2::select::RegexMatch::changePcre2Option
virtual RegexMatch & changePcre2Option(Uint opt, bool x)
Add or remove a PCRE2 option.
Definition: jpcre2.hpp:1921
jpcre2::VecOpt
std::vector< Uint > VecOpt
vector for Uint option values.
Definition: jpcre2.hpp:133
jpcre2::select::Regex::preplace
SIZE_T preplace(String const &mains, String const &repl, Modifier const &mod="")
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4364
jpcre2::select::Regex::Regex
Regex(Regex &&r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3753
jpcre2::select::MatchEvaluator::getBufferSize
PCRE2_SIZE getBufferSize()
Get the initial buffer size that is being used by internal function pcre2_substitute.
Definition: jpcre2.hpp:2759
jpcre2::select::RegexReplace::addJpcre2Option
RegexReplace & addJpcre2Option(Uint x)
Add specified JPCRE2 option to existing options for replace.
Definition: jpcre2.hpp:3418
jpcre2::INFO::NAME
static const char NAME[]
Name of the project.
Definition: jpcre2.hpp:120
jpcre2::select::RegexMatch::setFindAll
virtual RegexMatch & setFindAll(bool x)
Set whether to perform global match.
Definition: jpcre2.hpp:1828
jpcre2::ModifierTable::toCompileOption
void toCompileOption(Modifier const &mod, bool x, Uint *po, Uint *jo, int *en, SIZE_T *eo) const
Modifier parser for compile related options.
Definition: jpcre2.hpp:1000
jpcre2::select::Regex::Regex
Regex(String const *re, Uint po, Uint jo)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3717
jpcre2::ERROR::INSUFFICIENT_OVECTOR
@ INSUFFICIENT_OVECTOR
Ovector was not big enough during a match.
Definition: jpcre2.hpp:144
jpcre2::select::MatchEvaluator::setCallback
MatchEvaluator & setCallback(typename MatchEvaluatorCallback< NumSub const &, MapNas const &, void * >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2469
jpcre2::ModifierTable::resetMatchModifierTable
ModifierTable & resetMatchModifierTable()
Reset the match modifier table to its initial (empty) state including memory.
Definition: jpcre2.hpp:891
jpcre2::select::Regex::setModifier
Regex & setModifier(Modifier const &x)
set the modifier (resets all JPCRE2 and PCRE2 options) by calling Regex::changeModifier().
Definition: jpcre2.hpp:4024
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< NumSub const &, MapNas const &, MapNtN const & >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2335
jpcre2::INFO::VERSION_PRE_RELEASE
static const char VERSION_PRE_RELEASE[]
Alpha or beta (testing) release version.
Definition: jpcre2.hpp:125
jpcre2::select::Char
Char_T Char
Typedef for character (char, wchar_t, char16_t, char32_t)
Definition: jpcre2.hpp:1241
jpcre2::select::RegexMatch::getStartOffset
virtual PCRE2_SIZE getStartOffset() const
Get offset from where match will start in the subject.
Definition: jpcre2.hpp:1649
jpcre2::select::RegexReplace::changeJpcre2Option
RegexReplace & changeJpcre2Option(Uint opt, bool x)
Parse modifier and add/remove equivalent PCRE2 and JPCRE2 options.
Definition: jpcre2.hpp:3385
jpcre2::select::RegexMatch::getSubjectPointer
virtual String const * getSubjectPointer() const
Get pointer to subject string.
Definition: jpcre2.hpp:1600
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< void *, MapNas const &, void * >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2345
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(MatchEvaluator &&me)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2403
jpcre2::select::RegexReplace::getStartOffset
PCRE2_SIZE getStartOffset() const
Get start offset.
Definition: jpcre2.hpp:3144
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< NumSub const &, void *, void * >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2305
jpcre2::ModifierTable::clearMatchModifierTable
ModifierTable & clearMatchModifierTable()
Clear the match modifier table to its initial (empty) state.
Definition: jpcre2.hpp:931
jpcre2::Modifier::length
SIZE_T length() const
Returns the length of the modifier string.
Definition: jpcre2.hpp:659
jpcre2::select::RegexReplace::setModifier
RegexReplace & setModifier(Modifier const &s)
Set the modifier string (resets all JPCRE2 and PCRE2 options) by calling RegexReplace::changeModifier...
Definition: jpcre2.hpp:3285
jpcre2::ModifierTable::setCompileModifierTable
ModifierTable & setCompileModifierTable(std::string const &tabs, const Uint *tabvp)
Set modifier table for compile.
Definition: jpcre2.hpp:1123
jpcre2::select::MatchEvaluator::setModifier
MatchEvaluator & setModifier(Modifier const &s)
Call RegexMatch::setModifier(Modifier const& s).
Definition: jpcre2.hpp:2678
jpcre2::select::MatchEvaluator::setMatchDataBlock
MatchEvaluator & setMatchDataBlock(MatchData *mdt)
Call RegexMatch::setMatchDataBlock(MatchContext * mdt);.
Definition: jpcre2.hpp:2741
jpcre2::Modifier::Modifier
Modifier()
Default constructor.
Definition: jpcre2.hpp:639
jpcre2::select::Regex::compile
void compile(void)
Compile pattern using info from class variables.
Definition: jpcre2.hpp:4422
jpcre2::select::Regex::Regex
Regex(String const &re)
Compile pattern with initialization.
Definition: jpcre2.hpp:3660
jpcre2::select::RegexReplace::getModifierTable
ModifierTable const * getModifierTable()
Get the modifier table that is set,.
Definition: jpcre2.hpp:3138
jpcre2::select::Regex::Regex
Regex()
Default Constructor.
Definition: jpcre2.hpp:3654
jpcre2::select::RegexMatch::setNumberedSubstringVector
virtual RegexMatch & setNumberedSubstringVector(VecNum *v)
Set a pointer to the numbered substring vector.
Definition: jpcre2.hpp:1710
jpcre2::select::RegexMatch::getNamedSubstringVector
virtual VecNas const * getNamedSubstringVector() const
Get pointer to named substring vector.
Definition: jpcre2.hpp:1684
jpcre2::select::RegexReplace::changeModifier
RegexReplace & changeModifier(Modifier const &mod, bool x)
After a call to this function PCRE2 and JPCRE2 options will be properly set.
Definition: jpcre2.hpp:3372
jpcre2::select::NumSub
std::vector< String > NumSub
Vector for Numbered substrings (Sub container).
Definition: jpcre2.hpp:1271
jpcre2::select::RegexReplace::addPcre2Option
RegexReplace & addPcre2Option(Uint x)
Add specified PCRE2 option to existing options for replace.
Definition: jpcre2.hpp:3428
jpcre2::select
struct to select the types.
Definition: jpcre2.hpp:1238
jpcre2::select::Regex::changeModifier
Regex & changeModifier(Modifier const &mod, bool x)
Parse modifier and add/remove equivalent PCRE2 and JPCRE2 options.
Definition: jpcre2.hpp:4070
jpcre2::ModifierTable::setReplaceModifierTableToDefault
ModifierTable & setReplaceModifierTableToDefault()
Set replace modifier table to default.
Definition: jpcre2.hpp:1160
jpcre2::select::MatchEvaluator::setModifierTable
MatchEvaluator & setModifierTable(ModifierTable const *mdt)
Call RegexMatch::setModifierTable(ModifierTable const * s).
Definition: jpcre2.hpp:2686
jpcre2::select::callback::erase
static String erase(void *, void *, void *)
Callback function that removes the matched part/s in the subject string and does not take any match v...
Definition: jpcre2.hpp:2036
jpcre2::Modifier::c_str
char const * c_str() const
Returns the c_str() of modifier string.
Definition: jpcre2.hpp:655
jpcre2::select::RegexReplace::preplace
SIZE_T preplace(void)
Perl compatible replace method.
Definition: jpcre2.hpp:3451
jpcre2::select::VecNtN
std::vector< MapNtN > VecNtN
Vector of substring name to substring number map.
Definition: jpcre2.hpp:1275
jpcre2::Modifier::Modifier
Modifier(std::string const &x)
Constructor that takes a std::string.
Definition: jpcre2.hpp:643
jpcre2::Uint
uint32_t Uint
Used for options (bitwise operation)
Definition: jpcre2.hpp:130
jpcre2::select::Regex::resetErrors
Regex & resetErrors()
Reset regex compile related errors to zero.
Definition: jpcre2.hpp:3857
jpcre2::select::RegexMatch::getMatchEndOffsetVector
virtual VecOff const * getMatchEndOffsetVector() const
Get pre-set match end offset vector pointer.
Definition: jpcre2.hpp:1665
jpcre2::select::getErrorMessage
static String getErrorMessage(int err_num, int err_off)
Returns error message (either JPCRE2 or PCRE2) from error number and error offset.
Definition: jpcre2.hpp:1342
jpcre2::select::RegexReplace::setReplaceWith
RegexReplace & setReplaceWith(String const *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3271
jpcre2::select::RegexReplace::setStartOffset
RegexReplace & setStartOffset(PCRE2_SIZE start_offset)
Set start offset.
Definition: jpcre2.hpp:3311
jpcre2::select::RegexReplace::setPcre2Option
RegexReplace & setPcre2Option(Uint x)
Set PCRE2 option replace (overwrite existing option)
Definition: jpcre2.hpp:3333
jpcre2::select::RegexReplace::getPcre2Option
Uint getPcre2Option() const
Get PCRE2 option.
Definition: jpcre2.hpp:3152
jpcre2::select::RegexReplace::reset
RegexReplace & reset()
Reset all class variables to its default (initial) state including memory.
Definition: jpcre2.hpp:3042
jpcre2::ModifierTable::clearReplaceModifierTable
ModifierTable & clearReplaceModifierTable()
Clear the replace modifier table to its initial (empty) state.
Definition: jpcre2.hpp:942
jpcre2::select::RegexMatch::setSubject
virtual RegexMatch & setSubject(String const *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1774
jpcre2::select::RegexMatch
Provides public constructors to create RegexMatch objects.
Definition: jpcre2.hpp:1375
jpcre2::select::RegexMatch::getErrorOffset
virtual int getErrorOffset() const
Returns the last error offset.
Definition: jpcre2.hpp:1575
jpcre2::select::Regex::Regex
Regex(String const *re)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3667
jpcre2::select::RegexReplace::getModifier
std::string getModifier() const
Calculate modifier string from PCRE2 and JPCRE2 options and return it.
Definition: jpcre2.hpp:3131
jpcre2::select::toString
static String toString(Char a)
Converts a Char_T to jpcre2::select::String.
Definition: jpcre2.hpp:1298
jpcre2::select::Regex::compile
void compile(String const *re)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4198
jpcre2::select::RegexMatch::clear
virtual RegexMatch & clear()
Clear all class variables (may retain some memory for further use).
Definition: jpcre2.hpp:1547
jpcre2::select::VecNas
std::vector< MapNas > VecNas
Vector of matches with named substrings.
Definition: jpcre2.hpp:1273
jpcre2::select::RegexMatch::getNameToNumberMapVector
virtual VecNtN const * getNameToNumberMapVector() const
Get pointer to name to number map vector.
Definition: jpcre2.hpp:1690
jpcre2::select::RegexReplace::getRegexObject
Regex const * getRegexObject() const
Get a pointer to the associated Regex object.
Definition: jpcre2.hpp:3167
jpcre2::select::RegexMatch::setMatchStartOffsetVector
virtual RegexMatch & setMatchStartOffsetVector(VecOff *v)
Set the pointer to a vector to store the offsets where matches start in the subject.
Definition: jpcre2.hpp:1742
jpcre2::select::Regex::initReplace
RegexReplace initReplace()
Returns a default constructed RegexReplace object by value.
Definition: jpcre2.hpp:4264
jpcre2::select::MatchEvaluator::changeModifier
MatchEvaluator & changeModifier(Modifier const &mod, bool x)
Call RegexMatch::changeModifier(Modifier const& mod, bool x).
Definition: jpcre2.hpp:2767
jpcre2::select::Regex::setPattern
Regex & setPattern(String const *re)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:4008
jpcre2::select::RegexMatch::operator=
virtual RegexMatch & operator=(RegexMatch &&rm)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:1522
jpcre2::select::RegexReplace::addModifier
RegexReplace & addModifier(Modifier const &mod)
Parse modifier string and add equivalent PCRE2 and JPCRE2 options.
Definition: jpcre2.hpp:3409
jpcre2::select::RegexMatch::operator=
virtual RegexMatch & operator=(RegexMatch const &rm)
Overloaded copy-assignment operator.
Definition: jpcre2.hpp:1495
jpcre2::select::Regex::addJpcre2Option
Regex & addJpcre2Option(Uint x)
Add option to existing JPCRE2 options for compile.
Definition: jpcre2.hpp:4114
jpcre2::Modifier::Modifier
Modifier(char const *x)
Constructor that takes char const * (null safety is provided by this one)
Definition: jpcre2.hpp:647
jpcre2::select::Regex::Regex
Regex(String const *re, Uint po)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:3699
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(MatchEvaluator const &me)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2379
jpcre2::select::RegexMatch::getMatchStartOffsetVector
virtual VecOff const * getMatchStartOffsetVector() const
Get pre-set match start offset vector pointer.
Definition: jpcre2.hpp:1657
jpcre2::select::MatchEvaluator
This class inherits RegexMatch and provides a similar functionality.
Definition: jpcre2.hpp:2135
jpcre2::select::Regex::getErrorOffset
int getErrorOffset() const
Returns the last error offset.
Definition: jpcre2.hpp:3940
jpcre2::select::MatchEvaluator::MatchEvaluator
MatchEvaluator(typename MatchEvaluatorCallback< void *, void *, void * >::Callback mef)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: jpcre2.hpp:2295
jpcre2::select::MatchEvaluator::addPcre2Option
MatchEvaluator & addPcre2Option(Uint x)
Call RegexMatch::addPcre2Option(Uint x).
Definition: jpcre2.hpp:2809