Skip to content

Commit 41a6625

Browse files
committed
Add UPGRADING for mb_ereg changes
Also some minor code cleanup.
1 parent 8f17826 commit 41a6625

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

UPGRADING

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ BCMath:
9999
. bcmul() and bcpow() now return numbers with the requested scale. Formerly,
100100
the returned numbers may have omitted trailing decimal zeroes.
101101

102+
MBString:
103+
. Due to added support for named captures, mb_ereg_*() patterns using named
104+
captures will behave differently. In particular named captures will be part
105+
of matches and mb_ereg_replace() will interpret additional syntax. See
106+
"New Features" section for more information.
107+
102108
mysqli:
103109
. Prepared statements now properly report the fractional seconds for DATETIME/
104110
TIME/TIMESTAMP columns with decimals specifier (e.g. TIMESTAMP(6) when using
@@ -192,6 +198,21 @@ MBString:
192198
. Mbstring now correctly supports strings larger than 2GB.
193199
. Performance of the mbstring extension has been significantly improved
194200
across the board. The largest improvements are in case conversion functions.
201+
. mb_ereg_*() functions now support named captures. Matching functions like
202+
mb_ereg() will now return named captures both using their group number and
203+
their name, similar to PCRE:
204+
205+
mb_ereg('(?<word>\w+)', '国', $matches);
206+
// => [0 => "国", 1 => "国", "word" => "国"];
207+
208+
Additionally, mb_ereg_replace() now supports the \k<> and \k'' notations
209+
to reference named captures in the replacement string:
210+
211+
mb_ereg_replace('\s*(?<word>\w+)\s*', "_\k<word>_\k'word'_", ' foo ');
212+
// => "_foo_foo_"
213+
214+
\k<> and \k'' can also be used for numbered references, which also works
215+
with group numbers greater than 9.
195216

196217
readline:
197218
. Support for the completion_append_character and completion_suppress_append

ext/mbstring/php_mbregex.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ _php_mb_regex_init_options(const char *parg, size_t narg, OnigOptionType *option
655655
typedef struct mb_regex_groups_iter_args {
656656
zval *groups;
657657
char *search_str;
658-
int search_len;
658+
size_t search_len;
659659
OnigRegion *region;
660660
} mb_regex_groups_iter_args;
661661
/* }}} */
@@ -665,25 +665,19 @@ static int
665665
mb_regex_groups_iter(const OnigUChar* name, const OnigUChar* name_end, int ngroup_num, int* group_nums, regex_t* reg, void* parg)
666666
{
667667
mb_regex_groups_iter_args *args = (mb_regex_groups_iter_args *) parg;
668-
int i, gn, ref, beg, end;
669-
670-
for (i = 0; i < ngroup_num; i++) {
671-
gn = group_nums[i];
672-
ref = onig_name_to_backref_number(reg, name, name_end, args->region);
673-
if (ref != gn) {
674-
/*
675-
* In case of duplicate groups, keep only the last suceeding one
676-
* to be consistent with preg_match with the PCRE_DUPNAMES option.
677-
*/
678-
continue;
679-
}
680-
beg = args->region->beg[gn];
681-
end = args->region->end[gn];
682-
if (beg >= 0 && beg < end && end <= args->search_len) {
683-
add_assoc_stringl_ex(args->groups, (char *)name, name_end - name, &args->search_str[beg], end - beg);
684-
} else {
685-
add_assoc_bool_ex(args->groups, (char *)name, name_end - name, 0);
686-
}
668+
int gn, beg, end;
669+
670+
/*
671+
* In case of duplicate groups, keep only the last suceeding one
672+
* to be consistent with preg_match with the PCRE_DUPNAMES option.
673+
*/
674+
gn = onig_name_to_backref_number(reg, name, name_end, args->region);
675+
beg = args->region->beg[gn];
676+
end = args->region->end[gn];
677+
if (beg >= 0 && beg < end && end <= args->search_len) {
678+
add_assoc_stringl_ex(args->groups, (char *)name, name_end - name, &args->search_str[beg], end - beg);
679+
} else {
680+
add_assoc_bool_ex(args->groups, (char *)name, name_end - name, 0);
687681
}
688682

689683
return 0;

0 commit comments

Comments
 (0)