1
0

tool_regex.h 883 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef AFUN_TOOL_REGEX
  2. #define AFUN_TOOL_REGEX
  3. #ifdef __cplusplus
  4. #define PCRE2_CODE_UNIT_WIDTH 8
  5. #include "pcre2.h"
  6. #include "tool_macro.h"
  7. #ifndef AFUN_TOOL_C
  8. namespace aFuntool {
  9. #endif
  10. class AFUN_TOOL_EXPORT Regex { // 整个对象都是inline的, 不需要Export符号
  11. std::string pattern; // 正则表达式的字符串
  12. pcre2_code *re; // 正则表达式
  13. public:
  14. explicit Regex(std::string pattern_) noexcept(false);
  15. AFUN_INLINE Regex(const Regex &regex) noexcept;
  16. AFUN_INLINE Regex(Regex &&regex) noexcept;
  17. AFUN_INLINE ~Regex() noexcept;
  18. Regex &operator=(const Regex &regex)=delete;
  19. Regex &operator=(Regex &&regex)=delete;
  20. [[nodiscard]] bool match(const std::string &subject) const;
  21. };
  22. #ifndef AFUN_TOOL_C
  23. }
  24. #endif
  25. #include "tool_regex.inline.h"
  26. #endif
  27. #endif //AFUN_TOOL_REGEX