srchilite::RegexPreProcessor Class Reference

preprocess a regular expression, e.g., transform "()" into "(?:)" More...

#include <regexpreprocessor.h>

List of all members.

Static Public Member Functions

static const std::string replace_references (const std::string &original, const backreference_replacements &replace)
 Replace into the original string occurrences of backreferences with the corresponding string in the replace parameter, i.e., n} backreference will be replaced with replace[n-1].
static const std::string replace_references (const std::string &original, const regex_match_results &results)
 Replace into the original string occurrences of backreferences with the corresponding subexpressions that matched in the results.
static const std::string preprocess (const std::string &s)
 translates marked subexpressions (.
static const std::string make_nonsensitive (const std::string &s)
 translates the expression into a case nonsensitive expression, i.e., foo is translated into [Ff][Oo][Oo]
static unsigned int num_of_subexpressions (const std::string &s)
 counts the number of marked subexpressions (.
static subexpressions_info num_of_marked_subexpressions (const std::string &s, bool allow_outer_char=false, bool allow_outer_nonmarked=false)
 check that the expressions is made up of marked subexpressions (.
static const
subexpressions_strings
split_marked_subexpressions (const std::string &s)
 Splits the marked subexpressions of a regular expression made up of only marked subexpressions and no nested subexpressions and char outside subexpressions (thus, before calling this, you must make sure that num_of_marked_subexpressions did not return an error.
static bool contains_backreferences (const std::string &s)
 Checks whether the passed regular expression string contains a backreference (e.g., either or a conditional with a backreference (?(1).
static backreference_info num_of_backreferences (const std::string &s)
 counts the number of backreferences (also in conditionals)
static backreference_info num_of_references (const std::string &s)
 counts the number of references (i.e., reference to a matched subexpression of another regular expression)
static const std::string replace_backreferences (const std::string &original, const backreference_replacements &replace)
 Replace into the original string occurrences of backreferences with the corresponding string in the replace parameter, i.e.,
backreference will be replaced with replace[n-1].
static const std::string replace_backreferences (const std::string &original, const regex_match_results &results)
 Replace into the original string occurrences of backreferences with the corresponding subexpressions that matched in the results.


Detailed Description

preprocess a regular expression, e.g., transform "()" into "(?:)"

Member Function Documentation

bool srchilite::RegexPreProcessor::contains_backreferences ( const std::string &  s  )  [static]

Checks whether the passed regular expression string contains a backreference (e.g., either or a conditional with a backreference (?(1).

..)

Returns:
true if the passed regular expression string contains a backreference

const string srchilite::RegexPreProcessor::make_nonsensitive ( const std::string &  s  )  [static]

translates the expression into a case nonsensitive expression, i.e., foo is translated into [Ff][Oo][Oo]

Returns:
the translated string

backreference_info srchilite::RegexPreProcessor::num_of_backreferences ( const std::string &  s  )  [static]

counts the number of backreferences (also in conditionals)

Parameters:
s 
Returns:
the number of backreferences and the highest backreference number

subexpressions_info srchilite::RegexPreProcessor::num_of_marked_subexpressions ( const std::string &  s,
bool  allow_outer_char = false,
bool  allow_outer_nonmarked = false 
) [static]

check that the expressions is made up of marked subexpressions (.

..) and no nested subexpressions and no char outside subexpressions (unless allow_outer_char is true).

Non-marked groups are allowed only if allow_outer_nonmarked is true.

Parameters:
s 
allow_outer_char whether we allow characters outside marked subexps
allow_outer_nonmarked whether we allow outer nonmarked subexps
Returns:
the struct containing the number of marked subexpressions and possible errors

backreference_info srchilite::RegexPreProcessor::num_of_references ( const std::string &  s  )  [static]

counts the number of references (i.e., reference to a matched subexpression of another regular expression)

Parameters:
s 
Returns:
the number of backreferences and the highest backreference number

unsigned int srchilite::RegexPreProcessor::num_of_subexpressions ( const std::string &  s  )  [static]

counts the number of marked subexpressions (.

..)

Parameters:
s 
Returns:
the number of marked subexpressions

const string srchilite::RegexPreProcessor::preprocess ( const std::string &  s  )  [static]

translates marked subexpressions (.

..) into non marked subexpressions (?: )

Returns:
the translated string

const std::string srchilite::RegexPreProcessor::replace_backreferences ( const std::string &  original,
const regex_match_results results 
) [static]

Replace into the original string occurrences of backreferences with the corresponding subexpressions that matched in the results.

Notice that we assume that the results come from a regular expression without nested subexpressions.

Warning:
For the moment this is never used but in testing
Parameters:
original 
results 
Returns:
the result of the replacement

const std::string srchilite::RegexPreProcessor::replace_backreferences ( const std::string &  original,
const backreference_replacements replace 
) [static]

Replace into the original string occurrences of backreferences with the corresponding string in the replace parameter, i.e.,
backreference will be replaced with replace[n-1].

Warning:
For the moment this is never used but in testing
Parameters:
original 
replace 
Returns:
the result of the replacement

const string srchilite::RegexPreProcessor::replace_references ( const std::string &  original,
const regex_match_results results 
) [static]

Replace into the original string occurrences of backreferences with the corresponding subexpressions that matched in the results.

Notice that we assume that the results come from a regular expression without nested subexpressions.

Parameters:
original 
results 
Returns:
the result of the replacement

const string srchilite::RegexPreProcessor::replace_references ( const std::string &  original,
const backreference_replacements replace 
) [static]

Replace into the original string occurrences of backreferences with the corresponding string in the replace parameter, i.e., n} backreference will be replaced with replace[n-1].

Parameters:
original 
replace 
Returns:
the result of the replacement

const subexpressions_strings * srchilite::RegexPreProcessor::split_marked_subexpressions ( const std::string &  s  )  [static]

Splits the marked subexpressions of a regular expression made up of only marked subexpressions and no nested subexpressions and char outside subexpressions (thus, before calling this, you must make sure that num_of_marked_subexpressions did not return an error.

Returns:
the subexpressions in a collection (this is allocated on the heap, so it is up to the caller to delete it)


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

Generated on Sun Jun 14 18:23:26 2009 for Source-highlight Library by  doxygen 1.5.9