Source-highlight Library
regexpreprocessor.h
1 //
2 // C++ Interface: RegexPreProcessor
3 //
4 // Description: performs operations or inspections on a string representing
5 // a valid regular expression
6 //
7 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 1999-2007
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #ifndef REGEXPREPROCESSOR_H
13 #define REGEXPREPROCESSOR_H
14 
15 #include <string>
16 #include <list>
17 #include <utility>
18 #include <vector>
19 #include <boost/regex.hpp>
20 
21 namespace srchilite {
22 
28  const static std::string ERR_OUTER_UNMARKED;
29  const static std::string ERR_NESTED_SUBEXP;
30  const static std::string ERR_UNBALANCED_PAREN;
31  const static std::string ERR_OUTSIDE_SUBEXP;
32 
34  unsigned int marked;
36  std::string errors;
37 
39  marked(0) {
40  }
41 };
42 
46 typedef std::list<std::string> subexpressions_strings;
47 
53 typedef std::pair<int, int> backreference_info;
54 
58 typedef std::vector<std::string> backreference_replacements;
59 
63 typedef boost::match_results<std::string::const_iterator> regex_match_results;
64 
69 public:
71 
73 
78  static const std::string preprocess(const std::string &s);
79 
85  static const std::string make_nonsensitive(const std::string &s);
86 
93  static unsigned int num_of_subexpressions(const std::string &s);
94 
109  const std::string &s, bool allow_outer_char = false,
110  bool allow_outer_nonmarked = false);
111 
121  static const subexpressions_strings *split_marked_subexpressions(
122  const std::string &s);
123 
132  static bool contains_backreferences(const std::string &s);
133 
141  static backreference_info num_of_backreferences(const std::string &s);
142 
151  static backreference_info num_of_references(const std::string &s);
152 
164  static const std::string replace_backreferences(
165  const std::string &original,
166  const backreference_replacements &replace);
167 
181  static const std::string replace_backreferences(
182  const std::string &original, const regex_match_results &results);
183 
193  static const std::string replace_references(
194  const std::string &original,
195  const backreference_replacements &replace);
196 
208  static const std::string replace_references(
209  const std::string &original, const regex_match_results &results);
210 
211 };
212 
213 }
214 
215 #endif
std::pair< int, int > backreference_info
Information about backreferences; the first elem contains the number of backreferences and the second...
Definition: regexpreprocessor.h:53
Definition: regexpreprocessor.h:27
preprocess a regular expression, e.g., transform "()" into "(?:)"
Definition: regexpreprocessor.h:68
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 r...
Definition: regexpreprocessor.cpp:373
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
static bool contains_backreferences(const std::string &s)
Checks whether the passed regular expression string contains a backreference (e.g., either \1 or a conditional with a backreference (?(1)...)
Definition: regexpreprocessor.cpp:255
boost::match_results< std::string::const_iterator > regex_match_results
The result of boost::regex_search.
Definition: regexpreprocessor.h:63
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 (...) and no nested subexpressions and...
Definition: regexpreprocessor.cpp:166
static const std::string preprocess(const std::string &s)
translates marked subexpressions (...) into non marked subexpressions (?: )
Definition: regexpreprocessor.cpp:82
unsigned int marked
num of marked subexpressions
Definition: regexpreprocessor.h:34
std::vector< std::string > backreference_replacements
What to replace to backreferences in a regular expression.
Definition: regexpreprocessor.h:58
std::string errors
error specifications, if any
Definition: regexpreprocessor.h:36
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][...
Definition: regexpreprocessor.cpp:100
std::list< std::string > subexpressions_strings
all the marked subexpressions in a list
Definition: regexpreprocessor.h:46
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...
Definition: regexpreprocessor.cpp:142
static backreference_info num_of_backreferences(const std::string &s)
counts the number of backreferences (also in conditionals)
Definition: regexpreprocessor.cpp:259
static unsigned int num_of_subexpressions(const std::string &s)
counts the number of marked subexpressions (...)
Definition: regexpreprocessor.cpp:129
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 expres...
Definition: regexpreprocessor.cpp:288
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 r...
Definition: regexpreprocessor.cpp:314