zsh-workers
 help / color / mirror / code / Atom feed
* Re: Match length and multibyte characters
       [not found] <CAC_auRfyDuJ-JoeSE9zfnhO=fy4bjOrK0rT8=97O_XeE4SKxNA@mail.gmail.com>
@ 2015-09-11 18:31 ` Jun T.
  2015-09-11 23:08   ` Bart Schaefer
       [not found] ` <FCD65B5C-D8F2-466B-AE3C-D34131252659@kba.biglobe.ne.jp>
  1 sibling, 1 reply; 3+ messages in thread
From: Jun T. @ 2015-09-11 18:31 UTC (permalink / raw)
  To: zsh-workers

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 += 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)
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 @@
 >Ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ  ἦν ὁ λόγος
 >Ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ 
 
+  a="1ë34ë6"
+  print ${(BEN)a#*4}
+  print ${(BEN)a##*ë}
+  print ${(BEN)a%4*}
+  print ${(BEN)a%%ë*}
+  print ${(SBEN)a#ë3}
+  print ${(SBEN)a%4ë}
+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=(κατέβην χθὲς εἰς Πειραιᾶ)
   print ${(l.3..¥.r.3..£.)foo}
   print ${(l.4..¥.r.2..£.)foo}




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Match length and multibyte characters
       [not found] ` <FCD65B5C-D8F2-466B-AE3C-D34131252659@kba.biglobe.ne.jp>
@ 2015-09-11 19:37   ` Jun T.
  0 siblings, 0 replies; 3+ messages in thread
From: Jun T. @ 2015-09-11 19:37 UTC (permalink / raw)
  To: zsh-workers


2015/09/12 03:02, I wrote:
> Otherwise, 10 comes before 2.

Sorry, this is if sorting in ascending order, i.e., the (o) flag.

(o)	1 10 2 20 3
(O)	3 20 2 10 1
(n)	1 2 3 10 20
(On)	20 10 3 2 1	this is what you want.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Match length and multibyte characters
  2015-09-11 18:31 ` Match length and multibyte characters Jun T.
@ 2015-09-11 23:08   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2015-09-11 23:08 UTC (permalink / raw)
  To: zsh-workers

On Sep 12,  3:31am, Jun T. wrote:
} Subject: Re: Match length and multibyte characters
}
} The following (with test) is a patch I sent to zsh-users
} as a reply to users:20537.

Looks reasonable to me.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-11 23:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAC_auRfyDuJ-JoeSE9zfnhO=fy4bjOrK0rT8=97O_XeE4SKxNA@mail.gmail.com>
2015-09-11 18:31 ` Match length and multibyte characters Jun T.
2015-09-11 23:08   ` Bart Schaefer
     [not found] ` <FCD65B5C-D8F2-466B-AE3C-D34131252659@kba.biglobe.ne.jp>
2015-09-11 19:37   ` Jun T.

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).