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;
|
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 *
|
PyObject *
|
||||||
wcswidth_std(PyObject UNUSED *self, PyObject *str) {
|
wcswidth_std(PyObject UNUSED *self, PyObject *str) {
|
||||||
if (PyUnicode_READY(str) != 0) return NULL;
|
if (PyUnicode_READY(str) != 0) return NULL;
|
||||||
|
|||||||
@ -20,3 +20,4 @@ typedef struct {
|
|||||||
void initialize_wcs_state(WCSState *state);
|
void initialize_wcs_state(WCSState *state);
|
||||||
int wcswidth_step(WCSState *state, const char_type ch);
|
int wcswidth_step(WCSState *state, const char_type ch);
|
||||||
PyObject * wcswidth_std(PyObject UNUSED *self, PyObject *str);
|
PyObject * wcswidth_std(PyObject UNUSED *self, PyObject *str);
|
||||||
|
size_t wcswidth_string(const char_type *s);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user