X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstrings%2Fregex.h;h=acc842bc6e969807eac2e156be5ca5161df689d6;hb=39da82b967c70282973025e4b12186625e29fe26;hp=8226c44ae057c2b17bb63adf8198c1686015525b;hpb=967785734be5c3fc6f75da122c2d93ebbb338271;p=libs%2Fcore.git diff --git a/source/strings/regex.h b/source/strings/regex.h index 8226c44..acc842b 100644 --- a/source/strings/regex.h +++ b/source/strings/regex.h @@ -1,11 +1,22 @@ #ifndef MSP_STRINGS_REGEX_H_ #define MSP_STRINGS_REGEX_H_ +#include #include #include "regmatch.h" namespace Msp { +class bad_regex: public std::logic_error +{ +public: + bad_regex(const std::string &, const std::string &, const std::string::const_iterator &); + +private: + std::string make_where(const std::string &, const std::string::const_iterator &); +}; + + /** This class provides regular expression matching. It supports a subset of POSIX.2 extended regex syntax. Character classes, equivalence classes and @@ -61,7 +72,7 @@ The MATCH_ANY instruction consumes the input character and always succeeds. class Regex { private: - typedef std::string Code; + typedef std::basic_string Code; typedef unsigned short Count; typedef short Offset; typedef unsigned short Index; @@ -91,11 +102,11 @@ private: struct RunContext { Code::const_iterator citer; - RegMatch::GroupArray groups; + std::vector groups; }; Code code; - unsigned n_groups; + unsigned n_groups = 0; public: /** Constructs a new Regex object from a string representation. */ @@ -108,7 +119,7 @@ private: Code parse_atom(const std::string &, std::string::const_iterator &i, unsigned &); Code parse_brackets(const std::string &, std::string::const_iterator &); - bool parse_repeat(std::string::const_iterator &, Count &, Count &); + bool parse_repeat(const std::string &, std::string::const_iterator &, Count &, Count &); public: /** Matches the regex against a string. Refer to RegMatch documentation for @@ -116,7 +127,7 @@ public: RegMatch match(const std::string &str) const; private: - bool run(const std::string &, const std::string::const_iterator &, RegMatch::GroupArray &) const; + bool run(const std::string &, const std::string::const_iterator &, std::vector &) const; bool group_compare(const RegMatch::Group &, const RegMatch::Group &) const; public: