mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-07-25 09:21:05 +02:00
49992: further unify single- and multi-byte implementations of nicechar()
This commit is contained in:
parent
b80d160039
commit
0d9c2422bf
2 changed files with 3 additions and 62 deletions
|
@ -1,5 +1,8 @@
|
|||
2022-04-04 Bart Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 49992: Src/utils.c: further unify single- and multi-byte
|
||||
implementations of nicechar() to fix ${(V)...} output format
|
||||
|
||||
* 49991: Src/glob.c, Src/utils.c: single-byte brace expansion
|
||||
handles $'\0' and control character output aligns with multibyte
|
||||
|
||||
|
|
62
Src/utils.c
62
Src/utils.c
|
@ -438,7 +438,6 @@ putshout(int c)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MULTIBYTE_SUPPORT
|
||||
/*
|
||||
* Turn a character into a visible representation thereof. The visible
|
||||
* string is put together in a static buffer, and this function returns
|
||||
|
@ -524,67 +523,6 @@ nicechar(int c)
|
|||
return nicechar_sel(c, 0);
|
||||
}
|
||||
|
||||
#else /* MULTIBYTE_SUPPORT */
|
||||
|
||||
/**/
|
||||
mod_export char *
|
||||
nicechar(int c)
|
||||
{
|
||||
static char buf[10];
|
||||
char *s = buf;
|
||||
c &= 0xff;
|
||||
if (ZISPRINT(c))
|
||||
goto done;
|
||||
if (c & 0x80) {
|
||||
if (isset(PRINTEIGHTBIT))
|
||||
goto done;
|
||||
*s++ = '\\';
|
||||
*s++ = 'M';
|
||||
*s++ = '-';
|
||||
c &= 0x7f;
|
||||
if(ZISPRINT(c))
|
||||
goto done;
|
||||
}
|
||||
if (c == 0x7f) {
|
||||
*s++ = '\\';
|
||||
*s++ = 'C';
|
||||
*s++ = '-';
|
||||
c = '?';
|
||||
} else if (c == '\n') {
|
||||
*s++ = '\\';
|
||||
c = 'n';
|
||||
} else if (c == '\t') {
|
||||
*s++ = '\\';
|
||||
c = 't';
|
||||
} else if (c < 0x20) {
|
||||
/*
|
||||
if (quotable) {
|
||||
*s++ = '\\';
|
||||
*s++ = 'C';
|
||||
*s++ = '-';
|
||||
} else
|
||||
*/
|
||||
*s++ = '^';
|
||||
c += 0x40;
|
||||
}
|
||||
done:
|
||||
/*
|
||||
* The resulting string is still metafied, so check if
|
||||
* we are returning a character in the range that needs metafication.
|
||||
* This can't happen if the character is printed "nicely", so
|
||||
* this results in a maximum of two bytes total (plus the null).
|
||||
*/
|
||||
if (imeta(c)) {
|
||||
*s++ = Meta;
|
||||
*s++ = c ^ 32;
|
||||
} else
|
||||
*s++ = c;
|
||||
*s = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* MULTIBYTE_SUPPORT */
|
||||
|
||||
/*
|
||||
* Return 1 if nicechar() would reformat this character.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue