Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Index of element after width of characters



I can resign from the "," and stay with "<" and ">" if Bart agrees.
The comma would be more complicated than the rest, having 3 possible
values: index, -1, empty string. Having only "<" and ">" it's easy to
detect that the limit doesn't divide any char in half:

a="測句a"
idx1=${(<:2:)a}
    idx1=1 # 測
idx2=${(>:2:)a}
    idx2=2 # 句
idx3=${(,:2:)a}
    idx3=

a="測句a"
idx1=${(<:3:)a}
    idx1=1 # 測
idx2=${(>:3:)a}
    idx2=3 # a
idx3=${(,:3:)a}
    idx3=2 # 句

As it can be seen ;) when a character is divided in half by the width
limit then indexes returned by < and > differ by 2. So a simple test
allows to detect this and compute the period's index: idx1+1.

Your syntax is very complicated, we should go for < and > as this is
important functionality that allows to use $COLUMNS, construct
prompts, format text. Characters < and > are related, it's good that
they will be allocated for the same feature.

Best regards,
Sebastian Gniazdowski


On 28 October 2015 at 14:31, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On Wed, Oct 28, 2015 at 12:38 PM, Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
>> After thinking this through I would want to use "<", ",", ">". Could I
>> allocate those symbols? Very mnemonic and nice, the use would be
>> ${(<:10:)a}, ${(,:10:)a}, ${(>:10:)a} for index before width, index at
>> width, index after width. I checked that they work with parser.
>>
>> PS. The code works in D07multibyte.ztst, so the tests issue is solved.
>
> Wouldn't it make more sense to use syntax like $a[(y)10,-1] and
> $a[1,(y)10] ? That's also less likely to trouble Bart since we only
> have about 9 flags in that namespace. For example the (w) flag works
> this way, making the number refer to words rather than characters in
> the string.
>
> --
> Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author