diff options
Diffstat (limited to 'Modules/unicodedata.c')
-rw-r--r-- | Modules/unicodedata.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index 8aa18f2..4a1e94c 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -24,6 +24,8 @@ typedef struct { const unsigned char bidirectional; /* index into _PyUnicode_BidirectionalNames */ const unsigned char mirrored; /* true if mirrored in bidir mode */ + const unsigned char east_asian_width; /* index into + _PyUnicode_EastAsianWidth */ } _PyUnicode_DatabaseRecord; /* data file generated by Tools/unicode/makeunicodedata.py */ @@ -205,6 +207,24 @@ unicodedata_mirrored(PyObject *self, PyObject *args) } static PyObject * +unicodedata_east_asian_width(PyObject *self, PyObject *args) +{ + PyUnicodeObject *v; + int index; + + if (!PyArg_ParseTuple(args, "O!:east_asian_width", + &PyUnicode_Type, &v)) + return NULL; + if (PyUnicode_GET_SIZE(v) != 1) { + PyErr_SetString(PyExc_TypeError, + "need a single Unicode character as parameter"); + return NULL; + } + index = (int) _getrecord(v)->east_asian_width; + return PyString_FromString(_PyUnicode_EastAsianWidthNames[index]); +} + +static PyObject * unicodedata_decomposition(PyObject *self, PyObject *args) { PyUnicodeObject *v; @@ -871,6 +891,7 @@ static PyMethodDef unicodedata_functions[] = { {"bidirectional", unicodedata_bidirectional, METH_VARARGS}, {"combining", unicodedata_combining, METH_VARARGS}, {"mirrored", unicodedata_mirrored, METH_VARARGS}, + {"east_asian_width", unicodedata_east_asian_width, METH_VARARGS}, {"decomposition",unicodedata_decomposition, METH_VARARGS}, {"name", unicodedata_name, METH_VARARGS}, {"lookup", unicodedata_lookup, METH_VARARGS}, |