From: Sebastian Gniazdowski <psprint@zdharma.org>
To: zsh-workers@zsh.org
Subject: RE: (m)-flag for boundary cases
Date: Tue, 21 Mar 2017 14:02:13 +0100 [thread overview]
Message-ID: <etPan.58d12455.2eb141f2.378f@MacMini.local> (raw)
> Try this? Works for characters that are 2 columns wide. If you have
> a mix of character widths, probably a custom math function to use in the
> subscript ...
>
> dw=3 # Desired width
> echo ${(mr:dw::_:)a[1,${(m)#a[1,dw-1]}>dw?dw/2:dw]}
Mixed character widths are possibile. Following cases can occur:
1. a="測試a句"; echo ${(mr:7:)a},
測試a句,
2. a="測試a句"; echo ${(mr:6:)a},
測試a句,
3. a="測試a句"; echo ${(mr:5:)a},
測試a,
4. a="測試a句"; echo ${(mr:4:)a},
測試,
Now a try with minus-one:
------------------------
1. a="測試a句"; echo ${(mr:7-1:)a},
測試a句,
2. a="測試a句"; echo ${(mr:6-1:)a},
測試a,
3. a="測試a句"; echo ${(mr:5-1:)a},
測試, # problem
4. a="測試a句"; echo ${(mr:4-1:)a},
測試,
So if one could fix the trailing-a absence, it seems it would work. Did following:
dw=5; a="測試a句"; echo ${(mr,${(m)#${(mr:dw:)a}[-1]} > 1 ? dw-1 : dw,)a}
測試a
dw=3; a="測試a句"; echo ${(mr,${(m)#${(mr:dw:)a}[-1]} > 1 ? dw-1 : dw,)a}
測
But not sure if I will commit this.
--
Sebastian Gniazdowski
psprint@zdharma.org
next reply other threads:[~2017-03-21 13:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-21 13:02 Sebastian Gniazdowski [this message]
2017-04-02 22:57 ` Bart Schaefer
-- strict thread matches above, loose matches on Subject: below --
2017-03-20 14:33 Sebastian Gniazdowski
2017-03-20 16:00 ` Sebastian Gniazdowski
2017-03-20 16:43 ` Bart Schaefer
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=etPan.58d12455.2eb141f2.378f@MacMini.local \
--to=psprint@zdharma.org \
--cc=zsh-workers@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).