regex.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef AFUN_REGEX
  2. #define AFUN_REGEX
  3. #define PCRE2_CODE_UNIT_WIDTH 8
  4. #include "pcre2.h"
  5. #include "aFunToolExport.h"
  6. namespace aFuntool {
  7. const int REGEX_ERROR_SIZE = 512;
  8. class RegexException : public std::exception
  9. {
  10. std::string message = "Regex Error";
  11. public:
  12. explicit RegexException(std::string &msg) {
  13. this->message = "RegexErrpr: " + msg;
  14. }
  15. explicit RegexException(const char *msg) {
  16. this->message = std::string("RegexErrpr: ") + msg;
  17. }
  18. virtual const char *what() {
  19. return message.c_str();
  20. }
  21. };
  22. struct af_Regex {
  23. pcre2_code *re; // 正则表达式
  24. char *pattern; // 正则表达式的字符串
  25. };
  26. class Regex {
  27. pcre2_code *re; // 正则表达式
  28. std::string pattern; // 正则表达式的字符串
  29. public:
  30. explicit Regex(const std::string &pattern);
  31. ~Regex();
  32. int match(const char *subject);
  33. };
  34. }
  35. #endif //AFUN_REGEX