regex_yaml.h 2.4 KB

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