tweaks: elide the pointless is_valid_unicode() function
The call of this function in make_mbchar() does not add anything, because wctomb() already returns -1 for codes U+D800 to U+DFFF, and parse_verbatim_kbinput() already rejects anything that starts with U+11.... or higher, so make_mbchar() is never called for codes beyond U+10FFFF. And the call in display_string() just needs to check for wc <= 0x10FFFF because mbtowc() already returns -1 for codes U+D800 to U+DFFF.master
parent
de816840cb
commit
66d9d6c6d2
11
src/chars.c
11
src/chars.c
|
@ -212,8 +212,7 @@ char *make_mbchar(long code, int *length)
|
|||
|
||||
*length = wctomb(mb_char, (wchar_t)code);
|
||||
|
||||
/* Reject invalid Unicode characters. */
|
||||
if (*length < 0 || !is_valid_unicode((wchar_t)code)) {
|
||||
if (*length < 0) {
|
||||
IGNORE_CALL_RESULT(wctomb(NULL, 0));
|
||||
*length = 0;
|
||||
}
|
||||
|
@ -615,11 +614,3 @@ bool white_string(const char *string)
|
|||
|
||||
return !*string;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* Return TRUE if wc is valid Unicode, and FALSE otherwise. */
|
||||
bool is_valid_unicode(wchar_t wc)
|
||||
{
|
||||
return ((0 <= wc && wc <= 0xD7FF) || (0xE000 <= wc && wc <= 0x10FFFF));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -230,9 +230,6 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer);
|
|||
bool has_blank_char(const char *string);
|
||||
#endif
|
||||
bool white_string(const char *string);
|
||||
#ifdef ENABLE_UTF8
|
||||
bool is_valid_unicode(wchar_t wc);
|
||||
#endif
|
||||
|
||||
/* Most functions in color.c. */
|
||||
#ifdef ENABLE_COLOR
|
||||
|
|
|
@ -1823,7 +1823,7 @@ char *display_string(const char *buf, size_t column, size_t span,
|
|||
charlength = mbtowc(&wc, buf, MAXCHARLEN);
|
||||
|
||||
/* Represent an invalid character with the Replacement Character. */
|
||||
if (charlength < 0 || !is_valid_unicode(wc)) {
|
||||
if (charlength < 0 || wc > 0x10FFFF) {
|
||||
converted[index++] = '\xEF';
|
||||
converted[index++] = '\xBF';
|
||||
converted[index++] = '\xBD';
|
||||
|
|
Loading…
Reference in New Issue