zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: support negative LEN in ${VAR:OFFSET:LEN}
Date: Thu, 10 Mar 2011 07:19:02 -0800	[thread overview]
Message-ID: <110310071902.ZM15166@torch.brasslantern.com> (raw)
In-Reply-To: <AANLkTinMNB+5_+ZG1-FgwRcG-2KP88Td8bhOYYE1rRsE@mail.gmail.com>

On Mar 10, 12:10pm, Mikael Magnusson wrote:
} Subject: support negative LEN in ${VAR:OFFSET:LEN}
}
} +var(length) is treated directly as a length when it is positive.
} +When it is negative, it works as an offset just like var(offset). If
} +this results in a negative length, a diagnostic will be printed and
} +nothing will be substituted.

I don't object to adding the feature, but that documentation is a bit
confusing.  Also, when writing documentation, it's almost always better
to avoid passive phrasing like "x will be y".  Perhaps:

  When positive, var(length) counts from the var(offset) position
  toward the end of the scalar or array.  When negative, var(length)
  counts back from the end.  If this results in a position smaller
  than var(offset), a diagnostic is printed and nothing is substituted.

The equivalent $var[start,end] expression would not print a diagnostic.
Does bash really work that way?  That is, you have to know the length
of the string in order to safely count backwards from the end of it?

} +   foo="123456789"
} +   print ${foo:5:-6}
} +1:Regression test for total length < 0 in string
} +?(eval):2: substring expression < 0: -2

Is that what bash's diagnostic looks like?  If so we should borrow
consistently, but it'd be a lot clearer if it said

    substring expression: 3 < 5


  reply	other threads:[~2011-03-10 15:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-10 11:10 Mikael Magnusson
2011-03-10 15:19 ` Bart Schaefer [this message]
2011-03-10 15:31   ` Mikael Magnusson
2011-03-16 15:04     ` Mikael Magnusson
2011-03-16 16:21       ` Bart Schaefer
2011-05-11 15:39         ` PATCH: " Mikael Magnusson

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=110310071902.ZM15166@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).