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);
69 bool match(const std::
string& str,
int flags = 0);
75 std::
string operator[](
int idx);
85 ERegexp(
const std::string& expr,
int match_count = 0,
int flags = 0)
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) {}
ERegexp(const std::string &expr, int match_count=0, int flags=0)
Definition: regexp.h:85
size_t matchLength(int idx)
Definition: regexp.cpp:118
std::string lastMatch
Definition: regexp.h:59
regmatch_t * pmatch
Definition: regexp.h:57
size_t matchStart(int idx)
Definition: regexp.cpp:104
regex_t re
Definition: regexp.h:56
Regexp(const std::string &expr, int match_count=0, int flags=0)
Definition: regexp.cpp:52
int nmatch
Definition: regexp.h:58
size_t matchEnd(int idx)
Definition: regexp.cpp:111
bool match(const std::string &str, int flags=0)
Definition: regexp.cpp:73
~Regexp()
Definition: regexp.cpp:65
Warning: the various iterators reuse the Regexps and therefore only one iteration of a Splitter can b...
Definition: regexp.h:156
value_type * pointer
Definition: regexp.h:164
std::string value_type
Definition: regexp.h:162
bool operator!=(const const_iterator &ti) const
Definition: regexp.h:185
const std::string & operator*() const
Definition: regexp.h:173
const_iterator(wibble::Regexp &re, const std::string &str)
Definition: regexp.h:168
const_iterator(wibble::Regexp &re)
Definition: regexp.h:169
const std::string * operator->() const
Definition: regexp.h:177
std::forward_iterator_tag iterator_category
Definition: regexp.h:166
bool operator==(const const_iterator &ti) const
Definition: regexp.h:181
value_type & reference
Definition: regexp.h:165
ptrdiff_t difference_type
Definition: regexp.h:163
Split a string using a regular expression to match the token separators.
Definition: regexp.h:146
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 end()
Definition: regexp.h:201
const_iterator begin(const std::string &str)
Split the string and iterate the resulting tokens.
Definition: regexp.h:200
std::forward_iterator_tag iterator_category
Definition: regexp.h:104
std::string value_type
Definition: regexp.h:100
const_iterator(Tokenizer &tok)
Definition: regexp.h:106
value_type & reference
Definition: regexp.h:103
const_iterator(Tokenizer &tok, bool)
Definition: regexp.h:107
value_type * pointer
Definition: regexp.h:102
bool operator!=(const const_iterator &ti) const
Definition: regexp.h:119
bool operator==(const const_iterator &ti) const
Definition: regexp.h:115
std::string operator*() const
Definition: regexp.h:111
ptrdiff_t difference_type
Definition: regexp.h:101
Tokenizer(const std::string &str, const std::string &re, int flags)
Definition: regexp.h:125
const_iterator end()
Definition: regexp.h:129
const_iterator begin()
Definition: regexp.h:128
const std::vector< std::string > & context() const
Definition: exception.h:166
Base class for all exceptions.
Definition: exception.h:180
Regexp(const regex_t &re, int code, const std::string &context)
Definition: regexp.cpp:31
int m_code
Definition: regexp.h:36
std::string m_message
Definition: regexp.h:37
virtual std::string desc() const
Get a string describing what happened that threw the exception.
Definition: regexp.h:48
virtual int code() const
Get the regexp error code associated to the exception.
Definition: regexp.h:45
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: regexp.h:47
~Regexp()
Definition: regexp.h:42
ListIterator< List > end(List)
Definition: list.h:425
size_t size(const std::string &file)
File size.
Definition: fs.cpp:287