nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 66d9d6c6d236ef1ed9bfc7545b227c8fbd80671b
parent de816840cb39c915b20ecf5225acded37f95ba9d
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 25 Mar 2021 10:52:42 +0100

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.

Diffstat:
Msrc/chars.c | 11+----------
Msrc/prototypes.h | 3---
Msrc/winio.c | 2+-
3 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/src/chars.c b/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 diff --git a/src/prototypes.h b/src/prototypes.h @@ -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 diff --git a/src/winio.c b/src/winio.c @@ -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';