mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-05-17 13:36:04 +02:00
40640: the (A) parameter flag forces array result even if assignment syntax is not used
This commit is contained in:
parent
5a32ced1be
commit
4b8db48c6b
|
@ -1,3 +1,9 @@
|
|||
2017-02-25 Barton E. Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 40640 (plus doc typo fixed): Doc/Zsh/expn.yo, Src/subst.c: the
|
||||
(A) parameter flag forces array result even if assignment syntax
|
||||
is not used
|
||||
|
||||
2017-02-25 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||
|
||||
* unposted: Completion/Zsh/Context/_brace_parameter: Port 40617
|
||||
|
|
|
@ -955,15 +955,25 @@ This is distinct from em(field splitting) by the tt(f), tt(s)
|
|||
or tt(z) flags, which still applies within each array element.
|
||||
)
|
||||
item(tt(A))(
|
||||
Assign as an array parameter with `tt(${)...tt(=)...tt(})',
|
||||
Convert the substitution into an array expression, even if it otherwise
|
||||
would be scalar. This has lower precedence than subscripting, so one
|
||||
level of nested expansion is required in order that subscripts apply
|
||||
to array elements. Thus tt(${${LPAR()A)tt(RPAR())var(name)tt(}[1]})
|
||||
yields the full value of var(name) when var(name) is scalar.
|
||||
|
||||
This assigns an array parameter with `tt(${)...tt(=)...tt(})',
|
||||
`tt(${)...tt(:=)...tt(})' or `tt(${)...tt(::=)...tt(})'.
|
||||
If this flag is repeated (as in `tt(AA)'), assign an associative
|
||||
If this flag is repeated (as in `tt(AA)'), assigns an associative
|
||||
array parameter. Assignment is made before sorting or padding;
|
||||
if field splitting is active, the var(word) part is split before
|
||||
assignment. The var(name) part may be a subscripted range for
|
||||
ordinary arrays; when assigning an associative array, the var(word)
|
||||
part em(must) be converted to an array, for example by using
|
||||
`tt(${(AA)=)var(name)tt(=)...tt(})' to activate field splitting.
|
||||
|
||||
Surrounding context such as additional nesting or use of the value
|
||||
in a scalar assignment may cause the array to be joined back into
|
||||
a single string again.
|
||||
)
|
||||
item(tt(a))(
|
||||
Sort in array index order; when combined with `tt(O)' sort in reverse
|
||||
|
|
11
Src/subst.c
11
Src/subst.c
|
@ -2902,6 +2902,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
|
|||
} else
|
||||
setaparam(idbeg, a);
|
||||
isarr = 1;
|
||||
arrasg = 0;
|
||||
} else {
|
||||
untokenize(val);
|
||||
setsparam(idbeg, ztrdup(val));
|
||||
|
@ -3784,6 +3785,16 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
|
|||
insertlinknode(l, n, dupstring(fstr)); /* appended, no incnode */
|
||||
*fstr = '\0';
|
||||
}
|
||||
if (arrasg && !isarr) {
|
||||
/*
|
||||
* Caller requested this be forced to an array even if scalar.
|
||||
* Any point in distinguishing arrasg == 2 (assoc array) here?
|
||||
*/
|
||||
l->list.flags |= LF_ARRAY;
|
||||
aval = hmkarray(val);
|
||||
isarr = 1;
|
||||
DPUTS(!val, "value is NULL in paramsubst, empty array");
|
||||
}
|
||||
if (isarr) {
|
||||
char *x;
|
||||
char *y;
|
||||
|
|
Loading…
Reference in New Issue