From 41a6625c09071feb22efb0814a9cb208c27698d0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 6 Jul 2018 23:42:16 +0200 Subject: Add UPGRADING for mb_ereg changes Also some minor code cleanup. --- ext/mbstring/php_mbregex.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'ext/mbstring/php_mbregex.c') diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index d048376062..3349025491 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -655,7 +655,7 @@ _php_mb_regex_init_options(const char *parg, size_t narg, OnigOptionType *option typedef struct mb_regex_groups_iter_args { zval *groups; char *search_str; - int search_len; + size_t search_len; OnigRegion *region; } mb_regex_groups_iter_args; /* }}} */ @@ -665,25 +665,19 @@ static int mb_regex_groups_iter(const OnigUChar* name, const OnigUChar* name_end, int ngroup_num, int* group_nums, regex_t* reg, void* parg) { mb_regex_groups_iter_args *args = (mb_regex_groups_iter_args *) parg; - int i, gn, ref, beg, end; - - for (i = 0; i < ngroup_num; i++) { - gn = group_nums[i]; - ref = onig_name_to_backref_number(reg, name, name_end, args->region); - if (ref != gn) { - /* - * In case of duplicate groups, keep only the last suceeding one - * to be consistent with preg_match with the PCRE_DUPNAMES option. - */ - continue; - } - beg = args->region->beg[gn]; - end = args->region->end[gn]; - if (beg >= 0 && beg < end && end <= args->search_len) { - add_assoc_stringl_ex(args->groups, (char *)name, name_end - name, &args->search_str[beg], end - beg); - } else { - add_assoc_bool_ex(args->groups, (char *)name, name_end - name, 0); - } + int gn, beg, end; + + /* + * In case of duplicate groups, keep only the last suceeding one + * to be consistent with preg_match with the PCRE_DUPNAMES option. + */ + gn = onig_name_to_backref_number(reg, name, name_end, args->region); + beg = args->region->beg[gn]; + end = args->region->end[gn]; + if (beg >= 0 && beg < end && end <= args->search_len) { + add_assoc_stringl_ex(args->groups, (char *)name, name_end - name, &args->search_str[beg], end - beg); + } else { + add_assoc_bool_ex(args->groups, (char *)name, name_end - name, 0); } return 0; -- cgit v1.2.1