diff options
Diffstat (limited to 'Modules/unicodedata.c')
-rw-r--r-- | Modules/unicodedata.c | 75 |
1 files changed, 58 insertions, 17 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index f4d3608750..c6c4ba2c71 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -17,6 +17,12 @@ #include "ucnhash.h" #include "structmember.h" +/*[clinic input] +module unicodedata +class unicodedata.UCD 'PreviousDBVersion *' '&UCD_Type' +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6dac153082d150bc]*/ + /* character properties */ typedef struct { @@ -107,25 +113,61 @@ static Py_UCS4 getuchar(PyUnicodeObject *obj) /* --- Module API --------------------------------------------------------- */ -PyDoc_STRVAR(unicodedata_decimal__doc__, -"decimal(unichr[, default])\n\ -\n\ -Returns the decimal value assigned to the Unicode character unichr\n\ -as integer. If no such value is defined, default is returned, or, if\n\ -not given, ValueError is raised."); +/*[clinic input] + +unicodedata.UCD.decimal + + unichr: object(type='PyUnicodeObject *', subclass_of='&PyUnicode_Type') + default: object=NULL + / + +Converts a Unicode character into its equivalent decimal value. + +Returns the decimal value assigned to the Unicode character unichr +as integer. If no such value is defined, default is returned, or, if +not given, ValueError is raised. +[clinic start generated code]*/ + +PyDoc_STRVAR(unicodedata_UCD_decimal__doc__, +"sig=($self, unichr, default=None)\n" +"Converts a Unicode character into its equivalent decimal value.\n" +"\n" +"Returns the decimal value assigned to the Unicode character unichr\n" +"as integer. If no such value is defined, default is returned, or, if\n" +"not given, ValueError is raised."); + +#define UNICODEDATA_UCD_DECIMAL_METHODDEF \ + {"decimal", (PyCFunction)unicodedata_UCD_decimal, METH_VARARGS, unicodedata_UCD_decimal__doc__}, static PyObject * -unicodedata_decimal(PyObject *self, PyObject *args) +unicodedata_UCD_decimal_impl(PreviousDBVersion *self, PyUnicodeObject *unichr, PyObject *default_value); + +static PyObject * +unicodedata_UCD_decimal(PreviousDBVersion *self, PyObject *args) +{ + PyObject *return_value = NULL; + PyUnicodeObject *unichr; + PyObject *default_value = NULL; + + if (!PyArg_ParseTuple(args, + "O!|O:decimal", + &PyUnicode_Type, &unichr, &default_value)) + goto exit; + return_value = unicodedata_UCD_decimal_impl(self, unichr, default_value); + +exit: + return return_value; +} + +static PyObject * +unicodedata_UCD_decimal_impl(PreviousDBVersion *self, PyUnicodeObject *unichr, PyObject *default_value) +/*[clinic end generated code: output=a3ad5de9393acb2f input=c25c9d2b4de076b1]*/ { - PyUnicodeObject *v; - PyObject *defobj = NULL; int have_old = 0; long rc; Py_UCS4 c; - if (!PyArg_ParseTuple(args, "O!|O:decimal", &PyUnicode_Type, &v, &defobj)) - return NULL; - c = getuchar(v); + c = getuchar(unichr); if (c == (Py_UCS4)-1) return NULL; @@ -145,14 +187,14 @@ unicodedata_decimal(PyObject *self, PyObject *args) if (!have_old) rc = Py_UNICODE_TODECIMAL(c); if (rc < 0) { - if (defobj == NULL) { + if (default_value == NULL) { PyErr_SetString(PyExc_ValueError, "not a decimal"); return NULL; } else { - Py_INCREF(defobj); - return defobj; + Py_INCREF(default_value); + return default_value; } } return PyLong_FromLong(rc); @@ -1250,7 +1292,7 @@ unicodedata_lookup(PyObject* self, PyObject* args) /* XXX Add doc strings. */ static PyMethodDef unicodedata_functions[] = { - {"decimal", unicodedata_decimal, METH_VARARGS, unicodedata_decimal__doc__}, + UNICODEDATA_UCD_DECIMAL_METHODDEF {"digit", unicodedata_digit, METH_VARARGS, unicodedata_digit__doc__}, {"numeric", unicodedata_numeric, METH_VARARGS, unicodedata_numeric__doc__}, {"category", unicodedata_category, METH_VARARGS, @@ -1327,7 +1369,6 @@ this database is based on the UnicodeData.txt file version\n\ The module uses the same names and symbols as defined by the\n\ UnicodeData File Format " UNIDATA_VERSION "."); - static struct PyModuleDef unicodedatamodule = { PyModuleDef_HEAD_INIT, "unicodedata", |