* PATCH: ${(m)#...}
@ 2008-04-03 21:01 Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2008-04-03 21:01 UTC (permalink / raw)
To: Zsh hackers list
I introduced the (m) flag to calculate the width of a multibyte
character for the (l) and (r) padding flags. I'm not sure why I didn't
introduce it for parameter lengths, too, but now I'm finding that
useful. ${(m)#...} now returns the printable width of the string.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.88
diff -u -r1.88 expn.yo
--- Doc/Zsh/expn.yo 1 Feb 2008 19:59:48 -0000 1.88
+++ Doc/Zsh/expn.yo 3 Apr 2008 20:57:32 -0000
@@ -943,11 +943,13 @@
mechanism to be used for generating repetitions of control characters.
)
item(tt(m))(
-Only useful together with tt(l) and tt(r) when the tt(MULTIBYTE) option
+Only useful together with one of the flags tt(l) or tt(r) or with the
+tt(#) length operator when the tt(MULTIBYTE) option
is in effect. Use the character width reported by the system in
-calculating the how much of the string it occupies. Most printable
-characters have a width of one unit, however certain Asian character sets
-and certain special effects use wider characters.
+calculating the how much of the string it occupies or the overall
+length of the string. Most printable characters have a width of one
+unit, however certain Asian character sets and certain special effects
+use wider characters; combining characters have zero width.
)
item(tt(r:)var(expr)tt(::)var(string1)tt(::)var(string2)tt(:))(
As tt(l), but pad the words on the right and insert var(string2)
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.83
diff -u -r1.83 subst.c
--- Src/subst.c 27 Feb 2008 15:51:27 -0000 1.83
+++ Src/subst.c 3 Apr 2008 20:57:33 -0000
@@ -2589,7 +2589,8 @@
else if (getlen == 2) {
if (*aval)
for (len = -sl, ctr = aval;
- len += sl + MB_METASTRLEN(*ctr), *++ctr;);
+ len += sl + MB_METASTRLEN2(*ctr, multi_width),
+ *++ctr;);
}
else
for (ctr = aval;
@@ -2597,7 +2598,7 @@
len += wordcount(*ctr, spsep, getlen > 3), ctr++);
} else {
if (getlen < 3)
- len = MB_METASTRLEN(val);
+ len = MB_METASTRLEN2(val, multi_width);
else
len = wordcount(val, spsep, getlen > 3);
}
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-04-03 21:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-03 21:01 PATCH: ${(m)#...} Peter Stephenson
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).