mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-10 13:04:03 +03:00
Add a wcswidth() implementation useable from C code
This commit is contained in:
parent
0372242d12
commit
ada3f9e547
@ -118,6 +118,15 @@ wcswidth_step(WCSState *state, const char_type ch) {
|
||||
return ans;
|
||||
}
|
||||
|
||||
size_t
|
||||
wcswidth_string(const char_type *s) {
|
||||
WCSState state;
|
||||
initialize_wcs_state(&state);
|
||||
size_t ans = 0;
|
||||
while (*s) ans += wcswidth_step(&state, *(s++));
|
||||
return ans;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
wcswidth_std(PyObject UNUSED *self, PyObject *str) {
|
||||
if (PyUnicode_READY(str) != 0) return NULL;
|
||||
|
@ -20,3 +20,4 @@ typedef struct {
|
||||
void initialize_wcs_state(WCSState *state);
|
||||
int wcswidth_step(WCSState *state, const char_type ch);
|
||||
PyObject * wcswidth_std(PyObject UNUSED *self, PyObject *str);
|
||||
size_t wcswidth_string(const char_type *s);
|
||||
|
Loading…
Reference in New Issue
Block a user