From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: ${(m)#...}
Date: Thu, 03 Apr 2008 22:01:29 +0100 [thread overview]
Message-ID: <15699.1207256489@pws-pc> (raw)
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/
reply other threads:[~2008-04-03 21:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=15699.1207256489@pws-pc \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@sunsite.dk \
/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).