From 3b5d77d819e1b7a94c4b14d69bddb2dddf8605ff Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Sun, 12 Oct 2014 17:52:11 +0100
Subject: 33423: expand ${(p)...} to allow ${(ps.$param.)...}
---
ChangeLog | 6 ++++++
Doc/Zsh/expn.yo | 13 +++++++++++++
Src/subst.c | 21 ++++++++++++++++-----
3 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b2287d27c..e1de05210 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-12 Peter Stephenson
+
+ * 33423: Doc/Zsh/expn.yo, Src/subst.c: parameter expansion
+ (p) flag allows delimited strings to contain simple $param
+ expansions.
+
2014-10-11 Barton E. Schaefer
* unposted: Test/B06fc.ztst: tests for 33429.
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 5aab25954..a0478e78c 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1124,6 +1124,19 @@ item(tt(p))(
Recognize the same escape sequences as the tt(print) builtin
in string arguments to any of the flags described below that
follow this argument.
+
+Alternatively, with this option string arguments may be in the form
+tt($)var(var) in which case the value of the variable is substituted.
+Note this form is strict; the string argument does not undergo general
+parameter expansion.
+
+For example,
+
+example(sep=:
+val=a:b:c
+print ${+LPAR()ps.$sep.+RPAR()val})
+
+splits the variable on a tt(:).
)
item(tt(~))(
Strings inserted into the expansion by any of the flags below are to
diff --git a/Src/subst.c b/Src/subst.c
index 1aa9b982e..61aa1c136 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1385,12 +1385,23 @@ static char *
untok_and_escape(char *s, int escapes, int tok_arg)
{
int klen;
- char *dst;
+ char *dst = NULL;
- untokenize(dst = dupstring(s));
- if (escapes) {
- dst = getkeystring(dst, &klen, GETKEYS_SEP, NULL);
- dst = metafy(dst, klen, META_HREALLOC);
+ if (escapes && (*s == String || *s == Qstring) && s[1]) {
+ char *pstart = s+1, *pend;
+ for (pend = pstart; *pend; pend++)
+ if (!iident(*pend))
+ break;
+ if (!*pend) {
+ dst = dupstring(getsparam(pstart));
+ }
+ }
+ if (dst == NULL) {
+ untokenize(dst = dupstring(s));
+ if (escapes) {
+ dst = getkeystring(dst, &klen, GETKEYS_SEP, NULL);
+ dst = metafy(dst, klen, META_HREALLOC);
+ }
}
if (tok_arg)
shtokenize(dst);
--
cgit 1.4.1