regular_expression_replace Class Reference

#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 &regexp) 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_tregex_replace
defs_dict defs

Static Private Attributes

static const size_t max_match = 16

Detailed Description

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.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

regular_expression_replace::regular_expression_replace ( size_t  limit = 100,
size_t  limit_defs_expansion = 100 
)
Parameters:
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.


Member Function Documentation

void regular_expression_replace::add_definition ( std::string const &  name,
std::string const &  replace 
)
Parameters:
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().

Here is the caller graph for this function:

void regular_expression_replace::add_pattern ( std::string const &  pattern,
std::string const &  replace 
)
Parameters:
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().

Here is the caller graph for this function:

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
Parameters:
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().

Here is the caller graph for this function:

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]

Field Documentation

Definition at line 118 of file op_regex.h.

Definition at line 113 of file op_regex.h.

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().

Definition at line 115 of file op_regex.h.

Referenced by ~regular_expression_replace().


The documentation for this class was generated from the following files:

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1