mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-04 22:51:42 +02:00
33423: expand ${(p)...} to allow ${(ps.$param.)...}
This commit is contained in:
parent
521313b4b9
commit
3b5d77d819
3 changed files with 35 additions and 5 deletions
|
@ -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>
|
2014-10-11 Barton E. Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
* unposted: Test/B06fc.ztst: tests for 33429.
|
* unposted: Test/B06fc.ztst: tests for 33429.
|
||||||
|
|
|
@ -1124,6 +1124,19 @@ item(tt(p))(
|
||||||
Recognize the same escape sequences as the tt(print) builtin
|
Recognize the same escape sequences as the tt(print) builtin
|
||||||
in string arguments to any of the flags described below that
|
in string arguments to any of the flags described below that
|
||||||
follow this argument.
|
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(~))(
|
item(tt(~))(
|
||||||
Strings inserted into the expansion by any of the flags below are to
|
Strings inserted into the expansion by any of the flags below are to
|
||||||
|
|
13
Src/subst.c
13
Src/subst.c
|
@ -1385,13 +1385,24 @@ static char *
|
||||||
untok_and_escape(char *s, int escapes, int tok_arg)
|
untok_and_escape(char *s, int escapes, int tok_arg)
|
||||||
{
|
{
|
||||||
int klen;
|
int klen;
|
||||||
char *dst;
|
char *dst = NULL;
|
||||||
|
|
||||||
|
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));
|
untokenize(dst = dupstring(s));
|
||||||
if (escapes) {
|
if (escapes) {
|
||||||
dst = getkeystring(dst, &klen, GETKEYS_SEP, NULL);
|
dst = getkeystring(dst, &klen, GETKEYS_SEP, NULL);
|
||||||
dst = metafy(dst, klen, META_HREALLOC);
|
dst = metafy(dst, klen, META_HREALLOC);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (tok_arg)
|
if (tok_arg)
|
||||||
shtokenize(dst);
|
shtokenize(dst);
|
||||||
return dst;
|
return dst;
|
||||||
|
|
Loading…
Reference in a new issue