![]() |
JPCRE2
10.32.01
C++ wrapper for PCRE2 library
|
Provides public constructors to create RegexReplace objects. More...
#include <jpcre2.hpp>
Public Member Functions | |
RegexReplace () | |
Default constructor. More... | |
RegexReplace (Regex const *r) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ... More... | |
RegexReplace (RegexReplace const &rr) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ... More... | |
RegexReplace & | operator= (RegexReplace const &rr) |
Overloaded Copy assignment operator. More... | |
RegexReplace (RegexReplace &&rr) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ... More... | |
RegexReplace & | operator= (RegexReplace &&rr) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ... More... | |
RegexReplace & | reset () |
Reset all class variables to its default (initial) state including memory. More... | |
RegexReplace & | clear () |
Clear all class variables to its default (initial) state (some memory may retain for further use). More... | |
RegexReplace & | resetErrors () |
Reset replace related errors to zero. More... | |
int | getErrorNumber () const |
Returns the last error number. More... | |
int | getErrorOffset () const |
Returns the last error offset. More... | |
String | getErrorMessage () const |
Returns the last error message. More... | |
String | getReplaceWith () const |
Get replacement string. More... | |
String const * | getReplaceWithPointer () const |
Get pointer to replacement string. More... | |
String | getSubject () const |
Get subject string. More... | |
String const * | getSubjectPointer () const |
Get pointer to subject string. More... | |
std::string | getModifier () const |
Calculate modifier string from PCRE2 and JPCRE2 options and return it. More... | |
ModifierTable const * | getModifierTable () |
Get the modifier table that is set,. More... | |
PCRE2_SIZE | getStartOffset () const |
Get start offset. More... | |
Uint | getPcre2Option () const |
Get PCRE2 option. More... | |
Uint | getJpcre2Option () const |
Get JPCRE2 option. More... | |
Regex const * | getRegexObject () const |
Get a pointer to the associated Regex object. More... | |
MatchContext * | getMatchContext () |
Return pointer to the match context that was previously set with setMatchContext(). More... | |
virtual MatchData * | getMatchDataBlock () |
Get the pointer to the match data block that was set previously with setMatchData() Handling memory is the callers' responsibility. More... | |
PCRE2_SIZE | getBufferSize () |
Get the initial buffer size that is being used by internal function pcre2_substitute. More... | |
SIZE_T | getLastReplaceCount () |
Get the number of replacement in last replace operation. More... | |
RegexReplace & | setReplaceCounter (SIZE_T *counter) |
Set an external counter variable to store the replacement count. More... | |
RegexReplace & | setRegexObject (Regex const *r) |
Set the associated Regex object. More... | |
RegexReplace & | setSubject (String const &s) |
Set the subject string for replace. More... | |
RegexReplace & | setSubject (String *s) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ... More... | |
RegexReplace & | setReplaceWith (String const &s) |
Set the replacement string. More... | |
RegexReplace & | setReplaceWith (String const *s) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ... More... | |
RegexReplace & | setModifier (Modifier const &s) |
Set the modifier string (resets all JPCRE2 and PCRE2 options) by calling RegexReplace::changeModifier(). More... | |
RegexReplace & | setModifierTable (ModifierTable const *mdt) |
Set a custom modifier table to be used. More... | |
RegexReplace & | setBufferSize (PCRE2_SIZE x) |
Set the initial buffer size to be allocated for replaced string (used by PCRE2) More... | |
RegexReplace & | setStartOffset (PCRE2_SIZE start_offset) |
Set start offset. More... | |
RegexReplace & | setJpcre2Option (Uint x) |
Set JPCRE2 option for replace (overwrite existing option) More... | |
RegexReplace & | setPcre2Option (Uint x) |
Set PCRE2 option replace (overwrite existing option) More... | |
RegexReplace & | setMatchContext (MatchContext *match_context) |
Set the match context to be used. More... | |
RegexReplace & | setMatchDataBlock (MatchData *match_data) |
Set the match data block to be used. More... | |
RegexReplace & | changeModifier (Modifier const &mod, bool x) |
After a call to this function PCRE2 and JPCRE2 options will be properly set. More... | |
RegexReplace & | changeJpcre2Option (Uint opt, bool x) |
Parse modifier and add/remove equivalent PCRE2 and JPCRE2 options. More... | |
RegexReplace & | changePcre2Option (Uint opt, bool x) |
Add or remove a PCRE2 option. More... | |
RegexReplace & | addModifier (Modifier const &mod) |
Parse modifier string and add equivalent PCRE2 and JPCRE2 options. More... | |
RegexReplace & | addJpcre2Option (Uint x) |
Add specified JPCRE2 option to existing options for replace. More... | |
RegexReplace & | addPcre2Option (Uint x) |
Add specified PCRE2 option to existing options for replace. More... | |
String | replace (void) |
Perform regex replace by retrieving subject string, replacement string, modifier and other options from class variables. More... | |
SIZE_T | preplace (void) |
Perl compatible replace method. More... | |
SIZE_T | preplace (MatchEvaluator me) |
Perl compatible replace method with match evaluator. More... | |
String | nreplace (MatchEvaluator me) |
JPCRE2 native replace function. More... | |
String | replace (MatchEvaluator me) |
PCRE2 compatible replace function that takes a MatchEvaluator. More... | |
Provides public constructors to create RegexReplace objects.
Every RegexReplace object should be associated with a Regex object. This class stores a pointer to its' associated Regex object, thus when the content of the associated Regex object is changed, there's no need to set the pointer again.
Examples:
|
inline |
Default constructor.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ...
Creates a RegexReplace object associating a Regex object. Regex object is not modified.
r | pointer to a Regex object |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ...
Copy constructor.
rr | RegexReplace object reference |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ...
Move constructor. This constructor steals resources from the argument. It leaves the argument in a valid but indeterminate sate. The indeterminate state can be returned to normal by calling reset() on that object.
rr | rvalue reference to a RegexReplace object reference |
|
inline |
Add specified JPCRE2 option to existing options for replace.
x | Option value |
|
inline |
Parse modifier string and add equivalent PCRE2 and JPCRE2 options.
This is just a wrapper of the original function RegexReplace::changeModifier() provided for convenience.
mod | Modifier string. |
References jpcre2::select< Char_T, Map >::RegexReplace::changeModifier().
|
inline |
Add specified PCRE2 option to existing options for replace.
x | Option value |
|
inline |
Parse modifier and add/remove equivalent PCRE2 and JPCRE2 options.
Add or remove a JPCRE2 option
opt | JPCRE2 option value |
x | Add the option if it's true, remove otherwise. |
|
inline |
After a call to this function PCRE2 and JPCRE2 options will be properly set.
This function does not initialize or re-initialize options. If you want to set options from scratch, initialize them to 0 before calling this function.
If invalid modifier is detected, then the error number for the RegexReplace object will be jpcre2::ERROR::INVALID_MODIFIER and error offset will be the modifier character. You can get the message with RegexReplace::getErrorMessage() function.
mod | Modifier string. |
x | Whether to add or remove option |
References jpcre2::ModifierTable::toReplaceOption().
Referenced by jpcre2::select< Char_T, Map >::RegexReplace::addModifier(), and jpcre2::select< Char_T, Map >::RegexReplace::setModifier().
|
inline |
Add or remove a PCRE2 option.
opt | PCRE2 option value |
x | Add the option if it's true, remove otherwise. |
|
inline |
Clear all class variables to its default (initial) state (some memory may retain for further use).
References jpcre2::select< Char_T, Map >::RegexReplace::clear().
Referenced by jpcre2::select< Char_T, Map >::RegexReplace::clear(), jpcre2::select< Char_T, Map >::RegexReplace::setReplaceWith(), and jpcre2::select< Char_T, Map >::RegexReplace::setSubject().
|
inline |
Get the initial buffer size that is being used by internal function pcre2_substitute.
|
inline |
Returns the last error message.
References jpcre2::select< Char_T, Map >::getErrorMessage().
|
inline |
Returns the last error number.
|
inline |
Returns the last error offset.
|
inline |
Get JPCRE2 option.
|
inline |
Get the number of replacement in last replace operation.
If you set an external counter with RegexReplace::setReplaceCounter(), a call to this getter method will dereference the pointer to the external counter and return the value.
|
inline |
Return pointer to the match context that was previously set with setMatchContext().
Handling memory is the callers' responsibility.
|
inlinevirtual |
Get the pointer to the match data block that was set previously with setMatchData() Handling memory is the callers' responsibility.
|
inline |
Calculate modifier string from PCRE2 and JPCRE2 options and return it.
Do remember that modifiers (or PCRE2 and JPCRE2 options) do not change or get initialized as long as you don't do that explicitly. Calling RegexReplace::setModifier() will re-set them.
Mixed or combined modifier.
Some modifier may include other modifiers i.e they have the same meaning of some modifiers combined together. For example, the 'n' modifier includes the 'u' modifier and together they are equivalent to PCRE2_UTF | PCRE2_UCP
. When you set a modifier like this, both options get set, and when you remove the 'n' modifier (with RegexReplace::changeModifier()
), both will get removed.
References jpcre2::ModifierTable::fromReplaceOption().
|
inline |
Get the modifier table that is set,.
|
inline |
Get PCRE2 option.
|
inline |
|
inline |
Get replacement string.
|
inline |
Get pointer to replacement string.
|
inline |
Get start offset.
|
inline |
|
inline |
Get pointer to subject string.
|
inline |
JPCRE2 native replace function.
A different name is adopted to distinguish itself from the regular replace() function which uses pcre2_substitute() to do the replacement; contrary to that, it will provide a JPCRE2 native way of replacement operation. It takes a MatchEvaluator object which provides a callback function that is used to generate replacement string on the fly. Any replacement string set with RegexReplace::setReplaceWith()
function will have no effect. The string returned by the callback function will be treated as literal and will not go through any further processing.
This function works on a copy of the MatchEvaluator, and thus makes no changes to the original. The copy is modified as below:
PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT
will be removed.It calls MatchEvaluator::nreplace() on the MatchEvaluator object to perform the replacement.
It always performs a new match.
me | A MatchEvaluator object. |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ...
Overloaded move assignment operator. This constructor steals resources from the argument. It leaves the argument in a valid but indeterminate sate. The indeterminate state can be returned to normal by calling reset() on that object.
rr | rvalue reference to a RegexReplace object reference |
|
inline |
Overloaded Copy assignment operator.
rr | RegexReplace object reference |
|
inline |
Perl compatible replace method with match evaluator.
Modifies subject string in-place and returns replace count. MatchEvaluator class does not have a implementation of this replace method, thus it is not possible to re-use match data with preplace() method. Re-using match data with preplace doesn't actually make any sense, because new subject will always require new match data.
The replacement is performed with RegexReplace::replace()
which uses pcre2_substitute()
.
me | MatchEvaluator object. |
|
inline |
Perl compatible replace method.
Modifies subject string in-place and returns replace count.
The replacement is performed with RegexReplace::replace()
which uses pcre2_substitute()
.
References jpcre2::select< Char_T, Map >::RegexReplace::replace().
|
inline |
PCRE2 compatible replace function that takes a MatchEvaluator.
String returned by callback function is processed by pcre2_substitute, thus all PCRE2 substitute options are supported by this replace function.
It always performs a new match.
me | MatchEvaluator instance, (copied and modified according to this object). |
jpcre2::select< Char_T, Map >::String jpcre2::select< Char_T, Map >::RegexReplace::replace | ( | void | ) |
Perform regex replace by retrieving subject string, replacement string, modifier and other options from class variables.
In the replacement string (see RegexReplace::setReplaceWith()) $
is a special character which implies captured group.
$n
or ${n}
where n is the group number.${name}
, where 'name' is the group name.$
can be given as $$
.All options supported by pcre2_substitute is available.
Note: This function calls pcre2_substitute() to do the replacement.
Referenced by jpcre2::select< Char_T, Map >::RegexReplace::preplace(), jpcre2::select< Char_T, Map >::Regex::preplace(), and jpcre2::select< Char_T, Map >::Regex::replace().
|
inline |
Reset all class variables to its default (initial) state including memory.
|
inline |
Reset replace related errors to zero.
|
inline |
Set the initial buffer size to be allocated for replaced string (used by PCRE2)
x | Buffer size |
|
inline |
Set JPCRE2 option for replace (overwrite existing option)
x | Option value |
|
inline |
Set the match context to be used.
Native PCRE2 API may be used to create match context. The memory of the match context is not handled by RegexReplace object and not freed. User will be responsible for freeing memory.
match_context | Pointer to match context. |
|
inline |
Set the match data block to be used.
Native PCRE2 API may be used to create match data block. The memory of the match data is not handled by RegexReplace object and not freed. User will be responsible for creating/freeing memory.
match_data | Pointer to match data. |
|
inline |
Set the modifier string (resets all JPCRE2 and PCRE2 options) by calling RegexReplace::changeModifier().
s | Modifier string. |
References jpcre2::select< Char_T, Map >::RegexReplace::changeModifier().
Referenced by jpcre2::select< Char_T, Map >::Regex::preplace(), and jpcre2::select< Char_T, Map >::Regex::replace().
|
inline |
Set a custom modifier table to be used.
mdt | pointer to ModifierTable object. |
|
inline |
Set PCRE2 option replace (overwrite existing option)
x | Option value |
|
inline |
Set the associated Regex object.
Regex object is not modified.
r | Pointer to a Regex object. |
|
inline |
Set an external counter variable to store the replacement count.
This counter will be updated after each replacement operation on this object. A call to this method will reset the internal counter to 0, thus when you reset the counter to internal counter (by giving null as param), the previous replace count won't be available.
counter | Pointer to a counter variable. Null sets the counter to default internal counter. |
Referenced by jpcre2::select< Char_T, Map >::Regex::preplace(), and jpcre2::select< Char_T, Map >::Regex::replace().
|
inline |
Set the replacement string.
$
is a special character which implies captured group.
$n
or ${n}
where n is the group number.${name}
, where 'name' is the group name.$
can be given as $$
.Note: This function makes a copy of the string. If no copy is desired or you are working with big text, consider passing the string with pointer.
s | String to replace with |
Referenced by jpcre2::select< Char_T, Map >::Regex::preplace(), and jpcre2::select< Char_T, Map >::Regex::replace().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ...
s | Pointer to the string to replace with, null pointer unsets it. |
References jpcre2::select< Char_T, Map >::RegexReplace::clear().
|
inline |
Set start offset.
Set the offset where matching starts for replace operation
start_offset | The offset where matching starts for replace operation |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ...
Set pointer to the subject string for replace, null pointer unsets it. The underlined data is not modified unless RegexReplace::preplace() method is used.
s | Pointer to subject string |
References jpcre2::select< Char_T, Map >::RegexReplace::clear().
|
inline |
Set the subject string for replace.
This makes a copy of the string. If no copy is desired or you are working with big text, consider passing by pointer.
s | Subject string |
Referenced by jpcre2::select< Char_T, Map >::Regex::preplace(), and jpcre2::select< Char_T, Map >::Regex::replace().