chars: the representation of a control character is always two bytes
Any control character is represented by a ^ plus an ASCII character.
Этот коммит содержится в:
родитель
03586c60da
Коммит
622995fb12
19
src/chars.c
19
src/chars.c
@ -253,27 +253,20 @@ wchar_t control_wrep(wchar_t wc)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* c is a multibyte control character. It displays as ^@, ^?, or ^[ch],
|
/* Return the visible representation of multibyte control character c. */
|
||||||
* where ch is (c + 64). We return that single-byte character. */
|
char control_mbrep(const char *c)
|
||||||
char *control_mbrep(const char *c, char *crep, int *crep_len)
|
|
||||||
{
|
{
|
||||||
assert(c != NULL && crep != NULL && crep_len != NULL);
|
assert(c != NULL);
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
if (0 <= c[0] && c[0] <= 127)
|
if (0 <= c[0] && c[0] <= 127)
|
||||||
*crep = control_rep(c[0]);
|
return control_rep(c[0]);
|
||||||
else
|
else
|
||||||
*crep = control_rep(c[1]);
|
return control_rep(c[1]);
|
||||||
*crep_len = 1;
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
return control_rep(*c);
|
||||||
*crep_len = 1;
|
|
||||||
*crep = control_rep(*c);
|
|
||||||
}
|
|
||||||
|
|
||||||
return crep;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* c is a multibyte non-control character. We return that multibyte
|
/* c is a multibyte non-control character. We return that multibyte
|
||||||
|
@ -193,7 +193,7 @@ char control_rep(const signed char c);
|
|||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
wchar_t control_wrep(wchar_t wc);
|
wchar_t control_wrep(wchar_t wc);
|
||||||
#endif
|
#endif
|
||||||
char *control_mbrep(const char *c, char *crep, int *crep_len);
|
char control_mbrep(const char *c);
|
||||||
char *mbrep(const char *c, char *crep, int *crep_len);
|
char *mbrep(const char *c, char *crep, int *crep_len);
|
||||||
int mbwidth(const char *c);
|
int mbwidth(const char *c);
|
||||||
int mb_cur_max(void);
|
int mb_cur_max(void);
|
||||||
|
31
src/winio.c
31
src/winio.c
@ -1786,18 +1786,8 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
|
|||||||
|
|
||||||
if (is_cntrl_mbchar(buf_mb)) {
|
if (is_cntrl_mbchar(buf_mb)) {
|
||||||
if (column < start_col) {
|
if (column < start_col) {
|
||||||
char *character = charalloc(mb_cur_max());
|
converted[index++] = control_mbrep(buf_mb);
|
||||||
int charlen, i;
|
start_col++;
|
||||||
|
|
||||||
character = control_mbrep(buf_mb, character, &charlen);
|
|
||||||
|
|
||||||
for (i = 0; i < charlen; i++)
|
|
||||||
converted[index++] = character[i];
|
|
||||||
|
|
||||||
start_col += mbwidth(character);
|
|
||||||
|
|
||||||
free(character);
|
|
||||||
|
|
||||||
start_index += buf_mb_len;
|
start_index += buf_mb_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1859,22 +1849,11 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
|
|||||||
converted[index++] = ' ';
|
converted[index++] = ' ';
|
||||||
start_col++;
|
start_col++;
|
||||||
}
|
}
|
||||||
/* If buf contains a control character, interpret it. */
|
/* If buf contains a control character, represent it. */
|
||||||
} else if (is_cntrl_mbchar(buf_mb)) {
|
} else if (is_cntrl_mbchar(buf_mb)) {
|
||||||
char *character = charalloc(mb_cur_max());
|
|
||||||
int charlen, i;
|
|
||||||
|
|
||||||
converted[index++] = '^';
|
converted[index++] = '^';
|
||||||
start_col++;
|
converted[index++] = control_mbrep(buf_mb);
|
||||||
|
start_col += 2;
|
||||||
character = control_mbrep(buf_mb, character, &charlen);
|
|
||||||
|
|
||||||
for (i = 0; i < charlen; i++)
|
|
||||||
converted[index++] = character[i];
|
|
||||||
|
|
||||||
start_col += mbwidth(character);
|
|
||||||
|
|
||||||
free(character);
|
|
||||||
/* If buf contains a non-control character, interpret it. If buf
|
/* If buf contains a non-control character, interpret it. If buf
|
||||||
* contains an invalid multibyte sequence, display it as such. */
|
* contains an invalid multibyte sequence, display it as such. */
|
||||||
} else {
|
} else {
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user