17#include "libmbfl/config.h"
34#if !defined(ONIGURUMA_VERSION_INT) || ONIGURUMA_VERSION_INT < 60800
35typedef void OnigMatchParam;
36#define onig_new_match_param() (NULL)
37#define onig_initialize_match_param(x) (void)(x)
38#define onig_set_match_stack_limit_size_of_match_param(x, y)
39#define onig_set_retry_limit_in_match_of_match_param(x, y)
40#define onig_free_match_param(x)
41#define onig_search_with_param(reg, str, end, start, range, region, option, mp) \
42 onig_search(reg, str, end, start, range, region, option)
43#define onig_match_with_param(re, str, end, at, region, option, mp) \
44 onig_match(re, str, end, at, region, option)
49char php_mb_oniguruma_version[256];
51struct _zend_mb_regex_globals {
52 OnigEncoding default_mbctype;
53 OnigEncoding current_mbctype;
54 const mbfl_encoding *current_mbctype_mbfl_encoding;
59 php_mb_regex_t *search_re;
60 OnigRegion *search_regs;
61 OnigOptionType regex_default_options;
62 OnigSyntaxType *regex_default_syntax;
65#define MBREX(g) (MBSTRG(mb_regex_globals)->g)
68static void php_mb_regex_free_cache(
zval *el) {
69 onig_free((php_mb_regex_t *)
Z_PTR_P(el));
74static int _php_mb_regex_globals_ctor(zend_mb_regex_globals *pglobals)
76 pglobals->default_mbctype = ONIG_ENCODING_UTF8;
77 pglobals->current_mbctype = ONIG_ENCODING_UTF8;
80 pglobals->search_re = (php_mb_regex_t*)
NULL;
81 pglobals->search_pos = 0;
82 pglobals->search_regs = (OnigRegion*)
NULL;
83 pglobals->regex_default_options = ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE;
84 pglobals->regex_default_syntax = ONIG_SYNTAX_RUBY;
90zend_mb_regex_globals *php_mb_regex_globals_alloc(
void)
92 zend_mb_regex_globals *pglobals =
pemalloc(
93 sizeof(zend_mb_regex_globals), 1);
94 if (
SUCCESS != _php_mb_regex_globals_ctor(pglobals)) {
103void php_mb_regex_globals_free(zend_mb_regex_globals *pglobals)
117 snprintf(php_mb_oniguruma_version,
sizeof(php_mb_oniguruma_version),
"%d.%d.%d",
118 ONIGURUMA_VERSION_MAJOR, ONIGURUMA_VERSION_MINOR, ONIGURUMA_VERSION_TEENY);
144 MBREX(current_mbctype) = MBREX(default_mbctype);
145 MBREX(current_mbctype_mbfl_encoding) =
mbfl_name2encoding(php_mb_regex_get_default_mbctype());
151 MBREX(search_pos) = 0;
152 MBREX(search_re) =
NULL;
154 if (MBREX(search_regs) !=
NULL) {
155 onig_region_free(MBREX(search_regs), 1);
156 MBREX(search_regs) = (OnigRegion *)
NULL;
171 ONIGURUMA_VERSION_MAJOR,
172 ONIGURUMA_VERSION_MINOR,
173 ONIGURUMA_VERSION_TEENY);
184typedef struct _php_mb_regex_enc_name_map_t {
187} php_mb_regex_enc_name_map_t;
189static const php_mb_regex_enc_name_map_t enc_name_map[] = {
190#ifdef ONIG_ENCODING_EUC_JP
192 "EUC-JP\0EUCJP\0X-EUC-JP\0UJIS\0EUCJP\0EUCJP-WIN\0",
196#ifdef ONIG_ENCODING_UTF8
202#ifdef ONIG_ENCODING_UTF16_BE
204 "UTF-16\0UTF-16BE\0",
205 ONIG_ENCODING_UTF16_BE
208#ifdef ONIG_ENCODING_UTF16_LE
211 ONIG_ENCODING_UTF16_LE
214#ifdef ONIG_ENCODING_UTF32_BE
216 "UCS-4\0UTF-32\0UTF-32BE\0",
217 ONIG_ENCODING_UTF32_BE
220#ifdef ONIG_ENCODING_UTF32_LE
222 "UCS-4LE\0UTF-32LE\0",
223 ONIG_ENCODING_UTF32_LE
226#ifdef ONIG_ENCODING_SJIS
228 "SJIS\0CP932\0MS932\0SHIFT_JIS\0SJIS-WIN\0WINDOWS-31J\0",
232#ifdef ONIG_ENCODING_BIG5
234 "BIG5\0BIG-5\0BIGFIVE\0CN-BIG5\0BIG-FIVE\0",
238#ifdef ONIG_ENCODING_EUC_CN
240 "EUC-CN\0EUCCN\0EUC_CN\0GB-2312\0GB2312\0",
244#ifdef ONIG_ENCODING_EUC_TW
246 "EUC-TW\0EUCTW\0EUC_TW\0",
250#ifdef ONIG_ENCODING_EUC_KR
252 "EUC-KR\0EUCKR\0EUC_KR\0",
256#if defined(ONIG_ENCODING_KOI8) && !PHP_ONIG_BAD_KOI8_ENTRY
262#ifdef ONIG_ENCODING_KOI8_R
264 "KOI8R\0KOI8-R\0KOI-8R\0",
268#ifdef ONIG_ENCODING_ISO_8859_1
270 "ISO-8859-1\0ISO8859-1\0",
271 ONIG_ENCODING_ISO_8859_1
274#ifdef ONIG_ENCODING_ISO_8859_2
276 "ISO-8859-2\0ISO8859-2\0",
277 ONIG_ENCODING_ISO_8859_2
280#ifdef ONIG_ENCODING_ISO_8859_3
282 "ISO-8859-3\0ISO8859-3\0",
283 ONIG_ENCODING_ISO_8859_3
286#ifdef ONIG_ENCODING_ISO_8859_4
288 "ISO-8859-4\0ISO8859-4\0",
289 ONIG_ENCODING_ISO_8859_4
292#ifdef ONIG_ENCODING_ISO_8859_5
294 "ISO-8859-5\0ISO8859-5\0",
295 ONIG_ENCODING_ISO_8859_5
298#ifdef ONIG_ENCODING_ISO_8859_6
300 "ISO-8859-6\0ISO8859-6\0",
301 ONIG_ENCODING_ISO_8859_6
304#ifdef ONIG_ENCODING_ISO_8859_7
306 "ISO-8859-7\0ISO8859-7\0",
307 ONIG_ENCODING_ISO_8859_7
310#ifdef ONIG_ENCODING_ISO_8859_8
312 "ISO-8859-8\0ISO8859-8\0",
313 ONIG_ENCODING_ISO_8859_8
316#ifdef ONIG_ENCODING_ISO_8859_9
318 "ISO-8859-9\0ISO8859-9\0",
319 ONIG_ENCODING_ISO_8859_9
322#ifdef ONIG_ENCODING_ISO_8859_10
324 "ISO-8859-10\0ISO8859-10\0",
325 ONIG_ENCODING_ISO_8859_10
328#ifdef ONIG_ENCODING_ISO_8859_11
330 "ISO-8859-11\0ISO8859-11\0",
331 ONIG_ENCODING_ISO_8859_11
334#ifdef ONIG_ENCODING_ISO_8859_13
336 "ISO-8859-13\0ISO8859-13\0",
337 ONIG_ENCODING_ISO_8859_13
340#ifdef ONIG_ENCODING_ISO_8859_14
342 "ISO-8859-14\0ISO8859-14\0",
343 ONIG_ENCODING_ISO_8859_14
346#ifdef ONIG_ENCODING_ISO_8859_15
348 "ISO-8859-15\0ISO8859-15\0",
349 ONIG_ENCODING_ISO_8859_15
352#ifdef ONIG_ENCODING_ISO_8859_16
354 "ISO-8859-16\0ISO8859-16\0",
355 ONIG_ENCODING_ISO_8859_16
358#ifdef ONIG_ENCODING_ASCII
360 "ASCII\0US-ASCII\0US_ASCII\0ISO646\0",
364 {
NULL, ONIG_ENCODING_UNDEF }
369static OnigEncoding _php_mb_regex_name2mbctype(
const char *pname)
372 const php_mb_regex_enc_name_map_t *mapping;
374 if (pname ==
NULL || !*pname) {
375 return ONIG_ENCODING_UNDEF;
378 for (mapping = enc_name_map; mapping->names !=
NULL; mapping++) {
379 for (
p = mapping->names; *
p !=
'\0';
p += (
strlen(
p) + 1)) {
381 return mapping->code;
386 return ONIG_ENCODING_UNDEF;
391static const char *_php_mb_regex_mbctype2name(OnigEncoding mbctype)
393 const php_mb_regex_enc_name_map_t *mapping;
395 for (mapping = enc_name_map; mapping->names !=
NULL; mapping++) {
396 if (mapping->code == mbctype) {
397 return mapping->names;
406int php_mb_regex_set_mbctype(
const char *encname)
408 OnigEncoding mbctype = _php_mb_regex_name2mbctype(encname);
409 if (mbctype == ONIG_ENCODING_UNDEF) {
412 MBREX(current_mbctype) = mbctype;
419int php_mb_regex_set_default_mbctype(
const char *encname)
421 OnigEncoding mbctype = _php_mb_regex_name2mbctype(encname);
422 if (mbctype == ONIG_ENCODING_UNDEF) {
425 MBREX(default_mbctype) = mbctype;
431const char *php_mb_regex_get_mbctype(
void)
433 return _php_mb_regex_mbctype2name(MBREX(current_mbctype));
440 return MBREX(current_mbctype_mbfl_encoding);
445const char *php_mb_regex_get_default_mbctype(
void)
447 return _php_mb_regex_mbctype2name(MBREX(default_mbctype));
455static php_mb_regex_t *php_mbregex_compile_pattern(
const char *pattern,
size_t patlen, OnigOptionType
options, OnigSyntaxType *syntax)
459 OnigErrorInfo err_info;
460 OnigUChar err_str[ONIG_MAX_ERROR_MESSAGE_LEN];
461 OnigEncoding enc = MBREX(current_mbctype);
465 "Pattern is not valid under %s encoding", _php_mb_regex_mbctype2name(enc));
469 rc = zend_hash_str_find_ptr(&MBREX(ht_rc), (
char *)pattern, patlen);
470 if (!rc || onig_get_options(rc) !=
options || onig_get_encoding(rc) != enc || onig_get_syntax(rc) != syntax) {
471 if ((err_code = onig_new(&
retval, (OnigUChar *)pattern, (OnigUChar *)(pattern + patlen),
options, enc, syntax, &err_info)) != ONIG_NORMAL) {
472 onig_error_code_to_str(err_str, err_code, &err_info);
476 if (rc == MBREX(search_re)) {
478 MBREX(search_re) =
NULL;
480 zend_hash_str_update_ptr(&MBREX(ht_rc), (
char *)pattern, patlen,
retval);
489static size_t _php_mb_regex_get_option_string(
char *str,
size_t len, OnigOptionType option, OnigSyntaxType *syntax)
491 size_t len_left =
len;
496 if ((option & ONIG_OPTION_IGNORECASE) != 0) {
504 if ((option & ONIG_OPTION_EXTEND) != 0) {
512 if ((option & (ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE)) ==
513 (ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE)) {
520 if ((option & ONIG_OPTION_MULTILINE) != 0) {
528 if ((option & ONIG_OPTION_SINGLELINE) != 0) {
536 if ((option & ONIG_OPTION_FIND_LONGEST) != 0) {
543 if ((option & ONIG_OPTION_FIND_NOT_EMPTY) != 0) {
553 if (syntax == ONIG_SYNTAX_JAVA) {
555 }
else if (syntax == ONIG_SYNTAX_GNU_REGEX) {
557 }
else if (syntax == ONIG_SYNTAX_GREP) {
559 }
else if (syntax == ONIG_SYNTAX_EMACS) {
561 }
else if (syntax == ONIG_SYNTAX_RUBY) {
563 }
else if (syntax == ONIG_SYNTAX_PERL) {
565 }
else if (syntax == ONIG_SYNTAX_POSIX_BASIC) {
567 }
else if (syntax == ONIG_SYNTAX_POSIX_EXTENDED) {
594static bool _php_mb_regex_init_options(
const char *parg,
size_t narg, OnigOptionType *option,
595 OnigSyntaxType **syntax)
599 OnigOptionType optm = 0;
601 *syntax = ONIG_SYNTAX_RUBY;
609 optm |= ONIG_OPTION_IGNORECASE;
612 optm |= ONIG_OPTION_EXTEND;
615 optm |= ONIG_OPTION_MULTILINE;
618 optm |= ONIG_OPTION_SINGLELINE;
621 optm |= ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE;
624 optm |= ONIG_OPTION_FIND_LONGEST;
627 optm |= ONIG_OPTION_FIND_NOT_EMPTY;
630 *syntax = ONIG_SYNTAX_JAVA;
633 *syntax = ONIG_SYNTAX_GNU_REGEX;
636 *syntax = ONIG_SYNTAX_GREP;
639 *syntax = ONIG_SYNTAX_EMACS;
642 *syntax = ONIG_SYNTAX_RUBY;
645 *syntax = ONIG_SYNTAX_PERL;
648 *syntax = ONIG_SYNTAX_POSIX_BASIC;
651 *syntax = ONIG_SYNTAX_POSIX_EXTENDED;
658 if (option !=
NULL) *option|=optm;
670typedef struct mb_regex_groups_iter_args {
675} mb_regex_groups_iter_args;
680mb_regex_groups_iter(
const OnigUChar*
name,
const OnigUChar* name_end,
int ngroup_num,
int* group_nums,
regex_t* reg,
void* parg)
682 mb_regex_groups_iter_args *
args = (mb_regex_groups_iter_args *) parg;
689 gn = onig_name_to_backref_number(reg,
name, name_end,
args->region);
690 beg =
args->region->beg[gn];
706static inline void mb_regex_substitute(
712 php_mb_regex_t *regexp,
721 eos = replace + replace_len;
725 if (clen != 1 ||
p == eos ||
p[0] !=
'\\') {
727 smart_str_appendl(pbuf,
p, clen);
733 if (clen != 1 ||
p == eos) {
735 smart_str_appendl(pbuf, sp,
p - sp);
744 case '1':
case '2':
case '3':
case '4':
745 case '5':
case '6':
case '7':
case '8':
case '9':
746 if (!onig_noname_group_capture_is_active(regexp)) {
754 smart_str_appendl(pbuf, sp,
p - sp);
763 if (clen != 1 ||
p == eos || (
p[0] !=
'<' &&
p[0] !=
'\'')) {
766 smart_str_appendl(pbuf, sp,
p - sp);
770 char delim =
p[0] ==
'<' ?
'>' :
'\'';
771 char *
name, *name_end;
773 name_end =
name =
p + 1;
774 while (name_end < eos) {
781 if (name_end[0] == delim)
break;
782 if (maybe_num && !isdigit(name_end[0])) maybe_num = 0;
788 smart_str_appendl(pbuf, sp,
p - sp);
793 if (!onig_noname_group_capture_is_active(regexp)) {
795 smart_str_appendl(pbuf, sp,
p - sp);
798 if (name_end -
name == 1) {
802 if (
name[0] ==
'0') {
809 no = onig_name_to_backref_number(regexp, (OnigUChar *)
name, (OnigUChar *)name_end, regs);
816 smart_str_appendl(pbuf, sp,
p - sp);
819 if (no < 0 || no >= regs->num_regs) {
821 smart_str_appendl(pbuf, sp,
p - sp);
824 if (regs->beg[no] >= 0 && regs->beg[no] < regs->end[no] && (
size_t)regs->end[no] <= subject_len) {
825 smart_str_appendl(pbuf, subject + regs->beg[no], regs->end[no] - regs->beg[no]);
830 smart_str_appendl(pbuf,
p, eos -
p);
850 const char *
retval = php_mb_regex_get_mbctype();
867static int _php_mb_onig_search(
regex_t* reg,
const OnigUChar* str,
const OnigUChar*
end,
const OnigUChar*
start,
868 const OnigUChar* range, OnigRegion* region, OnigOptionType option) {
869 OnigMatchParam *mp = onig_new_match_param();
871 onig_initialize_match_param(mp);
873 onig_set_match_stack_limit_size_of_match_param(mp, (
unsigned int)
MBSTRG(regex_stack_limit));
876 onig_set_retry_limit_in_match_of_match_param(mp, (
unsigned int)
MBSTRG(regex_retry_limit));
879 err = onig_search_with_param(reg, str,
end,
start, range, region, option, mp);
880 onig_free_match_param(mp);
890 char *arg_pattern, *string;
891 size_t arg_pattern_len, string_len;
893 OnigRegion *regs =
NULL;
902 if (arg_pattern_len == 0) {
908 array = zend_try_array_init(array);
917 php_mb_regex_get_mbctype_encoding()
922 options = MBREX(regex_default_options);
924 options |= ONIG_OPTION_IGNORECASE;
927 re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len,
options, MBREX(regex_default_syntax));
933 regs = onig_region_new();
936 if (_php_mb_onig_search(re, (OnigUChar *)
string, (OnigUChar *)(
string + string_len), (OnigUChar *)
string, (OnigUChar *)(
string + string_len), regs, 0) < 0) {
943 for (i = 0; i < regs->num_regs; i++) {
946 if (beg >= 0 && beg <
end && (
size_t)
end <= string_len) {
953 if (onig_number_of_names(re) > 0) {
954 mb_regex_groups_iter_args
args = {array, string, string_len, regs};
955 onig_foreach_name(re, mb_regex_groups_iter, &
args);
962 onig_region_free(regs, 1);
985 size_t arg_pattern_len;
997 OnigSyntaxType *syntax;
998 OnigRegion *regs =
NULL;
1004 OnigUChar *string_lim;
1005 char *description =
NULL;
1007 const mbfl_encoding *enc = php_mb_regex_get_mbctype_encoding();
1011 char *option_str =
NULL;
1012 size_t option_str_len = 0;
1016 &arg_pattern, &arg_pattern_len,
1017 &replace, &replace_len,
1018 &
string, &string_len,
1019 &option_str, &option_str_len) ==
FAILURE) {
1024 &arg_pattern, &arg_pattern_len,
1025 &arg_replace_fci, &arg_replace_fci_cache,
1026 &
string, &string_len,
1027 &option_str, &option_str_len) ==
FAILURE) {
1036 if (option_str !=
NULL) {
1038 if (!_php_mb_regex_init_options(option_str, option_str_len, &
options, &syntax)) {
1042 options |= MBREX(regex_default_options);
1043 syntax = MBREX(regex_default_syntax);
1048 re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len,
options, syntax);
1063 pos = (OnigUChar *)
string;
1064 string_lim = (OnigUChar*)(
string + string_len);
1065 regs = onig_region_new();
1067 err = _php_mb_onig_search(re, (OnigUChar *)
string, (OnigUChar *)string_lim,
pos, (OnigUChar *)string_lim, regs, 0);
1069 OnigUChar err_str[ONIG_MAX_ERROR_MESSAGE_LEN];
1070 onig_error_code_to_str(err_str,
err);
1076 smart_str_appendl(&out_buf, (
char *)
pos, (
size_t)((OnigUChar *)(
string + regs->beg[0]) -
pos));
1079 mb_regex_substitute(pbuf,
string, string_len, replace, replace_len, re, regs, enc);
1088 for (i = 0; i < regs->num_regs; i++) {
1091 if (onig_number_of_names(re) > 0) {
1092 mb_regex_groups_iter_args
args = {&subpats, string, string_len, regs};
1093 onig_foreach_name(re, mb_regex_groups_iter, &
args);
1098 smart_str_0(&eval_buf);
1107 smart_str_free(&eval_buf);
1120 if ((
pos - (OnigUChar *)
string) <
n) {
1121 pos = (OnigUChar *)
string +
n;
1123 if (
pos < string_lim) {
1124 smart_str_appendl(&out_buf, (
char *)
pos, 1);
1130 if (string_lim -
pos > 0) {
1131 smart_str_appendl(&out_buf, (
char *)
pos, string_lim -
pos);
1134 onig_region_free(regs, 0);
1141 onig_region_free(regs, 1);
1143 smart_str_free(&eval_buf);
1146 smart_str_free(&out_buf);
1179 size_t arg_pattern_len;
1181 OnigRegion *regs =
NULL;
1183 OnigUChar *
pos, *chunk_pos;
1202 if ((re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, MBREX(regex_default_options), MBREX(regex_default_syntax))) ==
NULL) {
1208 chunk_pos =
pos = (OnigUChar *)
string;
1210 regs = onig_region_new();
1212 while (
count != 0 && (
size_t)(
pos - (OnigUChar *)
string) < string_len) {
1214 err = _php_mb_onig_search(re, (OnigUChar *)
string, (OnigUChar *)(
string + string_len),
pos, (OnigUChar *)(
string + string_len), regs, 0);
1218 beg = regs->beg[0],
end = regs->end[0];
1220 if ((
size_t)(
pos - (OnigUChar *)
string) <
end) {
1221 if (beg < string_len && beg >= (
size_t)(chunk_pos - (OnigUChar *)
string)) {
1229 chunk_pos =
pos = (OnigUChar *)
string +
end;
1233 onig_region_free(regs, 0);
1236 onig_region_free(regs, 1);
1241 OnigUChar err_str[ONIG_MAX_ERROR_MESSAGE_LEN];
1242 onig_error_code_to_str(err_str,
err);
1249 if ((OnigUChar *)(
string + string_len) > chunk_pos) {
1250 size_t n = ((OnigUChar *)(
string + string_len) - chunk_pos);
1262 size_t arg_pattern_len;
1268 OnigSyntaxType *syntax;
1269 OnigOptionType option = 0;
1274 char *option_str =
NULL;
1275 size_t option_str_len = 0;
1278 &arg_pattern, &arg_pattern_len, &
string, &string_len,
1279 &option_str, &option_str_len)==
FAILURE) {
1283 if (option_str !=
NULL) {
1284 if(!_php_mb_regex_init_options(option_str, option_str_len, &option, &syntax)) {
1288 option |= MBREX(regex_default_options);
1289 syntax = MBREX(regex_default_syntax);
1297 if ((re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, syntax)) ==
NULL) {
1301 mp = onig_new_match_param();
1302 onig_initialize_match_param(mp);
1303 if (
MBSTRG(regex_stack_limit) > 0 &&
MBSTRG(regex_stack_limit) < UINT_MAX) {
1304 onig_set_match_stack_limit_size_of_match_param(mp, (
unsigned int)
MBSTRG(regex_stack_limit));
1306 if (
MBSTRG(regex_retry_limit) > 0 &&
MBSTRG(regex_retry_limit) < UINT_MAX) {
1307 onig_set_retry_limit_in_match_of_match_param(mp, (
unsigned int)
MBSTRG(regex_retry_limit));
1310 err = onig_match_with_param(re, (OnigUChar *)
string, (OnigUChar *)(
string + string_len), (OnigUChar *)
string,
NULL, 0, mp);
1311 onig_free_match_param(mp);
1324 char *arg_pattern =
NULL, *arg_options =
NULL;
1325 size_t arg_pattern_len, arg_options_len;
1330 OnigOptionType option = 0;
1332 OnigSyntaxType *syntax;
1339 _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax);
1341 option |= MBREX(regex_default_options);
1342 syntax = MBREX(regex_default_syntax);
1345 if (MBREX(search_regs)) {
1346 onig_region_free(MBREX(search_regs), 1);
1347 MBREX(search_regs) =
NULL;
1352 if ((MBREX(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, syntax)) ==
NULL) {
1357 pos = MBREX(search_pos);
1361 str = (OnigUChar *)
Z_STRVAL(MBREX(search_str));
1365 if (MBREX(search_re) ==
NULL) {
1375 MBREX(search_regs) = onig_region_new();
1377 err = _php_mb_onig_search(MBREX(search_re), str, str +
len, str +
pos, str +
len, MBREX(search_regs), 0);
1378 if (
err == ONIG_MISMATCH) {
1379 MBREX(search_pos) =
len;
1381 }
else if (
err <= -2) {
1382 OnigUChar err_str[ONIG_MAX_ERROR_MESSAGE_LEN];
1383 onig_error_code_to_str(err_str,
err);
1390 beg = MBREX(search_regs)->beg[0];
1391 end = MBREX(search_regs)->end[0];
1397 n = MBREX(search_regs)->num_regs;
1398 for (i = 0; i <
n; i++) {
1399 beg = MBREX(search_regs)->beg[i];
1400 end = MBREX(search_regs)->end[i];
1401 if (beg >= 0 && beg <=
end &&
end <=
len) {
1407 if (onig_number_of_names(MBREX(search_re)) > 0) {
1408 mb_regex_groups_iter_args
args = {
1414 onig_foreach_name(MBREX(search_re), mb_regex_groups_iter, &
args);
1421 end = MBREX(search_regs)->end[0];
1423 MBREX(search_pos) =
end;
1425 MBREX(search_pos) =
pos + 1;
1430 onig_region_free(MBREX(search_regs), 1);
1431 MBREX(search_regs) = (OnigRegion *)
NULL;
1461 char *arg_pattern =
NULL, *arg_options =
NULL;
1462 size_t arg_pattern_len = 0, arg_options_len = 0;
1463 OnigSyntaxType *syntax =
NULL;
1464 OnigOptionType option;
1470 if (arg_pattern && arg_pattern_len == 0) {
1477 _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax);
1479 option = MBREX(regex_default_options);
1480 syntax = MBREX(regex_default_syntax);
1485 if ((MBREX(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, syntax)) ==
NULL) {
1490 if (!
Z_ISNULL(MBREX(search_str))) {
1497 MBREX(search_pos) = 0;
1500 MBREX(search_pos) =
ZSTR_LEN(arg_str);
1504 if (MBREX(search_regs) !=
NULL) {
1505 onig_region_free(MBREX(search_regs), 1);
1506 MBREX(search_regs) =
NULL;
1526 str = (OnigUChar *)
Z_STRVAL(MBREX(search_str));
1528 n = MBREX(search_regs)->num_regs;
1529 for (i = 0; i <
n; i++) {
1530 beg = MBREX(search_regs)->beg[i];
1531 end = MBREX(search_regs)->end[i];
1532 if (beg >= 0 && beg <=
end &&
end <=
len) {
1538 if (onig_number_of_names(MBREX(search_re)) > 0) {
1539 mb_regex_groups_iter_args
args = {
1545 onig_foreach_name(MBREX(search_re), mb_regex_groups_iter, &
args);
1576 position +=
Z_STRLEN(MBREX(search_str));
1584 MBREX(search_pos) = position;
1591static void _php_mb_regex_set_options(OnigOptionType
options, OnigSyntaxType *syntax, OnigOptionType *prev_options, OnigSyntaxType **prev_syntax)
1593 if (prev_options !=
NULL) {
1594 *prev_options = MBREX(regex_default_options);
1596 if (prev_syntax !=
NULL) {
1597 *prev_syntax = MBREX(regex_default_syntax);
1599 MBREX(regex_default_options) =
options;
1600 MBREX(regex_default_syntax) = syntax;
1607 OnigOptionType opt, prev_opt;
1608 OnigSyntaxType *syntax, *prev_syntax;
1609 char *
string =
NULL;
1614 &
string, &string_len) ==
FAILURE) {
1617 if (
string !=
NULL) {
1620 if(!_php_mb_regex_init_options(
string, string_len, &opt, &syntax)) {
1623 _php_mb_regex_set_options(opt, syntax, &prev_opt, &prev_syntax);
1625 syntax = prev_syntax;
1627 opt = MBREX(regex_default_options);
1628 syntax = MBREX(regex_default_syntax);
1630 _php_mb_regex_get_option_string(
buf,
sizeof(
buf), opt, syntax);
is_callable(mixed $value, bool $syntax_only=false, &$callable_name=null)
count(Countable|array $value, int $mode=COUNT_NORMAL)
zend_ffi_ctype_name_buf buf
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
const mbfl_encoding mbfl_encoding_utf8
const mbfl_encoding * mbfl_name2encoding(const char *name)
MBSTRING_API size_t php_mb_mbchar_bytes(const char *s, const mbfl_encoding *enc)
MBSTRING_API bool php_mb_check_encoding(const char *input, size_t length, const mbfl_encoding *encoding)
mb_split(string $pattern, string $string, int $limit=-1)
mb_eregi_replace(string $pattern, string $replacement, string $string, ?string $options=null)
mb_ereg_search_setpos(int $offset)
mb_ereg_search_pos(?string $pattern=null, ?string $options=null)
mb_ereg_match(string $pattern, string $string, ?string $options=null)
mb_ereg_search(?string $pattern=null, ?string $options=null)
mb_regex_encoding(?string $encoding=null)
mb_ereg_replace(string $pattern, string $replacement, string $string, ?string $options=null)
mb_ereg(string $pattern, string $string, &$matches=null)
mb_ereg_replace_callback(string $pattern, callable $callback, string $string, ?string $options=null)
mb_ereg_search_regs(?string $pattern=null, ?string $options=null)
mb_regex_set_options(?string $options=null)
mb_eregi(string $pattern, string $string, &$matches=null)
mb_ereg_search_init(string $string, ?string $pattern=null, ?string $options=null)
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_RINIT_FUNCTION
#define PHP_RSHUTDOWN_FUNCTION
unsigned const char * end
unsigned const char * pos
PHP_JSON_API size_t int options
xmlCharEncodingHandlerPtr encoding
ZEND_API char * zend_make_compiled_string_description(const char *name)
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API void add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, bool b)
ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length)
ZEND_API zend_result add_next_index_long(zval *arg, zend_long n)
ZEND_API void add_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API void add_index_bool(zval *arg, zend_ulong index, bool b)
ZEND_API void add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length)
ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
struct _zend_fcall_info_cache zend_fcall_info_cache
#define zend_parse_parameters_none()
struct _zend_fcall_info zend_fcall_info
#define ZEND_EXTERN_MODULE_GLOBALS(module_name)
ZEND_API zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache)
#define pefree(ptr, persistent)
#define pemalloc(size, persistent)
#define strcasecmp(s1, s2)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
struct _zend_string zend_string
#define convert_to_string(op)
#define ZEND_LONG_UINT_OVFL(zlong)
#define ZVAL_STR_COPY(z, s)
struct _zend_array HashTable
#define ZVAL_COPY_VALUE(z, v)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)