1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 22:11:54 +02:00

33423: expand ${(p)...} to allow ${(ps.$param.)...}

This commit is contained in:
Peter Stephenson 2014-10-12 17:52:11 +01:00
parent 521313b4b9
commit 3b5d77d819
3 changed files with 35 additions and 5 deletions

View file

@ -1,3 +1,9 @@
2014-10-12 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 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 <schaefer@zsh.org>
* unposted: Test/B06fc.ztst: tests for 33429.

View file

@ -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

View file

@ -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);