#include <op_regex.h>
Data Structures | |
struct | replace_t |
Public Member Functions | |
regular_expression_replace (size_t limit=100, size_t limit_defs_expansion=100) | |
~regular_expression_replace () | |
void | add_definition (std::string const &name, std::string const &replace) |
void | add_pattern (std::string const &pattern, std::string const &replace) |
bool | execute (std::string &str) const |
Private Types | |
typedef std::map< std::string, std::string > | defs_dict |
dictionary of regular definition | |
Private Member Functions | |
bool | do_execute (std::string &str, replace_t const ®exp) const |
void | do_replace (std::string &str, std::string const &replace, regmatch_t const *match) const |
std::string | expand_string (std::string const &input) |
std::string | substitute_definition (std::string const &pattern) |
regmatch_t const & | get_match (regmatch_t const *match, char idx) const |
Private Attributes | |
size_t | limit |
size_t | limit_defs_expansion |
std::vector< replace_t > | regex_replace |
defs_dict | defs |
Static Private Attributes | |
static const size_t | max_match = 16 |
lightweight encapsulation of regex lib search and replace
See stl.pat for further details and examples of used syntax.
Definition at line 39 of file op_regex.h.
typedef std::map<std::string, std::string> regular_expression_replace::defs_dict [private] |
dictionary of regular definition
Definition at line 117 of file op_regex.h.
regular_expression_replace::regular_expression_replace | ( | size_t | limit = 100 , |
|
size_t | limit_defs_expansion = 100 | |||
) |
limit | limit on number of search and replace done | |
limit_defs_expansion | limit on number of expansion done during replacement of regular definition name by their expansion |
build an object holding regular defintion and regular expression & replace, preparing it for substitution ala sed
Definition at line 80 of file op_regex.cpp.
regular_expression_replace::~regular_expression_replace | ( | ) |
Definition at line 89 of file op_regex.cpp.
References regex_replace.
void regular_expression_replace::add_definition | ( | std::string const & | name, | |
std::string const & | replace | |||
) |
name | a regular definition name | |
replace | the string to subsitute in other regular definition or regular exepression when this regular defintion name is encoutered. |
Referenced by setup_regex().
void regular_expression_replace::add_pattern | ( | std::string const & | pattern, | |
std::string const & | replace | |||
) |
pattern | a regular expression pattern, POSIX extended notation | |
replace | the replace string to use when this regular expression is matched |
You can imbed regular definition in pattern but not in replace.
Referenced by setup_regex().
bool regular_expression_replace::do_execute | ( | std::string & | str, | |
replace_t const & | regexp | |||
) | const [private] |
void regular_expression_replace::do_replace | ( | std::string & | str, | |
std::string const & | replace, | |||
regmatch_t const * | match | |||
) | const [private] |
bool regular_expression_replace::execute | ( | std::string & | str | ) | const |
str | the input/output string where we search pattern and replace them. |
Execute loop at max limit time on the set of regular expression
Return true if too many match occur and replacing has been stopped due to reach limit_defs_expansion. You can test if some pattern has been matched by saving the input string and comparing it to the new value. There is no way to detect s/a/a because the output string will be identical to the input string.
Referenced by demangle_symbol(), do_test(), and setup_regex().
std::string regular_expression_replace::expand_string | ( | std::string const & | input | ) | [private] |
regmatch_t const & regular_expression_replace::get_match | ( | regmatch_t const * | match, | |
char | idx | |||
) | const [private] |
Definition at line 205 of file op_regex.cpp.
References max_match.
std::string regular_expression_replace::substitute_definition | ( | std::string const & | pattern | ) | [private] |
defs_dict regular_expression_replace::defs [private] |
Definition at line 118 of file op_regex.h.
size_t regular_expression_replace::limit [private] |
Definition at line 113 of file op_regex.h.
size_t regular_expression_replace::limit_defs_expansion [private] |
Definition at line 114 of file op_regex.h.
const size_t regular_expression_replace::max_match = 16 [static, private] |
Definition at line 111 of file op_regex.h.
Referenced by get_match().
std::vector<replace_t> regular_expression_replace::regex_replace [private] |
Definition at line 115 of file op_regex.h.
Referenced by ~regular_expression_replace().