File indexing completed on 2025-05-12 09:08:10
0001 #ifndef REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003
0004 #if defined(_MSC_VER) || \
0005 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006 (__GNUC__ >= 4))
0007 #pragma once
0008 #endif
0009
0010 #include <string>
0011 #include <vector>
0012
0013 #include "ATOOLS/YAML/yaml-cpp/dll.h"
0014
0015 namespace SHERPA_YAML {
0016 class Stream;
0017
0018 enum REGEX_OP {
0019 REGEX_EMPTY,
0020 REGEX_MATCH,
0021 REGEX_RANGE,
0022 REGEX_OR,
0023 REGEX_AND,
0024 REGEX_NOT,
0025 REGEX_SEQ
0026 };
0027
0028
0029
0030
0031 class YAML_CPP_API RegEx {
0032 public:
0033 RegEx();
0034 explicit RegEx(char ch);
0035 RegEx(char a, char z);
0036 RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ);
0037 ~RegEx() = default;
0038
0039 friend YAML_CPP_API RegEx operator!(const RegEx& ex);
0040 friend YAML_CPP_API RegEx operator|(const RegEx& ex1, const RegEx& ex2);
0041 friend YAML_CPP_API RegEx operator&(const RegEx& ex1, const RegEx& ex2);
0042 friend YAML_CPP_API RegEx operator+(const RegEx& ex1, const RegEx& ex2);
0043
0044 bool Matches(char ch) const;
0045 bool Matches(const std::string& str) const;
0046 bool Matches(const Stream& in) const;
0047 template <typename Source>
0048 bool Matches(const Source& source) const;
0049
0050 int Match(const std::string& str) const;
0051 int Match(const Stream& in) const;
0052 template <typename Source>
0053 int Match(const Source& source) const;
0054
0055 private:
0056 explicit RegEx(REGEX_OP op);
0057
0058 template <typename Source>
0059 bool IsValidSource(const Source& source) const;
0060 template <typename Source>
0061 int MatchUnchecked(const Source& source) const;
0062
0063 template <typename Source>
0064 int MatchOpEmpty(const Source& source) const;
0065 template <typename Source>
0066 int MatchOpMatch(const Source& source) const;
0067 template <typename Source>
0068 int MatchOpRange(const Source& source) const;
0069 template <typename Source>
0070 int MatchOpOr(const Source& source) const;
0071 template <typename Source>
0072 int MatchOpAnd(const Source& source) const;
0073 template <typename Source>
0074 int MatchOpNot(const Source& source) const;
0075 template <typename Source>
0076 int MatchOpSeq(const Source& source) const;
0077
0078 private:
0079 REGEX_OP m_op;
0080 char m_a{};
0081 char m_z{};
0082 std::vector<RegEx> m_params;
0083 };
0084 }
0085
0086 #include "regeximpl.h"
0087
0088 #endif