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

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

On Wed, 28 Oct 2015 16:07:16 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Oct 28,  3:59pm, Peter Stephenson wrote:
> }
> } Mikael's right, actually --- this is an indexing problem and more
> } consistently done with subscripts.  It should actually be simpler than
> } the existing code for space-delimited words in scalars.
> Doesn't subscripting already treat multi-byte characters as single
> positions in strings?  The one strangeness may be characters that
> have zero disply width.
> So I take it that what we need is subscripting that counts display
> widths rather than character widths.

Yes, in MULTIBYTE mode it counts characters.  It's slightly more
complicated when you take account of the width since there isn't a
one-to-one match from width-based indices to characters in the string.
In particular, if you ask for foo[1,(?)2] (with whatever character is
used for the syntax instead of "?") when the first character is width 2,
you either get nothing or a complete chracter taking you to character
position 2.

I suppose ${#foo[1,(?)2]} is an easy way to tell you how many characters
were actually included.


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