Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
- X-seq: zsh-workers 52156
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Help: f (repeat) modifier, and histsubstpattern + :s/l/r/ modifier escaping of [{()}]
- Date: Sat, 16 Sep 2023 20:47:45 -0700
- Archived-at: <https://zsh.org/workers/52156>
- In-reply-to: <CAH+w=7Yv_tyBKLo1PuoeDB-YkWwpGh5d_hZODyTH7J0mgD3RNg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAO4D9E=+O-=66w0um7OzENVEiV11QfVUWYSTocacUX4rhYr1=Q@mail.gmail.com> <CAH+w=7Y+zos=sRfAv2769iJEzazHRfT4u6v+3B3mGoxy8Yv0-w@mail.gmail.com> <CAH+w=7Yv_tyBKLo1PuoeDB-YkWwpGh5d_hZODyTH7J0mgD3RNg@mail.gmail.com>
On Thu, Aug 17, 2023 at 4:09 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Proof of bug / concept of fix. This might eat a lot of heap so
> something more detailed is probably needed
There doesn't seem to be any better approach without actually invoking
pushheap/popheap which is likely overkill for most cases of this, so
I'm just going to commit users/29160.
Here's a test suite patch to go with it.
> diff --git a/Src/subst.c b/Src/subst.c
> index 14947ae36..7b866e638 100644
> --- a/Src/subst.c
> +++ b/Src/subst.c
> @@ -4539,7 +4539,8 @@ modify(char **str, char **ptr, int inbrace)
> case 'S':
> hsubpatopt = (c == 'S');
> if (hsubl && hsubr)
> - subst(©, hsubl, hsubr, gbal, hsubpatopt);
> + subst(©, dupstring(hsubl), dupstring(hsubr),
> + gbal, hsubpatopt);
> break;
> case 'q':
> copy = quotestring(copy, QT_BACKSLASH_SHOWNULL);
> @@ -4627,7 +4628,8 @@ modify(char **str, char **ptr, int inbrace)
> case 'S':
> hsubpatopt = (c == 'S');
> if (hsubl && hsubr)
> - subst(str, hsubl, hsubr, gbal, hsubpatopt);
> + subst(str, dupstring(hsubl), dupstring(hsubr),
> + gbal, hsubpatopt);
> break;
> case 'q':
> *str = quotestring(*str, QT_BACKSLASH);
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 83f0371a1..363846f5c 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -561,12 +561,14 @@
foo=(one.c two.c three.c)
print ${foo:s/#%(#b)t(*).c/T${match[1]}.X/}
print *(#q:s/#(#b)tmp(*e)/'scrunchy${match[1]}'/)
+ print ${${:-"left[({})]over"}:fs/(\\{\\}|\\(\\)|\\[\\])//}
unsetopt histsubstpattern
0:HIST_SUBST_PATTERN option
>TINGcd TINGfile1 TINGfile2 homedir
>THUMPcd THUMPfile1 THUMPfile2
>one.c Two.X Three.X
>homedir scrunchyfile1 scrunchyfile2 tmpcd
+>leftover
setopt ignorebraces
echo X{a,b}Y
Messages sorted by:
Reverse Date,
Date,
Thread,
Author