1 #ifndef WIBBLE_REGEXP_H 2 #define WIBBLE_REGEXP_H 25 #include <sys/types.h> 47 virtual const char*
type()
const throw () {
return "Regexp"; }
66 Regexp(
const std::string& expr,
int match_count = 0,
int flags = 0) throw (
wibble::exception::
Regexp);
69 bool match(const
std::
string& str,
int flags = 0) throw (
wibble::exception::Regexp);
75 std::
string operator[](
int idx) throw (
wibble::exception::OutOfRange);
77 size_t matchStart(
int idx) throw (
wibble::exception::OutOfRange);
78 size_t matchEnd(
int idx) throw (
wibble::exception::OutOfRange);
79 size_t matchLength(
int idx) throw (
wibble::exception::OutOfRange);
85 ERegexp(
const std::string& expr,
int match_count = 0,
int flags = 0) throw (
wibble::exception::Regexp)
86 : Regexp(expr, match_count, flags | REG_EXTENDED) {}
91 const std::string& str;
113 return tok.str.substr(beg, end-beg);
117 return beg == ti.beg && end == ti.end;
121 return beg != ti.beg || end != ti.end;
125 Tokenizer(
const std::string& str,
const std::string& re,
int flags)
126 : str(str), re(re, 1, flags) {}
183 return cur == ti.cur && next == ti.next;
187 return cur != ti.cur || next != ti.next;
195 : re(re, 1, flags) {}
const_iterator end()
Definition: regexp.h:201
const_iterator(Tokenizer &tok)
Definition: regexp.h:106
ptrdiff_t difference_type
Definition: regexp.h:101
regex_t re
Definition: regexp.h:56
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: regexp.h:47
value_type & reference
Definition: regexp.h:165
value_type * pointer
Definition: regexp.h:164
std::forward_iterator_tag iterator_category
Definition: regexp.h:104
int nmatch
Definition: regexp.h:58
regmatch_t * pmatch
Definition: regexp.h:57
std::string lastMatch
Definition: regexp.h:59
const_iterator(wibble::Regexp &re, const std::string &str)
Definition: regexp.h:168
std::forward_iterator_tag iterator_category
Definition: regexp.h:166
Base class for all exceptions.
Definition: exception.h:179
const_iterator(wibble::Regexp &re)
Definition: regexp.h:169
ERegexp(const std::string &expr, int match_count=0, int flags=0)
Definition: regexp.h:85
const_iterator end()
Definition: regexp.h:129
Tokenizer(const std::string &str, const std::string &re, int flags)
Definition: regexp.h:125
virtual int code() const
Get the regexp error code associated to the exception.
Definition: regexp.h:45
bool operator!=(const const_iterator &ti) const
Definition: regexp.h:119
ptrdiff_t difference_type
Definition: regexp.h:163
const std::string * operator->() const
Definition: regexp.h:177
const_iterator begin()
Definition: regexp.h:128
std::string m_message
Definition: regexp.h:37
Warning: the various iterators reuse the Regexps and therefore only one iteration of a Splitter can b...
Definition: regexp.h:155
value_type * pointer
Definition: regexp.h:102
int m_code
Definition: regexp.h:36
const std::vector< std::string > & context() const
Definition: exception.h:166
const_iterator(Tokenizer &tok, bool)
Definition: regexp.h:107
value_type & reference
Definition: regexp.h:103
size_t size(const std::string &file)
File size.
Definition: fs.cpp:287
bool operator==(const const_iterator &ti) const
Definition: regexp.h:115
Splitter(const std::string &re, int flags)
Create a splitter that uses the given regular expression to find tokens.
Definition: regexp.h:194
const_iterator begin(const std::string &str)
Split the string and iterate the resulting tokens.
Definition: regexp.h:200
bool operator!=(const const_iterator &ti) const
Definition: regexp.h:185
std::string value_type
Definition: regexp.h:162
bool operator==(const const_iterator &ti) const
Definition: regexp.h:181
~Regexp()
Definition: regexp.h:42
std::string value_type
Definition: regexp.h:100
Split a string using a regular expression to match the token separators.
Definition: regexp.h:145
ListIterator< List > end(List)
Definition: list.h:425
virtual std::string desc() const
Get a string describing what happened that threw the exception.
Definition: regexp.h:48
const std::string & operator*() const
Definition: regexp.h:173
std::string operator*() const
Definition: regexp.h:111
Regexp(const regex_t &re, int code, const std::string &context)
Definition: regexp.cpp:31