Wrote a simplified regular expression parser to make life easier (it only does single matches; i.e., no one-or-more matches, etc.).

Fixed some of the whitespace/line break matching.
This commit is contained in:
Jesse Beder 2008-06-27 08:20:41 +00:00
parent 873dbc2421
commit 4e435b1321
7 changed files with 277 additions and 75 deletions

37
regex.h Normal file
View file

@ -0,0 +1,37 @@
#pragma once
#include <vector>
#include <string>
namespace YAML
{
enum REGEX_OP { REGEX_EMPTY, REGEX_MATCH, REGEX_RANGE, REGEX_OR, REGEX_NOT, REGEX_SEQ };
// simplified regular expressions
// . Only straightforward matches (no repeated characters)
// . Only matches from start of string
class RegEx {
public:
RegEx();
RegEx(char ch);
RegEx(char a, char z);
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
~RegEx();
bool Matches(char ch) const;
bool Matches(const std::string& str) const;
int Match(const std::string& str) const;
friend RegEx operator ! (const RegEx& ex);
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
friend RegEx operator + (const RegEx& ex1, const RegEx& ex2);
private:
RegEx(REGEX_OP op);
private:
REGEX_OP m_op;
char m_a, m_z;
std::vector <RegEx> m_params;
};
}