From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11654 invoked by alias); 10 Mar 2011 15:19:38 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28880 Received: (qmail 11473 invoked from network); 10 Mar 2011 15:19:27 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110310071902.ZM15166@torch.brasslantern.com> Date: Thu, 10 Mar 2011 07:19:02 -0800 In-reply-to: Comments: In reply to Mikael Magnusson "support negative LEN in ${VAR:OFFSET:LEN}" (Mar 10, 12:10pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh workers Subject: Re: support negative LEN in ${VAR:OFFSET:LEN} MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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