summaryrefslogtreecommitdiffstats
path: root/Modules/unicodedata.c
diff options
context:
space:
mode:
authorHye-Shik Chang <hyeshik@gmail.com>2004-08-04 07:38:35 (GMT)
committerHye-Shik Chang <hyeshik@gmail.com>2004-08-04 07:38:35 (GMT)
commite9ddfbb41207328d5c89061067f3431e00711fda (patch)
tree54093161fe6808de7d6fcc3304eb32241231f010 /Modules/unicodedata.c
parentb5047fd01948ab108edcc1b3c2c901d915814cfd (diff)
downloadcpython-e9ddfbb41207328d5c89061067f3431e00711fda.zip
cpython-e9ddfbb41207328d5c89061067f3431e00711fda.tar.gz
cpython-e9ddfbb41207328d5c89061067f3431e00711fda.tar.bz2
SF #989185: Drop unicode.iswide() and unicode.width() and add
unicodedata.east_asian_width(). You can still implement your own simple width() function using it like this: def width(u): w = 0 for c in unicodedata.normalize('NFC', u): cwidth = unicodedata.east_asian_width(c) if cwidth in ('W', 'F'): w += 2 else: w += 1 return w
Diffstat (limited to 'Modules/unicodedata.c')
-rw-r--r--Modules/unicodedata.c21
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},