From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13111 invoked by alias); 27 Apr 2012 20:39:01 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17026 Received: (qmail 26617 invoked from network); 27 Apr 2012 20:38:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 74.125.82.171 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-proxyuser-ip:date:from:to:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=fm36+Z82HIUX2zyhdEgi6+ai72ZwQOtVKZWqdyWzO78=; b=mkK765OLhGeZ0T/clxpyyyufRqFCMywMhpYtZUnEibWbTZE6QHFMeAuR3pQxmjz8i9 1M375xaAot7JeOkYae+E/V99bC6iIlg4pPP5GjjDHeAy7PAAGquqVcMPxPdvfkPwA0U0 ZGvfK70dZmVnGXDqnBt9bWyNsiXBjELzwlHwFrfU+1j9pm04vJXSvfWFoXWRvnMsiUKE xbRQDdGhDKZg2Jq0ITnhkOfbq4CA9zmSuOwcUGucpsP7i0X9l8smeT5Jul8ZIm+SshCj 823rImbhEkNFJgZ8Jc2rMToXN28Pyr5+fd8l6p7K0kzLzI7kg+dJnjqY1TK0Y0zveEDb PJUA== X-ProxyUser-IP: 86.6.29.42 Date: Fri, 27 Apr 2012 21:38:37 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: ${(s::)VAR} vs "${(s::)VAR}" Message-ID: <20120427213837.1b861851@pws-pc.ntlworld.com> In-Reply-To: References: X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnLXtE8CpKGq0WVrBUflAiZYhgzsfBUupmJmY9Y9Fnlk77J2X+omx/jCa+yeuFClQoTJFl3 On Thu, 26 Apr 2012 16:48:00 -0400 Kynn Jones wrote: > % (VAR=123; for c ( "${(s::)VAR}" ) echo ">$c<") > >1< > >2< > >3< > >< I think I can say with some degree of certainty I haven't a clue what's going on here, and it doesn't agree with the documentation "An empty string may also be given in which case every character will be a separate element" since you don't magically get an extra character by sticking the expression in double quotes. This comes from the function wordcount() in utils.c, which is called in a couple of functions used for splitting words, none of which has any comments apart from a few speculations from me dating from 2003. The function takes a mysterious argument mul which presumably has got something to do with doing something multiple times. It seems hard to believe it should ever be counting an extra character when it's reached the null at the end of the string. The following seems to fix it without any obvious side effects. Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.268 diff -p -u -r1.268 utils.c --- Src/utils.c 16 Apr 2012 11:26:10 -0000 1.268 +++ Src/utils.c 27 Apr 2012 20:35:40 -0000 @@ -3114,7 +3114,7 @@ wordcount(char *s, char *sep, int mul) r = 1; sl = strlen(sep); for (; (c = findsep(&s, sep, 0)) >= 0; s += sl) - if ((c && *(s + sl)) || mul) + if ((c || mul) && *(s + sl)) r++; } else { char *t = s; Index: Test/D04parameter.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v retrieving revision 1.67 diff -p -u -r1.67 D04parameter.ztst --- Test/D04parameter.ztst 22 Apr 2012 18:39:53 -0000 1.67 +++ Test/D04parameter.ztst 27 Apr 2012 20:35:40 -0000 @@ -1304,6 +1304,19 @@ >in >it + str=abcd + print -l ${(s..)str} + print -l "${(s..)str}" +0:splitting of strings into characters +>a +>b +>c +>d +>a +>b +>c +>d + array=('%' '$' 'j' '*' '$foo') print ${array[(i)*]} "${array[(i)*]}" print ${array[(ie)*]} "${array[(ie)*]}" -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/