mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-22 12:51:23 +03:00
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.
This commit is contained in:
parent
3158133edd
commit
b02dccc51f
@ -200,11 +200,10 @@ char control_mbrep(const char *c, bool isdata)
|
||||
return control_rep(*c);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* This function is equivalent to wcwidth() for multibyte characters. */
|
||||
int mbwidth(const char *c)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8) {
|
||||
wchar_t wc;
|
||||
int width;
|
||||
|
||||
@ -213,14 +212,12 @@ int mbwidth(const char *c)
|
||||
|
||||
width = wcwidth(wc);
|
||||
|
||||
if (width == -1)
|
||||
if (width < 0)
|
||||
return 1;
|
||||
|
||||
return width;
|
||||
} else
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Convert the Unicode value in code to a multibyte character, if possible.
|
||||
* 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_word_mbchar(const char *c, bool allow_punct);
|
||||
char control_mbrep(const char *c, bool isdata);
|
||||
#ifdef ENABLE_UTF8
|
||||
int mbwidth(const char *c);
|
||||
#endif
|
||||
char *make_mbchar(long chr, int *chr_mb_len);
|
||||
int char_length(const char *pointer);
|
||||
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
|
||||
#define ISO8859_CHAR FALSE
|
||||
#define ZEROWIDTH_CHAR (mbwidth(buf) == 0)
|
||||
#else
|
||||
#define ISO8859_CHAR ((unsigned char)*buf > 0x9F)
|
||||
#define ZEROWIDTH_CHAR FALSE
|
||||
#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. */
|
||||
if (((signed char)*buf > 0x20 && *buf != DEL_CODE) || ISO8859_CHAR) {
|
||||
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 (column > beyond || (*buf != '\0' && (isprompt ||
|
||||
(isdata && !ISSET(SOFTWRAP))))) {
|
||||
#ifdef ENABLE_UTF8
|
||||
do {
|
||||
index = step_left(converted, index);
|
||||
} while (mbwidth(converted + index) == 0);
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* Display the left half of a two-column character as '['. */
|
||||
if (mbwidth(converted + index) == 2)
|
||||
converted[index++] = '[';
|
||||
#else
|
||||
index--;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user