summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2018-07-06 23:42:16 +0200
committerNikita Popov <nikita.ppv@gmail.com>2018-07-07 11:06:29 +0200
commit41a6625c09071feb22efb0814a9cb208c27698d0 (patch)
treeb3a4661efff547781eca212aeb27464f0e038323
parent8f1782678e9a790cf696da1268a7dfcb38e22312 (diff)
downloadphp-git-41a6625c09071feb22efb0814a9cb208c27698d0.tar.gz
Add UPGRADING for mb_ereg changes
Also some minor code cleanup.
-rw-r--r--UPGRADING21
-rw-r--r--ext/mbstring/php_mbregex.c34
2 files changed, 35 insertions, 20 deletions
diff --git a/UPGRADING b/UPGRADING
index c02d315422..dc749ee67c 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 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;