From 620c58abec1172971b98ddd1a1f75e62088dfee1 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Mon, 1 Jun 2009 03:42:16 +0000 Subject: [PATCH] Updated the nested RegEx classes so they don't need to also take an std::string --- src/regex.cpp | 83 +++++++-------------------------------------------- src/regex.h | 7 ----- 2 files changed, 10 insertions(+), 80 deletions(-) diff --git a/src/regex.cpp b/src/regex.cpp index 4ffd711..b48036e 100644 --- a/src/regex.cpp +++ b/src/regex.cpp @@ -106,12 +106,19 @@ namespace YAML // . Returns -1 if no characters were matched (the reason for // not returning zero is that we may have an empty regex // which is ALWAYS successful at matching zero characters). - int RegEx::Match(const std::string& str) const + // . REMEMBER that we only match from the start of the buffer! + int RegEx::Match(const Buffer& buffer) const { if(!m_pOp) - return str.empty() ? 0 : -1; // the empty regex only is successful on the empty string + return !buffer ? 0 : -1; // the empty regex only is successful on the empty string - return m_pOp->Match(str, *this); + return m_pOp->Match(buffer, *this); + } + + int RegEx::Match(const std::string& str) const + { + Buffer buffer(str.c_str(), str.size()); + return Match(buffer); } // Match @@ -119,17 +126,6 @@ namespace YAML { return Match(in.current()); } - - // Match - // . The buffer version does the same thing as the string version; - // REMEMBER that we only match from the start of the buffer! - int RegEx::Match(const Buffer& buffer) const - { - if(!m_pOp) - return !buffer ? 0 : -1; // see above - - return m_pOp->Match(buffer, *this); - } RegEx operator ! (const RegEx& ex) { @@ -166,14 +162,6 @@ namespace YAML // Operators // MatchOperator - int RegEx::MatchOperator::Match(const std::string& str, const RegEx& regex) const - { - if(str.empty() || str[0] != regex.m_a) - return -1; - return 1; - } - - int RegEx::MatchOperator::Match(const Buffer& buffer, const RegEx& regex) const { if(!buffer || buffer[0] != regex.m_a) @@ -182,13 +170,6 @@ namespace YAML } // RangeOperator - int RegEx::RangeOperator::Match(const std::string& str, const RegEx& regex) const - { - if(str.empty() || regex.m_a > str[0] || regex.m_z < str[0]) - return -1; - return 1; - } - int RegEx::RangeOperator::Match(const Buffer& buffer, const RegEx& regex) const { if(!buffer || regex.m_a > buffer[0] || regex.m_z < buffer[0]) @@ -197,16 +178,6 @@ namespace YAML } // OrOperator - int RegEx::OrOperator::Match(const std::string& str, const RegEx& regex) const - { - for(unsigned i=0;i= 0) - return n; - } - return -1; - } - int RegEx::OrOperator::Match(const Buffer& buffer, const RegEx& regex) const { for(unsigned i=0;i= 0) - return -1; - return 1; - } - int RegEx::NotOperator::Match(const Buffer& buffer, const RegEx& regex) const { if(regex.m_params.empty()) @@ -267,18 +216,6 @@ namespace YAML } // SeqOperator - int RegEx::SeqOperator::Match(const std::string& str, const RegEx& regex) const - { - int offset = 0; - for(unsigned i=0;i