zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH] Index of element after width of characters
Date: Thu, 29 Oct 2015 09:42:26 +0000	[thread overview]
Message-ID: <20151029094226.1e636040@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <151028160716.ZM1300@torch.brasslantern.com>

On Wed, 28 Oct 2015 16:07:16 -0700
Bart Schaefer <schaefer@brasslantern.com> 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.

pws


      reply	other threads:[~2015-10-29  9:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-27 17:18 Sebastian Gniazdowski
2015-10-27 19:41 ` Mikael Magnusson
2015-10-27 19:55 ` Sebastian Gniazdowski
2015-10-27 21:20 ` Bart Schaefer
2015-10-28  7:46   ` Sebastian Gniazdowski
2015-10-28  7:54     ` Sebastian Gniazdowski
2015-10-28 11:38       ` Sebastian Gniazdowski
2015-10-28 13:31         ` Mikael Magnusson
2015-10-28 15:46           ` Sebastian Gniazdowski
2015-10-28 15:59             ` Peter Stephenson
2015-10-28 16:37               ` Sebastian Gniazdowski
2015-10-28 23:07               ` Bart Schaefer
2015-10-29  9:42                 ` Peter Stephenson [this message]

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=20151029094226.1e636040@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --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).