chars: the representation of a control character is always two bytes

Any control character is represented by a ^ plus an ASCII character.
master
Benno Schulenberg 2016-06-29 20:37:28 +02:00
parent 03586c60da
commit 622995fb12
3 changed files with 12 additions and 40 deletions

View File

@ -253,27 +253,20 @@ wchar_t control_wrep(wchar_t wc)
}
#endif
/* c is a multibyte control character. It displays as ^@, ^?, or ^[ch],
* where ch is (c + 64). We return that single-byte character. */
char *control_mbrep(const char *c, char *crep, int *crep_len)
/* Return the visible representation of multibyte control character c. */
char control_mbrep(const char *c)
{
assert(c != NULL && crep != NULL && crep_len != NULL);
assert(c != NULL);
#ifdef ENABLE_UTF8
if (use_utf8) {
if (0 <= c[0] && c[0] <= 127)
*crep = control_rep(c[0]);
return control_rep(c[0]);
else
*crep = control_rep(c[1]);
*crep_len = 1;
return control_rep(c[1]);
} else
#endif
{
*crep_len = 1;
*crep = control_rep(*c);
}
return crep;
return control_rep(*c);
}
/* c is a multibyte non-control character. We return that multibyte

View File

@ -193,7 +193,7 @@ char control_rep(const signed char c);
#ifdef ENABLE_UTF8
wchar_t control_wrep(wchar_t wc);
#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);
int mbwidth(const char *c);
int mb_cur_max(void);

View File

@ -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 (column < start_col) {
char *character = charalloc(mb_cur_max());
int charlen, i;
character = control_mbrep(buf_mb, character, &charlen);
for (i = 0; i < charlen; i++)
converted[index++] = character[i];
start_col += mbwidth(character);
free(character);
converted[index++] = control_mbrep(buf_mb);
start_col++;
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++] = ' ';
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)) {
char *character = charalloc(mb_cur_max());
int charlen, i;
converted[index++] = '^';
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);
converted[index++] = control_mbrep(buf_mb);
start_col += 2;
/* If buf contains a non-control character, interpret it. If buf
* contains an invalid multibyte sequence, display it as such. */
} else {