mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-16 11:48:36 +12:00
Added stream input to the regular expressions, greatly simplifying the usage (in particular, we no longer have to specify the number of characters to be checked).
This commit is contained in:
parent
4e435b1321
commit
de29068110
4 changed files with 232 additions and 85 deletions
45
regex.h
45
regex.h
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <ios>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
|
@ -10,17 +11,55 @@ namespace YAML
|
|||
// simplified regular expressions
|
||||
// . Only straightforward matches (no repeated characters)
|
||||
// . Only matches from start of string
|
||||
class RegEx {
|
||||
class RegEx
|
||||
{
|
||||
private:
|
||||
struct Operator {
|
||||
virtual ~Operator() {}
|
||||
virtual int Match(const std::string& str, const RegEx& regex) const = 0;
|
||||
virtual int Match(std::istream& in, const RegEx& regex) const = 0;
|
||||
};
|
||||
|
||||
struct MatchOperator: public Operator {
|
||||
virtual int Match(const std::string& str, const RegEx& regex) const;
|
||||
virtual int Match(std::istream& in, const RegEx& regex) const;
|
||||
};
|
||||
|
||||
struct RangeOperator: public Operator {
|
||||
virtual int Match(const std::string& str, const RegEx& regex) const;
|
||||
virtual int Match(std::istream& in, const RegEx& regex) const;
|
||||
};
|
||||
|
||||
struct OrOperator: public Operator {
|
||||
virtual int Match(const std::string& str, const RegEx& regex) const;
|
||||
virtual int Match(std::istream& in, const RegEx& regex) const;
|
||||
};
|
||||
|
||||
struct NotOperator: public Operator {
|
||||
virtual int Match(const std::string& str, const RegEx& regex) const;
|
||||
virtual int Match(std::istream& in, const RegEx& regex) const;
|
||||
};
|
||||
|
||||
struct SeqOperator: public Operator {
|
||||
virtual int Match(const std::string& str, const RegEx& regex) const;
|
||||
virtual int Match(std::istream& in, const RegEx& regex) const;
|
||||
};
|
||||
|
||||
public:
|
||||
friend struct Operator;
|
||||
|
||||
RegEx();
|
||||
RegEx(char ch);
|
||||
RegEx(char a, char z);
|
||||
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
|
||||
RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
|
||||
RegEx(const RegEx& rhs);
|
||||
~RegEx();
|
||||
|
||||
bool Matches(char ch) const;
|
||||
bool Matches(const std::string& str) const;
|
||||
bool Matches(std::istream& in) const;
|
||||
int Match(const std::string& str) const;
|
||||
int Match(std::istream& in) const;
|
||||
|
||||
friend RegEx operator ! (const RegEx& ex);
|
||||
friend RegEx operator || (const RegEx& ex1, const RegEx& ex2);
|
||||
|
@ -28,9 +67,11 @@ namespace YAML
|
|||
|
||||
private:
|
||||
RegEx(REGEX_OP op);
|
||||
void SetOp();
|
||||
|
||||
private:
|
||||
REGEX_OP m_op;
|
||||
Operator *m_pOp;
|
||||
char m_a, m_z;
|
||||
std::vector <RegEx> m_params;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue