#include "regex.h" namespace YAML { RegEx::RegEx(REGEX_OP op): m_op(op) { } RegEx::RegEx(): m_op(REGEX_EMPTY) { } RegEx::RegEx(char ch): m_op(REGEX_MATCH), m_a(ch) { } RegEx::RegEx(char a, char z): m_op(REGEX_RANGE), m_a(a), m_z(z) { } RegEx::RegEx(const std::string& str, REGEX_OP op): m_op(op) { for(unsigned i=0;i= 0; } // Match // . Matches the given string against this regular expression. // . Returns the number of characters matched. // . Returns -1 if no characters were matched (the reason for // not returning zero is that we may have an empty regex // which SHOULD be considered successfully matching nothing, // but that of course matches zero characters). int RegEx::Match(const std::string& str) const { switch(m_op) { case REGEX_EMPTY: if(str.empty()) return 0; return -1; case REGEX_MATCH: if(str.empty() || str[0] != m_a) return -1; return 1; case REGEX_RANGE: if(str.empty() || m_a > str[0] || m_z < str[0]) return -1; return 1; case REGEX_NOT: if(m_params.empty()) return false; if(m_params[0].Match(str) >= 0) return -1; return 1; case REGEX_OR: for(unsigned i=0;i= 0) return n; } return -1; case REGEX_SEQ: int offset = 0; for(unsigned i=0;i