mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 13:38:34 +00:00
@@ -456,43 +456,50 @@ static bool intable(const struct interval *table, size_t n_items, int c)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* For UTF-8 character "c" return 2 for a double-width character, 1 for others.
|
||||
* Returns 4 or 6 for an unprintable character.
|
||||
* Is only correct for characters >= 0x80.
|
||||
* When p_ambw is "double", return 2 for a character with East Asian Width
|
||||
* class 'A'(mbiguous).
|
||||
*/
|
||||
/// For UTF-8 character "c" return 2 for a double-width character, 1 for others.
|
||||
/// Returns 4 or 6 for an unprintable character.
|
||||
/// Is only correct for characters >= 0x80.
|
||||
/// When p_ambw is "double", return 2 for a character with East Asian Width
|
||||
/// class 'A'(mbiguous).
|
||||
///
|
||||
/// @note Tables `doublewidth` and `ambiguous` are generated by
|
||||
/// gen_unicode_tables.lua, which must be manually invoked as needed.
|
||||
int utf_char2cells(int c)
|
||||
{
|
||||
if (c >= 0x100) {
|
||||
#ifdef USE_WCHAR_FUNCTIONS
|
||||
/*
|
||||
* Assume the library function wcwidth() works better than our own
|
||||
* stuff. It should return 1 for ambiguous width chars!
|
||||
*/
|
||||
//
|
||||
// Assume the library function wcwidth() works better than our own
|
||||
// stuff. It should return 1 for ambiguous width chars!
|
||||
//
|
||||
int n = wcwidth(c);
|
||||
|
||||
if (n < 0)
|
||||
return 6; /* unprintable, displays <xxxx> */
|
||||
if (n > 1)
|
||||
if (n < 0) {
|
||||
return 6; // unprintable, displays <xxxx>
|
||||
}
|
||||
if (n > 1) {
|
||||
return n;
|
||||
}
|
||||
#else
|
||||
if (!utf_printable(c))
|
||||
return 6; /* unprintable, displays <xxxx> */
|
||||
if (intable(doublewidth, ARRAY_SIZE(doublewidth), c))
|
||||
if (!utf_printable(c)) {
|
||||
return 6; // unprintable, displays <xxxx>
|
||||
}
|
||||
if (intable(doublewidth, ARRAY_SIZE(doublewidth), c)) {
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
if (p_emoji && intable(emoji_width, ARRAY_SIZE(emoji_width), c)) {
|
||||
return 2;
|
||||
}
|
||||
} else if (c >= 0x80 && !vim_isprintc(c)) {
|
||||
// Characters below 0x100 are influenced by 'isprint' option.
|
||||
return 4; // unprintable, displays <xx>
|
||||
}
|
||||
/* Characters below 0x100 are influenced by 'isprint' option */
|
||||
else if (c >= 0x80 && !vim_isprintc(c))
|
||||
return 4; /* unprintable, displays <xx> */
|
||||
|
||||
if (c >= 0x80 && *p_ambw == 'd' && intable(ambiguous, ARRAY_SIZE(ambiguous), c))
|
||||
if (c >= 0x80 && *p_ambw == 'd'
|
||||
&& intable(ambiguous, ARRAY_SIZE(ambiguous), c)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user