From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23017 invoked by alias); 9 Oct 2014 21:48:42 -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: 33411 Received: (qmail 28619 invoked from network); 9 Oct 2014 21:48:40 -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.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=q029jllYklBBLGICFyRU6sy45lJeBvc7Avz4cVoGOv4=; b=nnG/asTJELXXe5TrNFP4ZtnEIGRE26fMge3ek/1Kvh4kzn940NI5qJxW8XiouZ4V+J jSbrvlTAipX4Vrv6sK+SC4eFmRWCTwEjXWIAYU0l9PHmZXW9mXrLhbN1C86j+sDHps4O 2o658eNSNz6Xm0wwzTGiJ7bRSBX+MsQxzhUmvjCiaLUD1+PksU8kO4sEoz0380gM6RYi LQJSZ8H9beP7DjU1V6yI+D5sVtUA8uXWMFn2FnHwUOKRp0BaZFxq04vVSJaIXNiJyAV6 oBaFQMOk4QVgVO67r4tdUnY3zmydIb9/tcCE9J0qB1Mlvup8PRv4fOJWc6R1YJdckCnp TZ7Q== MIME-Version: 1.0 X-Received: by 10.42.106.204 with SMTP id a12mr11568116icp.88.1412891317447; Thu, 09 Oct 2014 14:48:37 -0700 (PDT) In-Reply-To: <20141009221459.7512f179@pws-pc.ntlworld.com> References: <5436A310.7040101@gmail.com> <20141009221459.7512f179@pws-pc.ntlworld.com> Date: Thu, 9 Oct 2014 23:48:37 +0200 Message-ID: Subject: =?UTF-8?Q?Re=3A_=28s=29_splitting_=E2=80=93_is_there_any_way_to_provide_=C2=AB?= =?UTF-8?Q?dynamic=C2=BB_separator?= From: Mikael Magnusson To: Peter Stephenson Cc: zsh workers Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 9 October 2014 23:14, Peter Stephenson wro= te: > On Thu, 09 Oct 2014 21:00:32 +0600 > Vasiliy Ivanov wrote: >> Sorry if I (maybe) missed something obvious, but I failed to find a way = to use separator from >> parameter (e.g. a=3D'1:2:3'; sep=3D':'; print -l ${(s.$sep.)a}). >> I think this is because expansion/substitution are not available in >> flags? If so, is there any another way for such a =C2=ABdynamic=C2=BB s= plitting? > > I don't think you've missed anything obvious or elegant. > > One way is > > (){ > local IFS=3D$sep > print -l ${=3Da} > } > > Or if you can rely on not having whitespace > > print -l ${=3D${a//:/ }} > > Or, of course, > > eval print -l '${(s.'$sep'.)a}' > > as long as you can sanity check $sep. > > > Of course there's nothing to stop us adding a simple parameter > substitution as a special case at this point (or any similarly delimited > parameter argument) ... Can't see how this can do much harm since it > sure as heck *looks* like a parameter expansion. I checked to make sure you can still do (s:$:) and that does still work. Moving into extremely unlikely corner-case land, (s:$b:) would split on the literal string $b before. With the patch, it actually still does, but only if b is unset. If b is set, then it is expanded and the expansion is split on instead. So the only problem here would be if someone used to split on a literal string $foo and then foo is set, their code would stop working. I don't know if it's worth it but we could possibly elect to only do this expansion if the p flag is active? Right now it means to expand \t into a literal tab, but it makes sense to have it more generally mean "expand stuff" in the string I think? eg, I think this would do it? + if (escapes && (*s =3D=3D String || *s =3D=3D Qstring) && s[1]) { --=20 Mikael Magnusson