tweaks: elide a function from a non-UTF8 build
In a non-UTF8 build, mbwidth() returns always 1, so it is pointless to call that function and compare its result to zero then. Also, don't bother special-casing the function for a non-UTF8 locale.
Этот коммит содержится в:
родитель
3158133edd
Коммит
b02dccc51f
@ -200,11 +200,10 @@ char control_mbrep(const char *c, bool isdata)
|
|||||||
return control_rep(*c);
|
return control_rep(*c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_UTF8
|
||||||
/* This function is equivalent to wcwidth() for multibyte characters. */
|
/* This function is equivalent to wcwidth() for multibyte characters. */
|
||||||
int mbwidth(const char *c)
|
int mbwidth(const char *c)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_UTF8
|
|
||||||
if (use_utf8) {
|
|
||||||
wchar_t wc;
|
wchar_t wc;
|
||||||
int width;
|
int width;
|
||||||
|
|
||||||
@ -213,14 +212,12 @@ int mbwidth(const char *c)
|
|||||||
|
|
||||||
width = wcwidth(wc);
|
width = wcwidth(wc);
|
||||||
|
|
||||||
if (width == -1)
|
if (width < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Convert the Unicode value in code to a multibyte character, if possible.
|
/* Convert the Unicode value in code to a multibyte character, if possible.
|
||||||
* If the conversion succeeds, return the (dynamically allocated) multibyte
|
* If the conversion succeeds, return the (dynamically allocated) multibyte
|
||||||
|
@ -213,7 +213,9 @@ bool is_ascii_cntrl_char(int c);
|
|||||||
bool is_cntrl_mbchar(const char *c);
|
bool is_cntrl_mbchar(const char *c);
|
||||||
bool is_word_mbchar(const char *c, bool allow_punct);
|
bool is_word_mbchar(const char *c, bool allow_punct);
|
||||||
char control_mbrep(const char *c, bool isdata);
|
char control_mbrep(const char *c, bool isdata);
|
||||||
|
#ifdef ENABLE_UTF8
|
||||||
int mbwidth(const char *c);
|
int mbwidth(const char *c);
|
||||||
|
#endif
|
||||||
char *make_mbchar(long chr, int *chr_mb_len);
|
char *make_mbchar(long chr, int *chr_mb_len);
|
||||||
int char_length(const char *pointer);
|
int char_length(const char *pointer);
|
||||||
int parse_mbchar(const char *buf, char *chr, size_t *col);
|
int parse_mbchar(const char *buf, char *chr, size_t *col);
|
||||||
|
@ -1890,11 +1890,13 @@ char *display_string(const char *buf, size_t column, size_t span,
|
|||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
#define ISO8859_CHAR FALSE
|
#define ISO8859_CHAR FALSE
|
||||||
|
#define ZEROWIDTH_CHAR (mbwidth(buf) == 0)
|
||||||
#else
|
#else
|
||||||
#define ISO8859_CHAR ((unsigned char)*buf > 0x9F)
|
#define ISO8859_CHAR ((unsigned char)*buf > 0x9F)
|
||||||
|
#define ZEROWIDTH_CHAR FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (*buf != '\0' && (column < beyond || mbwidth(buf) == 0)) {
|
while (*buf != '\0' && (column < beyond || ZEROWIDTH_CHAR)) {
|
||||||
/* A plain printable ASCII character is one byte, one column. */
|
/* A plain printable ASCII character is one byte, one column. */
|
||||||
if (((signed char)*buf > 0x20 && *buf != DEL_CODE) || ISO8859_CHAR) {
|
if (((signed char)*buf > 0x20 && *buf != DEL_CODE) || ISO8859_CHAR) {
|
||||||
converted[index++] = *(buf++);
|
converted[index++] = *(buf++);
|
||||||
@ -1983,14 +1985,16 @@ char *display_string(const char *buf, size_t column, size_t span,
|
|||||||
/* If there is more text than can be shown, make room for the ">". */
|
/* If there is more text than can be shown, make room for the ">". */
|
||||||
if (column > beyond || (*buf != '\0' && (isprompt ||
|
if (column > beyond || (*buf != '\0' && (isprompt ||
|
||||||
(isdata && !ISSET(SOFTWRAP))))) {
|
(isdata && !ISSET(SOFTWRAP))))) {
|
||||||
|
#ifdef ENABLE_UTF8
|
||||||
do {
|
do {
|
||||||
index = step_left(converted, index);
|
index = step_left(converted, index);
|
||||||
} while (mbwidth(converted + index) == 0);
|
} while (mbwidth(converted + index) == 0);
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
|
||||||
/* Display the left half of a two-column character as '['. */
|
/* Display the left half of a two-column character as '['. */
|
||||||
if (mbwidth(converted + index) == 2)
|
if (mbwidth(converted + index) == 2)
|
||||||
converted[index++] = '[';
|
converted[index++] = '[';
|
||||||
|
#else
|
||||||
|
index--;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user