Use the new multi-stage unicode table for wcwidth

This commit is contained in:
Kovid Goyal
2025-03-24 14:20:40 +05:30
parent 7697a1650d
commit 3d0e45ace8
12 changed files with 34 additions and 6719 deletions

View File

@@ -5,7 +5,7 @@
* Distributed under terms of the GPL3 license.
*/
#include "wcwidth-std.h"
#include "char-props.h"
#include "wcswidth.h"
#include "unicode-data.h"
@@ -19,6 +19,11 @@ is_flag_pair(char_type a, char_type b) {
return is_flag_codepoint(a) && is_flag_codepoint(b);
}
static inline bool
is_emoji_presentation_base(char_type ch) {
return char_props_for(ch).is_emoji_presentation_base == 1;
}
int
wcswidth_step(WCSState *state, const char_type ch) {
int ans = 0;
@@ -59,7 +64,7 @@ wcswidth_step(WCSState *state, const char_type ch) {
default: {
if (is_flag_codepoint(ch)) state->parser_state = FLAG_PAIR_STARTED;
int w = wcwidth_std(ch);
int w = wcwidth_std(char_props_for(ch));
switch(w) {
case -1:
case 0:
@@ -142,8 +147,3 @@ wcswidth_std(PyObject UNUSED *self, PyObject *str) {
}
return PyLong_FromSize_t(ans);
}
PyObject*
unicode_database_version(PyObject *self UNUSED, PyObject *args UNUSED) {
return Py_BuildValue("iii", UNICODE_MAJOR_VERSION, UNICODE_MINOR_VERSION, UNICODE_PATCH_VERSION);
}