Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
RE: (m)-flag for boundary cases
- X-seq: zsh-workers 40877
- From: Sebastian Gniazdowski <psprint@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: RE: (m)-flag for boundary cases
- Date: Tue, 21 Mar 2017 14:02:13 +0100
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
> 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@xxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author