regex_yaml.h (2411B)
1 #ifndef REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 #pragma once 8 #endif 9 10 #include <string> 11 #include <vector> 12 13 #include "yaml-cpp/dll.h" 14 15 namespace YAML { 16 class Stream; 17 18 enum REGEX_OP { 19 REGEX_EMPTY, 20 REGEX_MATCH, 21 REGEX_RANGE, 22 REGEX_OR, 23 REGEX_AND, 24 REGEX_NOT, 25 REGEX_SEQ 26 }; 27 28 // simplified regular expressions 29 // . Only straightforward matches (no repeated characters) 30 // . Only matches from start of string 31 class YAML_CPP_API RegEx { 32 public: 33 RegEx(); 34 explicit RegEx(char ch); 35 RegEx(char a, char z); 36 RegEx(const std::string& str, REGEX_OP op = REGEX_SEQ); 37 ~RegEx() = default; 38 39 friend YAML_CPP_API RegEx operator!(const RegEx& ex); 40 friend YAML_CPP_API RegEx operator|(const RegEx& ex1, const RegEx& ex2); 41 friend YAML_CPP_API RegEx operator&(const RegEx& ex1, const RegEx& ex2); 42 friend YAML_CPP_API RegEx operator+(const RegEx& ex1, const RegEx& ex2); 43 44 bool Matches(char ch) const; 45 bool Matches(const std::string& str) const; 46 bool Matches(const Stream& in) const; 47 template <typename Source> 48 bool Matches(const Source& source) const; 49 50 int Match(const std::string& str) const; 51 int Match(const Stream& in) const; 52 template <typename Source> 53 int Match(const Source& source) const; 54 55 private: 56 explicit RegEx(REGEX_OP op); 57 58 template <typename Source> 59 bool IsValidSource(const Source& source) const; 60 template <typename Source> 61 int MatchUnchecked(const Source& source) const; 62 63 template <typename Source> 64 int MatchOpEmpty(const Source& source) const; 65 template <typename Source> 66 int MatchOpMatch(const Source& source) const; 67 template <typename Source> 68 int MatchOpRange(const Source& source) const; 69 template <typename Source> 70 int MatchOpOr(const Source& source) const; 71 template <typename Source> 72 int MatchOpAnd(const Source& source) const; 73 template <typename Source> 74 int MatchOpNot(const Source& source) const; 75 template <typename Source> 76 int MatchOpSeq(const Source& source) const; 77 78 private: 79 REGEX_OP m_op; 80 char m_a{}; 81 char m_z{}; 82 std::vector<RegEx> m_params; 83 }; 84 } // namespace YAML 85 86 #include "regeximpl.h" 87 88 #endif // REGEX_H_62B23520_7C8E_11DE_8A39_0800200C9A66