From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-users-return-23717-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 5a343230 for ; Wed, 24 Oct 2018 15:13:14 +0000 (UTC) Received: (qmail 5005 invoked by alias); 24 Oct 2018 15:12:56 -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: List-Unsubscribe: X-Seq: 23717 Received: (qmail 8652 invoked by uid 1010); 24 Oct 2018 15:12:56 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot1-f51.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.210.51):SA:0(-1.9/5.0):. Processed in 1.582972 secs); 24 Oct 2018 15:12:56 -0000 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=vyi7FknZGLh4mua+j0hBiRcDdFvo5z/HUTg933SxpeM=; b=M8n3wABU9U+GWe6rv5J2BYX92zM9BKqIIiZDXZdHkVrVjwnjhS0h6yX/8lnDw9eNL9 kgRlFdAUMdIgyMOkIA1WZ//uqoqrcWNZ7fJOKwcasUSl9AZK5Bgbmld7rPQhG5OOgy5B 7I/IPIEF7bjemmCyTv9P71Gvryh8fPGQ8Ydm/dtp7cjHP5aFBrFw46jQzRYzZWXX67dj QCwZ2LJNJsBtrstNr4tAh8oVwJp9vSQpI620G3VP13g/asv6X8ziehqXnBsuY+k31le8 lHEmphE2A7CHl42wo4s25O7gWc0QpJPhXHsWPafUnQ7DCOCo3r8CeWBLsVojZClGQpbX RUZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=vyi7FknZGLh4mua+j0hBiRcDdFvo5z/HUTg933SxpeM=; b=rHEvxIvwF26uzxMZ/4Cg1WXYsbPhX8r/nB64W6dV6UNun4/VQZlwb8ynyPBN7TYK8U /B+g6fFZsnLGSwdp8hEP9LvSODX5Wl2M2v30k5LoT2/GYlqmL/pXGPU5nO1eeDLsqbbp s2lz1M9jSpvHzMNNI0s+z02yXgljss1KQ8epN7/TrzPobkCT9JnR++TH5/aLeqKolWSv sN1Nqkew9u/ToR6fxOsP/NyXYP6oaOYqLl2vzz4zAQ25aoK3P2ugKTSRWDrLM6LOamiR GPIGVuzSByNffkM4NoikExxkbStephl5z1mOSeGv0lte7ByfXQj3hGhFEdyZ8PKiS5nA 6Rww== X-Gm-Message-State: AGRZ1gLAWK6l7MFwzV6t74OiydsRUAYMY82oBojrqSkpyb6I4ntfbQpM 4kYz+KAPDhnispnB+9c8MgwBSQk5Bvb5XIWIxtZFQ3sX X-Google-Smtp-Source: AJdET5cSY2sRZ2ooLC0FsWqKT4vw4SA8+jGWTLA6f0/kxjBXa3j5rYG/9iAP+rc+GnhTXeypq50qSdG/vdjKmkpYwng= X-Received: by 2002:a9d:3634:: with SMTP id w49mr1988279otb.11.1540393971728; Wed, 24 Oct 2018 08:12:51 -0700 (PDT) MIME-Version: 1.0 From: Sebastian Gniazdowski Date: Wed, 24 Oct 2018 17:12:38 +0200 Message-ID: Subject: =?UTF-8?Q?A_challenge_=E2=80=93_non=2Dextendedglob_whitespace_trimming?= To: Zsh Users Content-Type: text/plain; charset="UTF-8" Hello! I think this is a valid challenge: 1. One can do the following to strip whitespace from string $str: str=${${str##[[:space:]]##}%%[[:space:]]##} This uses ## operator and thus requires setopt extendedglob. 2. Extendedglob-free code that does the same: str="${str#"${str%%[! $'\t']*}"}" # leading whitespace str="${str%"${str##*[! $'\t']}"}" # trailing whitespace It's tricky, but the main thing one has to notice to grasp this: The inner ${str%%...} substitution will match from end to beginning of string till last non-whitespace. So it will left only leading whitespace. Which is then removed from start of the string with #-subst. 3. I have an array `pairs', holding elements like this: pairs=( "a -> b" " c ->d " ), etc. I want to obtain array with additional split on "->" (so it is nicely fitting into a hash, key-a val-b, etc.). Following is an extendedglob-dependant code that performs the split and also trims leading and trailing whitespace from all elements: pairs=( "${(@)${(@)${(@s:->:)pairs}##[[:space:]]##}%%[[:space:]]##}" ) 4. Is there a extendedglob-free (not depending on it) version of the above point 3.? -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org