xref: /PHP-8.0/ext/pcre/php_pcre.h (revision f4b2497a)
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    | http://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 
17 #ifndef PHP_PCRE_H
18 #define PHP_PCRE_H
19 
20 #ifdef HAVE_BUNDLED_PCRE
21 #include "pcre2lib/pcre2.h"
22 #else
23 #include "pcre2.h"
24 #endif
25 
26 #include <locale.h>
27 
28 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);
29 PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count);
30 PHPAPI pcre2_code* pcre_get_compiled_regex_ex(zend_string *regex, uint32_t *capture_count, uint32_t *preg_options, uint32_t *coptions);
31 
32 extern zend_module_entry pcre_module_entry;
33 #define pcre_module_ptr &pcre_module_entry
34 
35 #include "php_version.h"
36 #define PHP_PCRE_VERSION PHP_VERSION
37 
38 typedef struct _pcre_cache_entry pcre_cache_entry;
39 
40 typedef enum {
41     PHP_PCRE_NO_ERROR = 0,
42     PHP_PCRE_INTERNAL_ERROR,
43     PHP_PCRE_BACKTRACK_LIMIT_ERROR,
44     PHP_PCRE_RECURSION_LIMIT_ERROR,
45     PHP_PCRE_BAD_UTF8_ERROR,
46     PHP_PCRE_BAD_UTF8_OFFSET_ERROR,
47     PHP_PCRE_JIT_STACKLIMIT_ERROR
48 } php_pcre_error_code;
49 
50 PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex);
51 PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware);
52 
53 PHPAPI void  php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str, zval *return_value,
54 	zval *subpats, int global, int use_flags, zend_long flags, zend_off_t start_offset);
55 
56 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,
57 	size_t limit, size_t *replace_count);
58 
59 PHPAPI void  php_pcre_split_impl(  pcre_cache_entry *pce, zend_string *subject_str, zval *return_value,
60 	zend_long limit_val, zend_long flags);
61 
62 PHPAPI void  php_pcre_grep_impl(   pcre_cache_entry *pce, zval *input, zval *return_value,
63 	zend_long flags);
64 
65 PHPAPI pcre2_match_context *php_pcre_mctx(void);
66 PHPAPI pcre2_general_context *php_pcre_gctx(void);
67 PHPAPI pcre2_compile_context *php_pcre_cctx(void);
68 PHPAPI void php_pcre_pce_incref(pcre_cache_entry *);
69 PHPAPI void php_pcre_pce_decref(pcre_cache_entry *);
70 PHPAPI pcre2_code *php_pcre_pce_re(pcre_cache_entry *);
71 /* capture_count can be ignored, re is required. */
72 PHPAPI pcre2_match_data *php_pcre_create_match_data(uint32_t, pcre2_code *);
73 PHPAPI void php_pcre_free_match_data(pcre2_match_data *);
74 
75 ZEND_BEGIN_MODULE_GLOBALS(pcre)
76 	HashTable pcre_cache;
77 	zend_long backtrack_limit;
78 	zend_long recursion_limit;
79 #ifdef HAVE_PCRE_JIT_SUPPORT
80 	zend_bool jit;
81 #endif
82 	zend_bool per_request_cache;
83 	php_pcre_error_code error_code;
84 	/* Used for unmatched subpatterns in OFFSET_CAPTURE mode */
85 	zval unmatched_null_pair;
86 	zval unmatched_empty_pair;
87 	/* General context using per-request allocator (ZMM). */
88 	pcre2_general_context *gctx_zmm;
89 ZEND_END_MODULE_GLOBALS(pcre)
90 
91 PHPAPI ZEND_EXTERN_MODULE_GLOBALS(pcre)
92 #define PCRE_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(pcre, v)
93 
94 #define phpext_pcre_ptr pcre_module_ptr
95 
96 #endif /* PHP_PCRE_H */
97