1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-29 06:51:03 +02:00

29261: Add g:: flag.

This commit is contained in:
Mikael Magnusson 2011-05-19 16:16:28 +00:00
parent 72cb7cfc6f
commit 6a29bc80d0
4 changed files with 96 additions and 4 deletions

View file

@ -1,3 +1,8 @@
2011-05-19 Mikael Magnusson <mikachu@gmail.com>
* 29261: Add g:: parameter expansion flag. Add note that s::
can take an empty string.
2011-05-19 Mikael Magnusson <mikachu@gmail.com> 2011-05-19 Mikael Magnusson <mikachu@gmail.com>
* 29307, 29308 + replies: Fix some doubled words in docs and * 29307, 29308 + replies: Fix some doubled words in docs and
@ -14752,5 +14757,5 @@
***************************************************** *****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL * This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.5312 $ * $Revision: 1.5313 $
***************************************************** *****************************************************

View file

@ -859,6 +859,14 @@ item(tt(F))(
Join the words of arrays together using newline as a separator. Join the words of arrays together using newline as a separator.
This is a shorthand for `tt(pj:\n:)'. This is a shorthand for `tt(pj:\n:)'.
) )
item(tt(g:opts:))(
Process escape sequences like the echo builtin when no options are given
(tt(g::)). With the tt(o) option, octal escapes don't take a leading
zero. With the tt(c) option, sequences like `tt(^X)' are also processed.
With the tt(e) option, processes `tt(\M-t)' and similar sequences like the
print builtin. With both of the tt(o) and tt(e) options, behaves like the
print builtin except that in none of these modes is `tt(\c)' interpreted.
)
item(tt(i))( item(tt(i))(
Sort case-insensitively. May be combined with `tt(n)' or `tt(O)'. Sort case-insensitively. May be combined with `tt(n)' or `tt(O)'.
) )
@ -1104,7 +1112,9 @@ Force field splitting at the
separator var(string). Note that a var(string) of two or more separator var(string). Note that a var(string) of two or more
characters means that all of them must match in sequence; this differs from characters means that all of them must match in sequence; this differs from
the treatment of two or more characters in the tt(IFS) parameter. the treatment of two or more characters in the tt(IFS) parameter.
See also the tt(=) flag and the tt(SH_WORD_SPLIT) option. See also the tt(=) flag and the tt(SH_WORD_SPLIT) option. An empty
string may also be given in which case every character will be a separate
element.
For historical reasons, the usual behaviour that empty array elements For historical reasons, the usual behaviour that empty array elements
are retained inside double quotes is disabled for arrays generated are retained inside double quotes is disabled for arrays generated
@ -1288,8 +1298,9 @@ item(tt(11.) em(Case modification))(
Any case modification from one of the flags tt((L)), tt((U)) or tt((C)) Any case modification from one of the flags tt((L)), tt((U)) or tt((C))
is applied. is applied.
) )
item(tt(12.) em(Prompt evaluation))( item(tt(12.) em(Escape sequence replacement))(
Any prompt-style formatting from the tt((%)) family of flags is applied. First any replacements from the tt((g)) flag are performed, then any
prompt-style formatting from the tt((%)) family of flags is applied.
) )
item(tt(13.) em(Quote application))( item(tt(13.) em(Quote application))(
Any quoting or unquoting using tt((q)) and tt((Q)) and related flags Any quoting or unquoting using tt((q)) and tt((Q)) and related flags

View file

@ -1606,6 +1606,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
* The (%) flag, c.f. mods again. * The (%) flag, c.f. mods again.
*/ */
int presc = 0; int presc = 0;
/*
* The (g) flag. Process escape sequences with various GETKEY_ flags.
*/
int getkeys = -1;
/* /*
* The (@) flag; interacts obscurely with qt and isarr. * The (@) flag; interacts obscurely with qt and isarr.
* This is one of the things that decides whether multsub * This is one of the things that decides whether multsub
@ -1932,6 +1936,36 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
presc++; presc++;
break; break;
case 'g':
t = get_strarg(++s, &arglen);
if (getkeys < 0)
getkeys = 0;
if (*t) {
sav = *t;
*t = 0;
while (*++s) {
switch (*s) {
case 'e':
getkeys |= GETKEY_EMACS;
break;
case 'o':
getkeys |= GETKEY_OCTAL_ESC;
break;
case 'c':
getkeys |= GETKEY_CTRL;
break;
default:
*t = sav;
goto flagerr;
}
}
*t = sav;
s = t + arglen - 1;
} else
goto flagerr;
break;
case 'z': case 'z':
shsplit = LEXFLAGS_ACTIVE; shsplit = LEXFLAGS_ACTIVE;
break; break;
@ -3082,6 +3116,28 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
val = casemodify(val, casmod); val = casemodify(val, casmod);
} }
} }
/*
* Process echo- and print-style escape sequences.
*/
if (getkeys >= 0) {
int len;
copied = 1; /* string is always copied */
if (isarr) {
char **ap, **ap2;
ap = aval;
aval = (char **) zhalloc(sizeof(char *) * (arrlen(aval)+1));
for (ap2 = aval; *ap; ap++, ap2++) {
*ap2 = getkeystring(*ap, &len, getkeys, NULL);
*ap2 = metafy(*ap2, len, META_USEHEAP);
}
*ap2++ = NULL;
} else {
val = getkeystring(val, &len, getkeys, NULL);
val = metafy(val, len, META_USEHEAP);
}
}
/* /*
* Perform prompt-style modifications. * Perform prompt-style modifications.
*/ */

View file

@ -298,6 +298,26 @@
>Howzat >Howzat
>usay >usay
foo='\u65\123'
print -r ${(g:o:)foo}
foo='\u65\0123'
print -r ${(g::)foo}
foo='\u65^X'
print -r ${(V)${(g:c:)foo}}
foo='\u65\C-x\M-a'
print -r ${(V)${(g:e:)foo}}
foo='\u65\123\C-x'
print -r ${(V)${(g:eo:)foo}}
foo=('\u65' '\0123' '^X\M-a')
print -r ${(V)${(g:e:)foo}}
0:${(g)...}
>eS
>eS
>e^X
>e^X\M-a
>eS^X
>e S ^X\M-a
foo='I'\''m nearly out of my mind with tedium' foo='I'\''m nearly out of my mind with tedium'
bar=foo bar=foo
print ${(P)bar} print ${(P)bar}