zsh-users
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: Erik Bernstein <erik@fscking.org>, zsh-users@zsh.org
Subject: Re: Match length and multibyte characters
Date: Sat, 12 Sep 2015 03:02:56 +0900	[thread overview]
Message-ID: <FCD65B5C-D8F2-466B-AE3C-D34131252659@kba.biglobe.ne.jp> (raw)
In-Reply-To: <CAC_auRfyDuJ-JoeSE9zfnhO=fy4bjOrK0rT8=97O_XeE4SKxNA@mail.gmail.com>


2015/09/10 20:35, Erik Bernstein <erik@fscking.org> wrote:
> % array=(a ä a)
> % print ${${(O)array//(#m)*/${#MATCH}}[1]} ${${(ON)array%%*}[1]}
> 1 2
> 
> Can maybe someone shed some light on whether the second version is
> supposed to work with multibyte characters and,

The second version returns 2 because ä is a 2 byte character in UTF-8.
This is a bug of the current zsh; all the flags N, B and E do not work
well with multibyte characters in ${...#...}, ${...%...} etc.

The patch below may fix the bug.

BTW, in your example, it is better to replace the flag (O) by (On)
so that the length is sorted in numerical order. Otherwise, 10 comes
before 2.


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 += 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 += (bl = 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 += (bl = 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 += (bl = strlen(buf));
     }
     if (bl)






  reply	other threads:[~2015-09-11 18:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-10 11:35 Erik Bernstein
2015-09-11 18:02 ` Jun T. [this message]
2015-09-11 19:40   ` Jun T.
2015-09-17 15:14   ` Erik Bernstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FCD65B5C-D8F2-466B-AE3C-D34131252659@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=erik@fscking.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).