php_pcre.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Andrei Zmievski <andrei@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef PHP_PCRE_H
  17. #define PHP_PCRE_H
  18. #ifdef HAVE_BUNDLED_PCRE
  19. #include "pcre2lib/pcre2.h"
  20. #else
  21. #include "pcre2.h"
  22. #endif
  23. #include <locale.h>
  24. PHPAPI zend_string *php_pcre_replace(zend_string *regex, zend_string *subject_str, const char *subject, size_t subject_len, zend_string *replace_str, size_t limit, size_t *replace_count);
  25. PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count);
  26. PHPAPI pcre2_code* pcre_get_compiled_regex_ex(zend_string *regex, uint32_t *capture_count, uint32_t *preg_options, uint32_t *coptions);
  27. extern zend_module_entry pcre_module_entry;
  28. #define pcre_module_ptr &pcre_module_entry
  29. #include "php_version.h"
  30. #define PHP_PCRE_VERSION PHP_VERSION
  31. typedef struct _pcre_cache_entry pcre_cache_entry;
  32. typedef enum {
  33. PHP_PCRE_NO_ERROR = 0,
  34. PHP_PCRE_INTERNAL_ERROR,
  35. PHP_PCRE_BACKTRACK_LIMIT_ERROR,
  36. PHP_PCRE_RECURSION_LIMIT_ERROR,
  37. PHP_PCRE_BAD_UTF8_ERROR,
  38. PHP_PCRE_BAD_UTF8_OFFSET_ERROR,
  39. PHP_PCRE_JIT_STACKLIMIT_ERROR
  40. } php_pcre_error_code;
  41. PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex);
  42. PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware);
  43. PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str, zval *return_value,
  44. zval *subpats, int global, int use_flags, zend_long flags, zend_off_t start_offset);
  45. PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *subject_str, const char *subject, size_t subject_len, zend_string *replace_str,
  46. size_t limit, size_t *replace_count);
  47. PHPAPI void php_pcre_split_impl( pcre_cache_entry *pce, zend_string *subject_str, zval *return_value,
  48. zend_long limit_val, zend_long flags);
  49. PHPAPI void php_pcre_grep_impl( pcre_cache_entry *pce, zval *input, zval *return_value,
  50. zend_long flags);
  51. PHPAPI pcre2_match_context *php_pcre_mctx(void);
  52. PHPAPI pcre2_general_context *php_pcre_gctx(void);
  53. PHPAPI pcre2_compile_context *php_pcre_cctx(void);
  54. PHPAPI void php_pcre_pce_incref(pcre_cache_entry *);
  55. PHPAPI void php_pcre_pce_decref(pcre_cache_entry *);
  56. PHPAPI pcre2_code *php_pcre_pce_re(pcre_cache_entry *);
  57. /* capture_count can be ignored, re is required. */
  58. PHPAPI pcre2_match_data *php_pcre_create_match_data(uint32_t, pcre2_code *);
  59. PHPAPI void php_pcre_free_match_data(pcre2_match_data *);
  60. ZEND_BEGIN_MODULE_GLOBALS(pcre)
  61. HashTable pcre_cache;
  62. zend_long backtrack_limit;
  63. zend_long recursion_limit;
  64. #ifdef HAVE_PCRE_JIT_SUPPORT
  65. bool jit;
  66. #endif
  67. bool per_request_cache;
  68. php_pcre_error_code error_code;
  69. /* Used for unmatched subpatterns in OFFSET_CAPTURE mode */
  70. zval unmatched_null_pair;
  71. zval unmatched_empty_pair;
  72. /* General context using per-request allocator (ZMM). */
  73. pcre2_general_context *gctx_zmm;
  74. ZEND_END_MODULE_GLOBALS(pcre)
  75. PHPAPI ZEND_EXTERN_MODULE_GLOBALS(pcre)
  76. #define PCRE_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(pcre, v)
  77. #define phpext_pcre_ptr pcre_module_ptr
  78. #endif /* PHP_PCRE_H */