com php-src: Add UPGRADING for mb_ereg changes: UPGRADI NG ext/mbstring/php_mbregex.c
| From: | Nikita Popov | Date: | Sat, 07 Jul 2018 09:06:29 +0000 |
| Subject: | com php-src: Add UPGRADING for mb_ereg changes: UPGRADI NG ext/mbstring/php_mbregex.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-102461@lists.php.net to get a copy of this message | ||
Commit: 41a6625c09071feb22efb0814a9cb208c27698d0
Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 6 Jul 2018 23:42:16 +0200
Parents: 8f1782678e9a790cf696da1268a7dfcb38e22312
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=41a6625c09071feb22efb0814a9cb208c27698d0
Log:
Add UPGRADING for mb_ereg changes
Also some minor code cleanup.
Changed paths:
M UPGRADING
M ext/mbstring/php_mbregex.c
Diff:
diff --git a/UPGRADING b/UPGRADING
index c02d315..dc749ee 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -99,6 +99,12 @@ BCMath:
. bcmul() and bcpow() now return numbers with the requested scale. Formerly,
the returned numbers may have omitted trailing decimal zeroes.
+MBString:
+ . Due to added support for named captures, mb_ereg_*() patterns using named
+ captures will behave differently. In particular named captures will be part
+ of matches and mb_ereg_replace() will interpret additional syntax. See
+ "New Features" section for more information.
+
mysqli:
. Prepared statements now properly report the fractional seconds for DATETIME/
TIME/TIMESTAMP columns with decimals specifier (e.g. TIMESTAMP(6) when using
@@ -192,6 +198,21 @@ MBString:
. Mbstring now correctly supports strings larger than 2GB.
. Performance of the mbstring extension has been significantly improved
across the board. The largest improvements are in case conversion functions.
+ . mb_ereg_*() functions now support named captures. Matching functions like
+ mb_ereg() will now return named captures both using their group number and
+ their name, similar to PCRE:
+
+ mb_ereg('(?<word>\w+)', '国', $matches);
+ // => [0 => "国", 1 => "国", "word" =>
"国"];
+
+ Additionally, mb_ereg_replace() now supports the \k<> and \k'' notations
+ to reference named captures in the replacement string:
+
+ mb_ereg_replace('\s*(?<word>\w+)\s*',
"_\k<word>_\k'word'_", ' foo ');
+ // => "_foo_foo_"
+
+ \k<> and \k'' can also be used for numbered references, which also works
+ with group numbers greater than 9.
readline:
. Support for the completion_append_character and completion_suppress_append
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index d048376..3349025 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;