From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17446 invoked by alias); 11 Sep 2015 18:32:30 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36491 Received: (qmail 21716 invoked from network); 11 Sep 2015 18:32:29 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Biglobe-Sender: Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: Match length and multibyte characters From: "Jun T." In-Reply-To: Date: Sat, 12 Sep 2015 03:31:16 +0900 Content-Transfer-Encoding: quoted-printable Message-Id: <2326255F-DDB4-4277-8B59-9851BA0BF797@kba.biglobe.ne.jp> References: To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.1878.6) X-Biglobe-Spnum: 50101 The following (with test) is a patch I sent to zsh-users as a reply to users:20537. The use of the macro MB_METASTRLEN2END means, if MULTIBYTE_SUPPORT if = off, ztrlenend(s+b,s+e) will be used instead of (e-b). I think this is better because the string is metafied. diff --git a/Src/glob.c b/Src/glob.c index dea1bf5..43d135b 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -2491,17 +2491,17 @@ get_match_ret(char *s, int b, int e, int fl, = char *replstr, ll +=3D 1 + (l - (e - b)); if (fl & SUB_BIND) { /* position of start of matched portion */ - sprintf(buf, "%d ", b + 1); + sprintf(buf, "%d ", MB_METASTRLEN2END(s, 0, s+b) + 1); ll +=3D (bl =3D strlen(buf)); } if (fl & SUB_EIND) { /* position of end of matched portion */ - sprintf(buf + bl, "%d ", e + 1); + sprintf(buf + bl, "%d ", MB_METASTRLEN2END(s, 0, s+e) + 1); ll +=3D (bl =3D strlen(buf)); } if (fl & SUB_LEN) { /* length of matched portion */ - sprintf(buf + bl, "%d ", e - b); + sprintf(buf + bl, "%d ", MB_METASTRLEN2END(s+b, 0, s+e)); ll +=3D (bl =3D strlen(buf)); } if (bl) diff --git a/Test/D07multibyte.ztst b/Test/D07multibyte.ztst index ace191f..5ae9b2c 100644 --- a/Test/D07multibyte.ztst +++ b/Test/D07multibyte.ztst @@ -293,6 +293,21 @@ >=E1=BC=98=CE=BD =E1=BC=80=CF=81=CF=87=E1=BF=87 =E1=BC=A6=CE=BD =E1=BD=81= =CE=BB=CF=8C=CE=B3=CE=BF=CF=82, =CE=BA=CE=B1=E1=BD=B6 =E1=BD=81 = =CE=BB=CF=8C=CE=B3=CE=BF=CF=82 =E1=BC=A6=CE=BD =CF=80=CF=81=E1=BD=B8=CF=82= =CF=84=E1=BD=B8=CE=BD =CE=B8=CE=B5=CF=8C=CE=BD, =CE=BA=CE=B1=E1=BD=B6 = =E1=BC=A6=CE=BD =E1=BD=81 =CE=BB=CF=8C=CE=B3=CE=BF=CF=82 >=E1=BC=98=CE=BD =E1=BC=80=CF=81=CF=87=E1=BF=87 =E1=BC=A6=CE=BD =E1=BD=81= =CE=BB=CF=8C=CE=B3=CE=BF=CF=82, =CE=BA=CE=B1=E1=BD=B6 =E1=BD=81 = =CE=BB=CF=8C=CE=B3=CE=BF=CF=82 =E1=BC=A6=CE=BD =CF=80=CF=81=E1=BD=B8=CF=82= =CF=84=E1=BD=B8=CE=BD =CE=B8=CE=B5=CF=8C=CE=BD, =CE=BA=CE=B1=E1=BD=B6=20= =20 + a=3D"1=C3=AB34=C3=AB6" + print ${(BEN)a#*4} + print ${(BEN)a##*=C3=AB} + print ${(BEN)a%4*} + print ${(BEN)a%%=C3=AB*} + print ${(SBEN)a#=C3=AB3} + print ${(SBEN)a%4=C3=AB} +0:Flags B, E, N and S in ${...#...} and ${...%...} +>1 5 4 +>1 6 5 +>4 7 3 +>2 7 5 +>2 4 2 +>4 6 2 + foo=3D(=CE=BA=CE=B1=CF=84=CE=AD=CE=B2=CE=B7=CE=BD =CF=87=CE=B8=E1=BD=B2= =CF=82 =CE=B5=E1=BC=B0=CF=82 =CE=A0=CE=B5=CE=B9=CF=81=CE=B1=CE=B9=E1=BE=B6= ) print ${(l.3..=C2=A5.r.3..=C2=A3.)foo} print ${(l.4..=C2=A5.r.2..=C2=A3.)foo}