Have wcwidth() return 0 for marks instead of -1

Since kitty always treats marks as combinig chars, this allows us to
remove a few unnecessary branches
This commit is contained in:
Kovid Goyal 2018-02-05 10:06:05 +05:30
parent c572b8bb1a
commit fbe4d036d8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 533 additions and 538 deletions

View File

@ -217,9 +217,8 @@ def gen_wcwidth():
p('\tswitch(code) {') p('\tswitch(code) {')
non_printing = class_maps['Cc'] | class_maps['Cf'] | class_maps['Cs'] non_printing = class_maps['Cc'] | class_maps['Cf'] | class_maps['Cs']
add(p, 'Null', {0}, 0) add(p, 'Marks', marks | {0}, 0)
add(p, 'Non-printing characters', non_printing, -1) add(p, 'Non-printing characters', non_printing, -1)
add(p, 'Marks', marks, -1)
add(p, 'Private use', class_maps['Co'], -3) add(p, 'Private use', class_maps['Co'], -3)
add(p, 'Text Presentation', emoji_categories['Emoji'] - emoji_categories['Emoji_Presentation'], 1) add(p, 'Text Presentation', emoji_categories['Emoji'] - emoji_categories['Emoji_Presentation'], 1)
add(p, 'East Asian ambiguous width', ambiguous, -2) add(p, 'East Asian ambiguous width', ambiguous, -2)

2
kitty/emoji.h generated
View File

@ -1,4 +1,4 @@
// unicode data, built from the unicode standard on: 2018-02-04 // unicode data, built from the unicode standard on: 2018-02-05
// see gen-wcwidth.py // see gen-wcwidth.py
#pragma once #pragma once
#include "data-types.h" #include "data-types.h"

View File

@ -278,7 +278,7 @@ unsigned int
safe_wcwidth(uint32_t ch) { safe_wcwidth(uint32_t ch) {
int ans = wcwidth_std(ch); int ans = wcwidth_std(ch);
if (ans < 0) ans = 1; if (ans < 0) ans = 1;
return MIN(2, ans); return ans;
} }
static inline void static inline void
@ -1445,8 +1445,7 @@ screen_wcswidth(Screen UNUSED *self, PyObject *str) {
unsigned long ans = 0; unsigned long ans = 0;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
char_type ch = PyUnicode_READ(kind, data, i); char_type ch = PyUnicode_READ(kind, data, i);
bool is_cc = is_combining_char(ch); ans += safe_wcwidth(ch);
ans += is_cc ? 0 : safe_wcwidth(ch);
} }
return PyLong_FromUnsignedLong(ans); return PyLong_FromUnsignedLong(ans);
} }

View File

@ -1,4 +1,4 @@
// unicode data, built from the unicode standard on: 2018-02-04 // unicode data, built from the unicode standard on: 2018-02-05
// see gen-wcwidth.py // see gen-wcwidth.py
#include "data-types.h" #include "data-types.h"

1059
kitty/wcwidth-std.h generated

File diff suppressed because it is too large Load Diff