mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
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:
37
regex.h
Normal file
37
regex.h
Normal 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user