Pawn.Regex.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Pawn.Regex plugin by urShadow
  2. #if !defined __cplusplus
  3. #if defined _pawnregex_included
  4. #endinput
  5. #endif
  6. #define _pawnregex_included
  7. #endif
  8. #define PAWNREGEX_INCLUDE_VERSION 112
  9. enum E_REGEX_GRAMMAR
  10. {
  11. REGEX_ECMASCRIPT, // ECMAScript grammar
  12. REGEX_BASIC, // Basic POSIX grammar
  13. REGEX_EXTENDED, // Extended POSIX grammar
  14. REGEX_AWK, // Awk POSIX grammar
  15. REGEX_GREP, // Grep POSIX grammar
  16. REGEX_EGREP // Egrep POSIX grammar
  17. };
  18. enum E_REGEX_FLAG
  19. {
  20. REGEX_DEFAULT = 1 << 0, // Default flag
  21. REGEX_ICASE = 1 << 1, // Regular expressions match without regard to case
  22. REGEX_NOSUBS = 1 << 2, // The match_results structure will not contain sub-expression matches.
  23. REGEX_OPTIMIZE = 1 << 3, // Matching efficiency is preferred over efficiency constructing regex objects.
  24. REGEX_COLLATE = 1 << 4, // Character ranges, like "[a-b]", are affected by locale.
  25. };
  26. enum E_MATCH_FLAG
  27. {
  28. MATCH_DEFAULT = 1 << 0, // Default matching behavior.
  29. MATCH_NOT_BOL = 1 << 1, // The first character is not considered a beginning of line ("^" does not match).
  30. MATCH_NOT_EOL = 1 << 2, // The last character is not considered an end of line ("$" does not match).
  31. MATCH_NOT_BOW = 1 << 3, // The escape sequence "\b" does not match as a beginning-of-word.
  32. MATCH_NOT_EOW = 1 << 4, // The escape sequence "\b" does not match as an end-of-word.
  33. MATCH_ANY = 1 << 5, // Any match is acceptable if more than one match is possible.
  34. MATCH_NOT_NULL = 1 << 6, // Empty sequences do not match.
  35. MATCH_CONTINUOUS = 1 << 7, // The expression must match a sub-sequence that begins at the first character.
  36. // Sub-sequences must begin at the first character to match.
  37. MATCH_PREV_AVAIL = 1 << 8, // One or more characters exist before the first one. (MATCH_NOT_BOL and MATCH_NOT_BOW are ignored)
  38. MATCH_FORMAT_SED = 1 << 9, // Uses the same rules as the sed utility in POSIX to replace matches.
  39. MATCH_FORMAT_NO_COPY = 1 << 10, // The sections in the target sequence that do not match the regular expression
  40. // are not copied when replacing matches.
  41. MATCH_FORMAT_FIRST_ONLY = 1 << 11, // Only the first occurrence of a regular expression is replaced.
  42. };
  43. #if !defined __cplusplus
  44. public _pawnregex_version = PAWNREGEX_INCLUDE_VERSION;
  45. #pragma unused _pawnregex_version
  46. native Regex:Regex_New(const pattern[], E_REGEX_FLAG:flags = REGEX_DEFAULT, E_REGEX_GRAMMAR:grammar = REGEX_ECMASCRIPT) = regex_new;
  47. native Regex_Delete(&Regex:r) = regex_delete;
  48. native Regex_Check(const str[], Regex:r, E_MATCH_FLAG:flags = MATCH_DEFAULT) = regex_check;
  49. native Regex_Match(const str[], Regex:r, &RegexMatch:m, E_MATCH_FLAG:flags = MATCH_DEFAULT) = regex_match;
  50. native Regex_Search(const str[], Regex:r, &RegexMatch:m, &pos, startpos = 0, E_MATCH_FLAG:flags = MATCH_DEFAULT) = regex_search;
  51. native Regex_Replace(const str[], Regex:r, const fmt[], dest[], E_MATCH_FLAG:flags = MATCH_DEFAULT, size = sizeof dest) = regex_replace;
  52. native Match_GetGroup(RegexMatch:m, index, dest[], &length, size = sizeof dest) = match_get_group;
  53. native Match_Free(&RegexMatch:m) = match_free;
  54. #pragma deprecated
  55. native regex:regex_new(const pattern[], E_REGEX_FLAG:flags = REGEX_DEFAULT, E_REGEX_GRAMMAR:grammar = REGEX_ECMASCRIPT);
  56. #pragma deprecated
  57. native regex_delete(&regex:r);
  58. #pragma deprecated
  59. native regex_check(const str[], regex:r, E_MATCH_FLAG:flags = MATCH_DEFAULT);
  60. #pragma deprecated
  61. native regex_match(const str[], regex:r, &match_results:m, E_MATCH_FLAG:flags = MATCH_DEFAULT);
  62. #pragma deprecated
  63. native regex_search(const str[], regex:r, &match_results:m, &pos, startpos = 0, E_MATCH_FLAG:flags = MATCH_DEFAULT);
  64. #pragma deprecated
  65. native regex_replace(const str[], regex:r, const fmt[], dest[], E_MATCH_FLAG:flags = MATCH_DEFAULT, size = sizeof dest);
  66. #pragma deprecated
  67. native match_get_group(match_results:m, index, dest[], &length, size = sizeof dest);
  68. #pragma deprecated
  69. native match_free(&match_results:m);
  70. #endif