JPCRE2  10.31.04
C++ wrapper for PCRE2 library
jpcre2.hpp File Reference

Main header file for JPCRE2 library to be included by programs that uses its functionalities. It includes the pcre2.h header, therefore you shouldn't include pcre2.h, neither should you define PCRE2_CODE_UNIT_WIDTH before including jpcre2.hpp. If your pcre2.h header is not in standard include paths, you may include pcre2.h with correct path before including jpcre2.hpp manually. In this case you will have to define PCRE2_CODE_UNIT_WIDTH before including pcre2.h. Make sure to link required PCRE2 libraries when compiling. More...

#include <pcre2.h>
#include <string>
#include <vector>
#include <map>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <utility>
#include <functional>
+ Include dependency graph for jpcre2.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  jpcre2::Modifier
 Class to take a std::string modifier value with null safety. More...
 
class  jpcre2::ModifierTable
 Lets you create custom modifier tables. More...
 
struct  jpcre2::select< Char_T, Map >
 struct to select the types. More...
 
class  jpcre2::select< Char_T, Map >::RegexMatch
 Provides public constructors to create RegexMatch objects. More...
 
struct  jpcre2::select< Char_T, Map >::MatchEvaluatorCallback< T1, T2, T3 >
 This class contains a typedef of a function pointer or a templated function wrapper (std::function) to provide callback function to the MatchEvaluator. More...
 
struct  jpcre2::select< Char_T, Map >::callback
 Provides some default static callback functions. More...
 
class  jpcre2::select< Char_T, Map >::MatchEvaluator
 This class inherits RegexMatch and provides a similar functionality. More...
 
class  jpcre2::select< Char_T, Map >::RegexReplace
 Provides public constructors to create RegexReplace objects. More...
 
class  jpcre2::select< Char_T, Map >::Regex
 Provides public constructors to create Regex object. More...
 

Namespaces

 jpcre2
 
 jpcre2::INFO
 
 jpcre2::ERROR
 

Macros

#define PCRE2_CODE_UNIT_WIDTH   0
 
#define JPCRE2_ASSERT(cond, msg)   jpcre2::jassert(cond, msg, __FILE__, __LINE__)
 
#define JPCRE2_VERSION   103104L
 Define for JPCRE2 version. More...
 
#define JPCRE2_USE_FUNCTION_POINTER_CALLBACK
 
#define JPCRE2_NDEBUG
 

Typedefs

typedef PCRE2_SIZE jpcre2::SIZE_T
 Used for match count and vector size. More...
 
typedef uint32_t jpcre2::Uint
 Used for options (bitwise operation) More...
 
typedef uint8_t jpcre2::Ush
 8 bit unsigned integer. More...
 
typedef std::vector< SIZE_T > jpcre2::VecOff
 vector of size_t. More...
 
typedef std::vector< Uint > jpcre2::VecOpt
 vector for Uint option values. More...
 

Enumerations

enum  {
  jpcre2::ERROR::INVALID_MODIFIER = 2,
  jpcre2::ERROR::INSUFFICIENT_OVECTOR = 3
}
 Error numbers for JPCRE2. More...
 
enum  {
  jpcre2::NONE = 0x0000000u,
  jpcre2::FIND_ALL = 0x0000002u,
  jpcre2::JIT_COMPILE = 0x0000004u
}
 These constants provide JPCRE2 options. More...
 

Functions

static void jpcre2::jassert (bool cond, const char *msg, const char *f, size_t line)
 JPCRE2 assert function. More...
 

Variables

static const char jpcre2::INFO::NAME [] = "JPCRE2"
 Name of the project. More...
 
static const char jpcre2::INFO::FULL_VERSION [] = "10.31.04"
 Full version string. More...
 
static const char jpcre2::INFO::VERSION_GENRE [] = "10"
 Generation, depends on original PCRE2 version. More...
 
static const char jpcre2::INFO::VERSION_MAJOR [] = "31"
 Major version, updated when API change is made. More...
 
static const char jpcre2::INFO::VERSION_MINOR [] = "04"
 Minor version, includes bug fix or minor feature upgrade. More...
 
static const char jpcre2::INFO::VERSION_PRE_RELEASE [] = ""
 Alpha or beta (testing) release version. More...
 

Detailed Description

Main header file for JPCRE2 library to be included by programs that uses its functionalities. It includes the pcre2.h header, therefore you shouldn't include pcre2.h, neither should you define PCRE2_CODE_UNIT_WIDTH before including jpcre2.hpp. If your pcre2.h header is not in standard include paths, you may include pcre2.h with correct path before including jpcre2.hpp manually. In this case you will have to define PCRE2_CODE_UNIT_WIDTH before including pcre2.h. Make sure to link required PCRE2 libraries when compiling.

Author
Md Jahidul Hamid

Macro Definition Documentation

◆ JPCRE2_ASSERT

#define JPCRE2_ASSERT (   cond,
  msg 
)    jpcre2::jassert(cond, msg, __FILE__, __LINE__)

Macro to call jpcre2::jassert() with file path and line number. When NDEBUG or JPCRE2_NDEBUG is defined before including this header, this macro will be defined as ((void)0) thus eliminating this assertion.

Parameters
condcondtion (boolean)
msgmessage

◆ JPCRE2_NDEBUG

#define JPCRE2_NDEBUG

Macro to remove debug codes. Using this macro is discouraged even in production mode but provided for completeness. You should not use this macro to bypass any error in your program. Define this macro before including this header if you want to remove debug codes included in this library.

Using the standard NDEBUG macro will have the same effect, but it is recommended that you use JPCRE2_NDEBUG to strip out debug codes specifically for this library.

◆ JPCRE2_USE_FUNCTION_POINTER_CALLBACK

#define JPCRE2_USE_FUNCTION_POINTER_CALLBACK

Use function pointer in all cases for MatchEvaluatorCallback function. By default function pointer is used for callback in MatchEvaluator when using <C++11 compiler, but for >=C++11 compiler std::function instead of function pointer is used. If this macro is defined before including jpcre2.hpp, function pointer will be used in all cases. It you are using lambda function with captures, stick with std::function, on the other hand, if you are using older compilers, you might want to use function pointer instead.

For example, with gcc-4.7, std::function will give compile error in C++11 mode, in such cases where full C++11 support is not available, use function pointer.

◆ JPCRE2_VERSION

#define JPCRE2_VERSION   103104L

Define for JPCRE2 version.

It can be used to support changes in different versions of the lib.

◆ PCRE2_CODE_UNIT_WIDTH

#define PCRE2_CODE_UNIT_WIDTH   0

This macro does not have any significance in JPCRE2 context. It is defined as 0 by default. Defining it before including jpcre2.hpp will override the default (discouraged as it will make it harder for you to detect problems), but still it will have no effect in a JPCRE2 perspective. Defining it with an invalid value will yield to compile error.

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::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::select::RegexMatch::setNamedSubstringVector
virtual RegexMatch & setNamedSubstringVector(VecNas *v)
Set a pointer to the named substring vector.
Definition: jpcre2.hpp:1721
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::Regex::preplace
SIZE_T preplace(String *mains, String const &repl, Modifier const &mod="")
Perl compatible replace method.
Definition: jpcre2.hpp:4332
jpcre2::select::RegexReplace::changePcre2Option
RegexReplace & changePcre2Option(Uint opt, bool x)
Add or remove a PCRE2 option.
Definition: jpcre2.hpp:3396
jpcre2::ModifierTable::clear
ModifierTable & clear()
Clear the modifier tables to their initial (empty) state.
Definition: jpcre2.hpp:964
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::RegexMatch::setSubject
virtual RegexMatch & setSubject(String const &s)
Set the subject string for match.
Definition: jpcre2.hpp:1762
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::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::MapNtN
class Map< String, SIZE_T > MapNtN
Substring name to Substring number map.
Definition: jpcre2.hpp:1259
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::replace
String replace(void)
Perform regex replace by retrieving subject string, replacement string, modifier and other options fr...
Definition: jpcre2.hpp:4654
jpcre2::select::RegexMatch::setRegexObject
virtual RegexMatch & setRegexObject(Regex const *r)
Set the associated regex object.
Definition: jpcre2.hpp:1699
jpcre2::select::Regex::setPattern
Regex & setPattern(String const &re)
Set the pattern string to compile.
Definition: jpcre2.hpp:3999
jpcre2::select::RegexReplace::getLastReplaceCount
SIZE_T getLastReplaceCount()
Get the number of replacement in last replace operation.
Definition: jpcre2.hpp:3196
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::ModifierTable
Lets you create custom modifier tables.
Definition: jpcre2.hpp:832
jpcre2::select::RegexReplace::setReplaceWith
RegexReplace & setReplaceWith(String const &s)
Set the replacement string.
Definition: jpcre2.hpp:3261
jpcre2::select::MapNtn
MapNtN MapNtn
Allow spelling mistake of MapNtN as MapNtn.
Definition: jpcre2.hpp:1268
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::VecNum
std::vector< NumSub > VecNum
Vector of matches with numbered substrings.
Definition: jpcre2.hpp:1279
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::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_ASSERT
#define JPCRE2_ASSERT(cond, msg)
jpcre2::select::Regex::setModifierTable
Regex & setModifierTable(ModifierTable const *mdt)
Set a custom modifier table to be used.
Definition: jpcre2.hpp:4033
jpcre2::ModifierTable::setReplaceModifierTable
ModifierTable & setReplaceModifierTable(std::string const &tabs, VecOpt const &tabv)
Set modifier table for replace.
Definition: jpcre2.hpp:1073
jpcre2::select::MapNas
class Map< String, String > MapNas
Map for Named substrings.
Definition: jpcre2.hpp:1257
jpcre2::ModifierTable::setAllToDefault
ModifierTable & setAllToDefault()
Set all tables to default.
Definition: jpcre2.hpp:1180
jpcre2::FIND_ALL
@ FIND_ALL
Find all during match (global match)
Definition: jpcre2.hpp:153
jpcre2.hpp
Main header file for JPCRE2 library to be included by programs that uses its functionalities....
jpcre2::VecOff
std::vector< SIZE_T > VecOff
vector of size_t.
Definition: jpcre2.hpp:132
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:4772
jpcre2::Modifier
Class to take a std::string modifier value with null safety.
Definition: jpcre2.hpp:634
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::RegexReplace::setSubject
RegexReplace & setSubject(String const &s)
Set the subject string for replace.
Definition: jpcre2.hpp:3227
jpcre2::select::Regex
Provides public constructors to create Regex object.
Definition: jpcre2.hpp:3550
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::select::Regex::compile
void compile(void)
Compile pattern using info from class variables.
Definition: jpcre2.hpp:4422
jpcre2::select::RegexMatch::setNumberedSubstringVector
virtual RegexMatch & setNumberedSubstringVector(VecNum *v)
Set a pointer to the numbered substring vector.
Definition: jpcre2.hpp:1710
jpcre2::select::NumSub
std::vector< String > NumSub
Vector for Numbered substrings (Sub container).
Definition: jpcre2.hpp:1271
jpcre2::select
struct to select the types.
Definition: jpcre2.hpp:1238
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::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::Uint
uint32_t Uint
Used for options (bitwise operation)
Definition: jpcre2.hpp:130
jpcre2::select::RegexMatch
Provides public constructors to create RegexMatch objects.
Definition: jpcre2.hpp:1375
jpcre2::select::VecNas
std::vector< MapNas > VecNas
Vector of matches with named substrings.
Definition: jpcre2.hpp:1273
jpcre2::select::Regex::initReplace
RegexReplace initReplace()
Returns a default constructed RegexReplace object by value.
Definition: jpcre2.hpp:4264
jpcre2::select::MatchEvaluator
This class inherits RegexMatch and provides a similar functionality.
Definition: jpcre2.hpp:2135