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:
parent
c572b8bb1a
commit
fbe4d036d8
@ -217,9 +217,8 @@ def gen_wcwidth():
|
||||
p('\tswitch(code) {')
|
||||
|
||||
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, 'Marks', marks, -1)
|
||||
add(p, 'Private use', class_maps['Co'], -3)
|
||||
add(p, 'Text Presentation', emoji_categories['Emoji'] - emoji_categories['Emoji_Presentation'], 1)
|
||||
add(p, 'East Asian ambiguous width', ambiguous, -2)
|
||||
|
||||
2
kitty/emoji.h
generated
2
kitty/emoji.h
generated
@ -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
|
||||
#pragma once
|
||||
#include "data-types.h"
|
||||
|
||||
@ -278,7 +278,7 @@ unsigned int
|
||||
safe_wcwidth(uint32_t ch) {
|
||||
int ans = wcwidth_std(ch);
|
||||
if (ans < 0) ans = 1;
|
||||
return MIN(2, ans);
|
||||
return ans;
|
||||
}
|
||||
|
||||
static inline void
|
||||
@ -1445,8 +1445,7 @@ screen_wcswidth(Screen UNUSED *self, PyObject *str) {
|
||||
unsigned long ans = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
char_type ch = PyUnicode_READ(kind, data, i);
|
||||
bool is_cc = is_combining_char(ch);
|
||||
ans += is_cc ? 0 : safe_wcwidth(ch);
|
||||
ans += safe_wcwidth(ch);
|
||||
}
|
||||
return PyLong_FromUnsignedLong(ans);
|
||||
}
|
||||
|
||||
@ -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
|
||||
#include "data-types.h"
|
||||
|
||||
|
||||
1059
kitty/wcwidth-std.h
generated
1059
kitty/wcwidth-std.h
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user