1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-24 04:50:27 +02:00

Jun T.: 37515: multibyte handling as per 35448.

This commit is contained in:
Barton E. Schaefer 2016-01-08 20:42:00 -08:00
parent 424b417063
commit 5eae5b58b1
3 changed files with 37 additions and 10 deletions

View file

@ -1,5 +1,8 @@
2016-01-08 Barton E. Schaefer <schaefer@zsh.org> 2016-01-08 Barton E. Schaefer <schaefer@zsh.org>
* Jun T.: 37515: Src/Modules/pcre.c, Test/V07pcre.ztst: multibyte
handling as per 35448.
* unposted (cf. Jun T.: 37516): Src/builtin.c: refine READ_MSTREAM * unposted (cf. Jun T.: 37516): Src/builtin.c: refine READ_MSTREAM
to avoid unsequenced evaluation to avoid unsequenced evaluation

View file

@ -190,18 +190,25 @@ zpcre_get_substrings(char *arg, int *ovec, int ret, char *matchvar,
if (want_begin_end) { if (want_begin_end) {
char *ptr = arg; char *ptr = arg;
zlong offs = 0; zlong offs = 0;
int clen, leftlen;
/* Count the characters before the match */ /* Count the characters before the match */
MB_METACHARINIT(); MB_CHARINIT();
while (ptr < arg + ovec[0]) { leftlen = ovec[0];
while (leftlen) {
offs++; offs++;
ptr += MB_METACHARLEN(ptr); clen = MB_CHARLEN(ptr, leftlen);
ptr += clen;
leftlen -= clen;
} }
setiparam("MBEGIN", offs + !isset(KSHARRAYS)); setiparam("MBEGIN", offs + !isset(KSHARRAYS));
/* Add on the characters in the match */ /* Add on the characters in the match */
while (ptr < arg + ovec[1]) { leftlen = ovec[1] - ovec[0];
while (leftlen) {
offs++; offs++;
ptr += MB_METACHARLEN(ptr); clen = MB_CHARLEN(ptr, leftlen);
ptr += clen;
leftlen -= clen;
} }
setiparam("MEND", offs + !isset(KSHARRAYS) - 1); setiparam("MEND", offs + !isset(KSHARRAYS) - 1);
if (nelem) { if (nelem) {
@ -219,17 +226,23 @@ zpcre_get_substrings(char *arg, int *ovec, int ret, char *matchvar,
ptr = arg; ptr = arg;
offs = 0; offs = 0;
/* Find the start offset */ /* Find the start offset */
MB_METACHARINIT(); MB_CHARINIT();
while (ptr < arg + ipair[0]) { leftlen = ipair[0];
while (leftlen) {
offs++; offs++;
ptr += MB_METACHARLEN(ptr); clen = MB_CHARLEN(ptr, leftlen);
ptr += clen;
leftlen -= clen;
} }
convbase(buf, offs + !isset(KSHARRAYS), 10); convbase(buf, offs + !isset(KSHARRAYS), 10);
*bptr = ztrdup(buf); *bptr = ztrdup(buf);
/* Continue to the end offset */ /* Continue to the end offset */
while (ptr < arg + ipair[1]) { leftlen = ipair[1] - ipair[0];
while (leftlen) {
offs++; offs++;
ptr += MB_METACHARLEN(ptr); clen = MB_CHARLEN(ptr, leftlen);
ptr += clen;
leftlen -= clen;
} }
convbase(buf, offs + !isset(KSHARRAYS) - 1, 10); convbase(buf, offs + !isset(KSHARRAYS) - 1, 10);
*eptr = ztrdup(buf); *eptr = ztrdup(buf);

View file

@ -37,6 +37,17 @@
>o→b >o→b
>→ >→
unset match mend
s=$'\u00a0'
[[ $s =~ '^.$' ]] && print OK
[[ A${s}B =~ .(.). && $match[1] == $s ]] && print OK
[[ A${s}${s}B =~ A([^[:ascii:]]*)B && $mend[1] == 3 ]] && print OK
unset s
0:Raw IMETA characters in input string
>OK
>OK
>OK
[[ foo =~ f.+ ]] ; print $? [[ foo =~ f.+ ]] ; print $?
[[ foo =~ x.+ ]] ; print $? [[ foo =~ x.+ ]] ; print $?
[[ ! foo =~ f.+ ]] ; print $? [[ ! foo =~ f.+ ]] ; print $?