Commit 26641e57 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #20181: Converted the unicodedata module to Argument Clinic.

parent dcc781b6
...@@ -3,37 +3,385 @@ preserve ...@@ -3,37 +3,385 @@ preserve
[clinic start generated code]*/ [clinic start generated code]*/
PyDoc_STRVAR(unicodedata_UCD_decimal__doc__, PyDoc_STRVAR(unicodedata_UCD_decimal__doc__,
"decimal($self, unichr, default=None, /)\n" "decimal($self, chr, default=None, /)\n"
"--\n" "--\n"
"\n" "\n"
"Converts a Unicode character into its equivalent decimal value.\n" "Converts a Unicode character into its equivalent decimal value.\n"
"\n" "\n"
"Returns the decimal value assigned to the Unicode character unichr\n" "Returns the decimal value assigned to the character chr as integer.\n"
"as integer. If no such value is defined, default is returned, or, if\n" "If no such value is defined, default is returned, or, if not given,\n"
"not given, ValueError is raised."); "ValueError is raised.");
#define UNICODEDATA_UCD_DECIMAL_METHODDEF \ #define UNICODEDATA_UCD_DECIMAL_METHODDEF \
{"decimal", (PyCFunction)unicodedata_UCD_decimal, METH_VARARGS, unicodedata_UCD_decimal__doc__}, {"decimal", (PyCFunction)unicodedata_UCD_decimal, METH_VARARGS, unicodedata_UCD_decimal__doc__},
static PyObject * static PyObject *
unicodedata_UCD_decimal_impl(PreviousDBVersion *self, unicodedata_UCD_decimal_impl(PyObject *self, int chr,
PyUnicodeObject *unichr,
PyObject *default_value); PyObject *default_value);
static PyObject * static PyObject *
unicodedata_UCD_decimal(PreviousDBVersion *self, PyObject *args) unicodedata_UCD_decimal(PyObject *self, PyObject *args)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
PyUnicodeObject *unichr; int chr;
PyObject *default_value = NULL; PyObject *default_value = NULL;
if (!PyArg_ParseTuple(args, if (!PyArg_ParseTuple(args,
"O!|O:decimal", "C|O:decimal",
&PyUnicode_Type, &unichr, &default_value)) &chr, &default_value))
goto exit; goto exit;
return_value = unicodedata_UCD_decimal_impl(self, unichr, default_value); return_value = unicodedata_UCD_decimal_impl(self, chr, default_value);
exit: exit:
return return_value; return return_value;
} }
/*[clinic end generated code: output=33b488251c4fd143 input=a9049054013a1b77]*/
PyDoc_STRVAR(unicodedata_UCD_digit__doc__,
"digit($self, chr, default=None, /)\n"
"--\n"
"\n"
"Converts a Unicode character into its equivalent digit value.\n"
"\n"
"Returns the digit value assigned to the character chr as integer.\n"
"If no such value is defined, default is returned, or, if not given,\n"
"ValueError is raised.");
#define UNICODEDATA_UCD_DIGIT_METHODDEF \
{"digit", (PyCFunction)unicodedata_UCD_digit, METH_VARARGS, unicodedata_UCD_digit__doc__},
static PyObject *
unicodedata_UCD_digit_impl(PyObject *self, int chr, PyObject *default_value);
static PyObject *
unicodedata_UCD_digit(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int chr;
PyObject *default_value = NULL;
if (!PyArg_ParseTuple(args,
"C|O:digit",
&chr, &default_value))
goto exit;
return_value = unicodedata_UCD_digit_impl(self, chr, default_value);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_numeric__doc__,
"numeric($self, chr, default=None, /)\n"
"--\n"
"\n"
"Converts a Unicode character into its equivalent numeric value.\n"
"\n"
"Returns the numeric value assigned to the character chr as float.\n"
"If no such value is defined, default is returned, or, if not given,\n"
"ValueError is raised.");
#define UNICODEDATA_UCD_NUMERIC_METHODDEF \
{"numeric", (PyCFunction)unicodedata_UCD_numeric, METH_VARARGS, unicodedata_UCD_numeric__doc__},
static PyObject *
unicodedata_UCD_numeric_impl(PyObject *self, int chr,
PyObject *default_value);
static PyObject *
unicodedata_UCD_numeric(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int chr;
PyObject *default_value = NULL;
if (!PyArg_ParseTuple(args,
"C|O:numeric",
&chr, &default_value))
goto exit;
return_value = unicodedata_UCD_numeric_impl(self, chr, default_value);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_category__doc__,
"category($self, chr, /)\n"
"--\n"
"\n"
"Returns the general category assigned to the character chr as string.");
#define UNICODEDATA_UCD_CATEGORY_METHODDEF \
{"category", (PyCFunction)unicodedata_UCD_category, METH_O, unicodedata_UCD_category__doc__},
static PyObject *
unicodedata_UCD_category_impl(PyObject *self, int chr);
static PyObject *
unicodedata_UCD_category(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int chr;
if (!PyArg_Parse(arg,
"C:category",
&chr))
goto exit;
return_value = unicodedata_UCD_category_impl(self, chr);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_bidirectional__doc__,
"bidirectional($self, chr, /)\n"
"--\n"
"\n"
"Returns the bidirectional class assigned to the character chr as string.\n"
"\n"
"If no such value is defined, an empty string is returned.");
#define UNICODEDATA_UCD_BIDIRECTIONAL_METHODDEF \
{"bidirectional", (PyCFunction)unicodedata_UCD_bidirectional, METH_O, unicodedata_UCD_bidirectional__doc__},
static PyObject *
unicodedata_UCD_bidirectional_impl(PyObject *self, int chr);
static PyObject *
unicodedata_UCD_bidirectional(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int chr;
if (!PyArg_Parse(arg,
"C:bidirectional",
&chr))
goto exit;
return_value = unicodedata_UCD_bidirectional_impl(self, chr);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_combining__doc__,
"combining($self, chr, /)\n"
"--\n"
"\n"
"Returns the canonical combining class assigned to the character chr as integer.\n"
"\n"
"Returns 0 if no combining class is defined.");
#define UNICODEDATA_UCD_COMBINING_METHODDEF \
{"combining", (PyCFunction)unicodedata_UCD_combining, METH_O, unicodedata_UCD_combining__doc__},
static int
unicodedata_UCD_combining_impl(PyObject *self, int chr);
static PyObject *
unicodedata_UCD_combining(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int chr;
int _return_value;
if (!PyArg_Parse(arg,
"C:combining",
&chr))
goto exit;
_return_value = unicodedata_UCD_combining_impl(self, chr);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong((long)_return_value);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_mirrored__doc__,
"mirrored($self, chr, /)\n"
"--\n"
"\n"
"Returns the mirrored property assigned to the character chr as integer.\n"
"\n"
"Returns 1 if the character has been identified as a \"mirrored\"\n"
"character in bidirectional text, 0 otherwise.");
#define UNICODEDATA_UCD_MIRRORED_METHODDEF \
{"mirrored", (PyCFunction)unicodedata_UCD_mirrored, METH_O, unicodedata_UCD_mirrored__doc__},
static int
unicodedata_UCD_mirrored_impl(PyObject *self, int chr);
static PyObject *
unicodedata_UCD_mirrored(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int chr;
int _return_value;
if (!PyArg_Parse(arg,
"C:mirrored",
&chr))
goto exit;
_return_value = unicodedata_UCD_mirrored_impl(self, chr);
if ((_return_value == -1) && PyErr_Occurred())
goto exit;
return_value = PyLong_FromLong((long)_return_value);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_east_asian_width__doc__,
"east_asian_width($self, chr, /)\n"
"--\n"
"\n"
"Returns the east asian width assigned to the character chr as string.");
#define UNICODEDATA_UCD_EAST_ASIAN_WIDTH_METHODDEF \
{"east_asian_width", (PyCFunction)unicodedata_UCD_east_asian_width, METH_O, unicodedata_UCD_east_asian_width__doc__},
static PyObject *
unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr);
static PyObject *
unicodedata_UCD_east_asian_width(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int chr;
if (!PyArg_Parse(arg,
"C:east_asian_width",
&chr))
goto exit;
return_value = unicodedata_UCD_east_asian_width_impl(self, chr);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_decomposition__doc__,
"decomposition($self, chr, /)\n"
"--\n"
"\n"
"Returns the character decomposition mapping assigned to the character chr as string.\n"
"\n"
"An empty string is returned in case no such mapping is defined.");
#define UNICODEDATA_UCD_DECOMPOSITION_METHODDEF \
{"decomposition", (PyCFunction)unicodedata_UCD_decomposition, METH_O, unicodedata_UCD_decomposition__doc__},
static PyObject *
unicodedata_UCD_decomposition_impl(PyObject *self, int chr);
static PyObject *
unicodedata_UCD_decomposition(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
int chr;
if (!PyArg_Parse(arg,
"C:decomposition",
&chr))
goto exit;
return_value = unicodedata_UCD_decomposition_impl(self, chr);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_normalize__doc__,
"normalize($self, form, unistr, /)\n"
"--\n"
"\n"
"Return the normal form \'form\' for the Unicode string unistr.\n"
"\n"
"Valid values for form are \'NFC\', \'NFKC\', \'NFD\', and \'NFKD\'.");
#define UNICODEDATA_UCD_NORMALIZE_METHODDEF \
{"normalize", (PyCFunction)unicodedata_UCD_normalize, METH_VARARGS, unicodedata_UCD_normalize__doc__},
static PyObject *
unicodedata_UCD_normalize_impl(PyObject *self, const char *form,
PyObject *input);
static PyObject *
unicodedata_UCD_normalize(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
const char *form;
PyObject *input;
if (!PyArg_ParseTuple(args,
"sO!:normalize",
&form, &PyUnicode_Type, &input))
goto exit;
return_value = unicodedata_UCD_normalize_impl(self, form, input);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_name__doc__,
"name($self, chr, default=None, /)\n"
"--\n"
"\n"
"Returns the name assigned to the character chr as a string.\n"
"\n"
"If no name is defined, default is returned, or, if not given,\n"
"ValueError is raised.");
#define UNICODEDATA_UCD_NAME_METHODDEF \
{"name", (PyCFunction)unicodedata_UCD_name, METH_VARARGS, unicodedata_UCD_name__doc__},
static PyObject *
unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value);
static PyObject *
unicodedata_UCD_name(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
int chr;
PyObject *default_value = NULL;
if (!PyArg_ParseTuple(args,
"C|O:name",
&chr, &default_value))
goto exit;
return_value = unicodedata_UCD_name_impl(self, chr, default_value);
exit:
return return_value;
}
PyDoc_STRVAR(unicodedata_UCD_lookup__doc__,
"lookup($self, name, /)\n"
"--\n"
"\n"
"Look up character by name.\n"
"\n"
"If a character with the given name is found, return the\n"
"corresponding character. If not found, KeyError is raised.");
#define UNICODEDATA_UCD_LOOKUP_METHODDEF \
{"lookup", (PyCFunction)unicodedata_UCD_lookup, METH_O, unicodedata_UCD_lookup__doc__},
static PyObject *
unicodedata_UCD_lookup_impl(PyObject *self, const char *name,
Py_ssize_clean_t name_length);
static PyObject *
unicodedata_UCD_lookup(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
const char *name;
Py_ssize_clean_t name_length;
if (!PyArg_Parse(arg,
"s#:lookup",
&name, &name_length))
goto exit;
return_value = unicodedata_UCD_lookup_impl(self, name, name_length);
exit:
return return_value;
}
/*[clinic end generated code: output=1f04e31ae703ffed input=a9049054013a1b77]*/
...@@ -101,50 +101,31 @@ new_previous_version(const char*name, const change_record* (*getrecord)(Py_UCS4) ...@@ -101,50 +101,31 @@ new_previous_version(const char*name, const change_record* (*getrecord)(Py_UCS4)
} }
static Py_UCS4 getuchar(PyUnicodeObject *obj)
{
if (PyUnicode_READY(obj))
return (Py_UCS4)-1;
if (PyUnicode_GET_LENGTH(obj) == 1) {
if (PyUnicode_READY(obj))
return (Py_UCS4)-1;
return PyUnicode_READ_CHAR(obj, 0);
}
PyErr_SetString(PyExc_TypeError,
"need a single Unicode character as parameter");
return (Py_UCS4)-1;
}
/* --- Module API --------------------------------------------------------- */ /* --- Module API --------------------------------------------------------- */
/*[clinic input] /*[clinic input]
unicodedata.UCD.decimal unicodedata.UCD.decimal
unichr: object(type='PyUnicodeObject *', subclass_of='&PyUnicode_Type') self: self
chr: int(types={'str'})
default: object=NULL default: object=NULL
/ /
Converts a Unicode character into its equivalent decimal value. Converts a Unicode character into its equivalent decimal value.
Returns the decimal value assigned to the Unicode character unichr Returns the decimal value assigned to the character chr as integer.
as integer. If no such value is defined, default is returned, or, if If no such value is defined, default is returned, or, if not given,
not given, ValueError is raised. ValueError is raised.
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_UCD_decimal_impl(PreviousDBVersion *self, unicodedata_UCD_decimal_impl(PyObject *self, int chr,
PyUnicodeObject *unichr,
PyObject *default_value) PyObject *default_value)
/*[clinic end generated code: output=bf853108f246ba19 input=c25c9d2b4de076b1]*/ /*[clinic end generated code: output=be23376e1a185231 input=3acf7f2238874a49]*/
{ {
int have_old = 0; int have_old = 0;
long rc; long rc;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
c = getuchar(unichr);
if (c == (Py_UCS4)-1)
return NULL;
if (self && UCD_Check(self)) { if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c); const change_record *old = get_old_record(self, c);
...@@ -175,61 +156,64 @@ unicodedata_UCD_decimal_impl(PreviousDBVersion *self, ...@@ -175,61 +156,64 @@ unicodedata_UCD_decimal_impl(PreviousDBVersion *self,
return PyLong_FromLong(rc); return PyLong_FromLong(rc);
} }
PyDoc_STRVAR(unicodedata_digit__doc__, /*[clinic input]
"digit(unichr[, default])\n\ unicodedata.UCD.digit
\n\
Returns the digit value assigned to the Unicode character unichr as\n\ self: self
integer. If no such value is defined, default is returned, or, if\n\ chr: int(types={'str'})
not given, ValueError is raised."); default: object=NULL
/
Converts a Unicode character into its equivalent digit value.
Returns the digit value assigned to the character chr as integer.
If no such value is defined, default is returned, or, if not given,
ValueError is raised.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_digit(PyObject *self, PyObject *args) unicodedata_UCD_digit_impl(PyObject *self, int chr, PyObject *default_value)
/*[clinic end generated code: output=96e18c950171fd2f input=733f093b399f5ab6]*/
{ {
PyUnicodeObject *v;
PyObject *defobj = NULL;
long rc; long rc;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!|O:digit", &PyUnicode_Type, &v, &defobj))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
rc = Py_UNICODE_TODIGIT(c); rc = Py_UNICODE_TODIGIT(c);
if (rc < 0) { if (rc < 0) {
if (defobj == NULL) { if (default_value == NULL) {
PyErr_SetString(PyExc_ValueError, "not a digit"); PyErr_SetString(PyExc_ValueError, "not a digit");
return NULL; return NULL;
} }
else { else {
Py_INCREF(defobj); Py_INCREF(default_value);
return defobj; return default_value;
} }
} }
return PyLong_FromLong(rc); return PyLong_FromLong(rc);
} }
PyDoc_STRVAR(unicodedata_numeric__doc__, /*[clinic input]
"numeric(unichr[, default])\n\ unicodedata.UCD.numeric
\n\
Returns the numeric value assigned to the Unicode character unichr\n\ self: self
as float. If no such value is defined, default is returned, or, if\n\ chr: int(types={'str'})
not given, ValueError is raised."); default: object=NULL
/
Converts a Unicode character into its equivalent numeric value.
Returns the numeric value assigned to the character chr as float.
If no such value is defined, default is returned, or, if not given,
ValueError is raised.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_numeric(PyObject *self, PyObject *args) unicodedata_UCD_numeric_impl(PyObject *self, int chr,
PyObject *default_value)
/*[clinic end generated code: output=53ce281fe85b10c4 input=c5875fa7cc768fb2]*/
{ {
PyUnicodeObject *v;
PyObject *defobj = NULL;
int have_old = 0; int have_old = 0;
double rc; double rc;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!|O:numeric", &PyUnicode_Type, &v, &defobj))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
if (self && UCD_Check(self)) { if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c); const change_record *old = get_old_record(self, c);
...@@ -247,37 +231,34 @@ unicodedata_numeric(PyObject *self, PyObject *args) ...@@ -247,37 +231,34 @@ unicodedata_numeric(PyObject *self, PyObject *args)
if (!have_old) if (!have_old)
rc = Py_UNICODE_TONUMERIC(c); rc = Py_UNICODE_TONUMERIC(c);
if (rc == -1.0) { if (rc == -1.0) {
if (defobj == NULL) { if (default_value == NULL) {
PyErr_SetString(PyExc_ValueError, "not a numeric character"); PyErr_SetString(PyExc_ValueError, "not a numeric character");
return NULL; return NULL;
} }
else { else {
Py_INCREF(defobj); Py_INCREF(default_value);
return defobj; return default_value;
} }
} }
return PyFloat_FromDouble(rc); return PyFloat_FromDouble(rc);
} }
PyDoc_STRVAR(unicodedata_category__doc__, /*[clinic input]
"category(unichr)\n\ unicodedata.UCD.category
\n\
Returns the general category assigned to the Unicode character\n\ self: self
unichr as string."); chr: int(types={'str'})
/
Returns the general category assigned to the character chr as string.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_category(PyObject *self, PyObject *args) unicodedata_UCD_category_impl(PyObject *self, int chr)
/*[clinic end generated code: output=8571539ee2e6783a input=f5edd6fd04bd455d]*/
{ {
PyUnicodeObject *v;
int index; int index;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!:category",
&PyUnicode_Type, &v))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->category; index = (int) _getrecord_ex(c)->category;
if (self && UCD_Check(self)) { if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c); const change_record *old = get_old_record(self, c);
...@@ -287,26 +268,24 @@ unicodedata_category(PyObject *self, PyObject *args) ...@@ -287,26 +268,24 @@ unicodedata_category(PyObject *self, PyObject *args)
return PyUnicode_FromString(_PyUnicode_CategoryNames[index]); return PyUnicode_FromString(_PyUnicode_CategoryNames[index]);
} }
PyDoc_STRVAR(unicodedata_bidirectional__doc__, /*[clinic input]
"bidirectional(unichr)\n\ unicodedata.UCD.bidirectional
\n\
Returns the bidirectional class assigned to the Unicode character\n\ self: self
unichr as string. If no such value is defined, an empty string is\n\ chr: int(types={'str'})
returned."); /
Returns the bidirectional class assigned to the character chr as string.
If no such value is defined, an empty string is returned.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_bidirectional(PyObject *self, PyObject *args) unicodedata_UCD_bidirectional_impl(PyObject *self, int chr)
/*[clinic end generated code: output=d36310ce2039bb92 input=5ce2f877b35305b5]*/
{ {
PyUnicodeObject *v;
int index; int index;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!:bidirectional",
&PyUnicode_Type, &v))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->bidirectional; index = (int) _getrecord_ex(c)->bidirectional;
if (self && UCD_Check(self)) { if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c); const change_record *old = get_old_record(self, c);
...@@ -318,55 +297,52 @@ unicodedata_bidirectional(PyObject *self, PyObject *args) ...@@ -318,55 +297,52 @@ unicodedata_bidirectional(PyObject *self, PyObject *args)
return PyUnicode_FromString(_PyUnicode_BidirectionalNames[index]); return PyUnicode_FromString(_PyUnicode_BidirectionalNames[index]);
} }
PyDoc_STRVAR(unicodedata_combining__doc__, /*[clinic input]
"combining(unichr)\n\ unicodedata.UCD.combining -> int
\n\
Returns the canonical combining class assigned to the Unicode\n\
character unichr as integer. Returns 0 if no combining class is\n\
defined.");
static PyObject * self: self
unicodedata_combining(PyObject *self, PyObject *args) chr: int(types={'str'})
/
Returns the canonical combining class assigned to the character chr as integer.
Returns 0 if no combining class is defined.
[clinic start generated code]*/
static int
unicodedata_UCD_combining_impl(PyObject *self, int chr)
/*[clinic end generated code: output=cad056d0cb6a5920 input=9125ea7d50b319e7]*/
{ {
PyUnicodeObject *v;
int index; int index;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!:combining",
&PyUnicode_Type, &v))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->combining; index = (int) _getrecord_ex(c)->combining;
if (self && UCD_Check(self)) { if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c); const change_record *old = get_old_record(self, c);
if (old->category_changed == 0) if (old->category_changed == 0)
index = 0; /* unassigned */ index = 0; /* unassigned */
} }
return PyLong_FromLong(index); return index;
} }
PyDoc_STRVAR(unicodedata_mirrored__doc__, /*[clinic input]
"mirrored(unichr)\n\ unicodedata.UCD.mirrored -> int
\n\
Returns the mirrored property assigned to the Unicode character\n\
unichr as integer. Returns 1 if the character has been identified as\n\
a \"mirrored\" character in bidirectional text, 0 otherwise.");
static PyObject * self: self
unicodedata_mirrored(PyObject *self, PyObject *args) chr: int(types={'str'})
/
Returns the mirrored property assigned to the character chr as integer.
Returns 1 if the character has been identified as a "mirrored"
character in bidirectional text, 0 otherwise.
[clinic start generated code]*/
static int
unicodedata_UCD_mirrored_impl(PyObject *self, int chr)
/*[clinic end generated code: output=2532dbf8121b50e6 input=4e51e8aaf8d7e23e]*/
{ {
PyUnicodeObject *v;
int index; int index;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!:mirrored",
&PyUnicode_Type, &v))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->mirrored; index = (int) _getrecord_ex(c)->mirrored;
if (self && UCD_Check(self)) { if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c); const change_record *old = get_old_record(self, c);
...@@ -375,28 +351,25 @@ unicodedata_mirrored(PyObject *self, PyObject *args) ...@@ -375,28 +351,25 @@ unicodedata_mirrored(PyObject *self, PyObject *args)
else if (old->mirrored_changed != 0xFF) else if (old->mirrored_changed != 0xFF)
index = old->mirrored_changed; index = old->mirrored_changed;
} }
return PyLong_FromLong(index); return index;
} }
PyDoc_STRVAR(unicodedata_east_asian_width__doc__, /*[clinic input]
"east_asian_width(unichr)\n\ unicodedata.UCD.east_asian_width
\n\
Returns the east asian width assigned to the Unicode character\n\ self: self
unichr as string."); chr: int(types={'str'})
/
Returns the east asian width assigned to the character chr as string.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_east_asian_width(PyObject *self, PyObject *args) unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr)
/*[clinic end generated code: output=484e8537d9ee8197 input=f93c61f37276c8f0]*/
{ {
PyUnicodeObject *v;
int index; int index;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!:east_asian_width",
&PyUnicode_Type, &v))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->east_asian_width; index = (int) _getrecord_ex(c)->east_asian_width;
if (self && UCD_Check(self)) { if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c); const change_record *old = get_old_record(self, c);
...@@ -406,29 +379,27 @@ unicodedata_east_asian_width(PyObject *self, PyObject *args) ...@@ -406,29 +379,27 @@ unicodedata_east_asian_width(PyObject *self, PyObject *args)
return PyUnicode_FromString(_PyUnicode_EastAsianWidthNames[index]); return PyUnicode_FromString(_PyUnicode_EastAsianWidthNames[index]);
} }
PyDoc_STRVAR(unicodedata_decomposition__doc__, /*[clinic input]
"decomposition(unichr)\n\ unicodedata.UCD.decomposition
\n\
Returns the character decomposition mapping assigned to the Unicode\n\ self: self
character unichr as string. An empty string is returned in case no\n\ chr: int(types={'str'})
such mapping is defined."); /
Returns the character decomposition mapping assigned to the character chr as string.
An empty string is returned in case no such mapping is defined.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_decomposition(PyObject *self, PyObject *args) unicodedata_UCD_decomposition_impl(PyObject *self, int chr)
/*[clinic end generated code: output=7d699f3ec7565d27 input=7f2c0ee66d75468f]*/
{ {
PyUnicodeObject *v;
char decomp[256]; char decomp[256];
int code, index, count; int code, index, count;
size_t i; size_t i;
unsigned int prefix_index; unsigned int prefix_index;
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
if (!PyArg_ParseTuple(args, "O!:decomposition",
&PyUnicode_Type, &v))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
code = (int)c; code = (int)c;
...@@ -829,22 +800,24 @@ is_normalized(PyObject *self, PyObject *input, int nfc, int k) ...@@ -829,22 +800,24 @@ is_normalized(PyObject *self, PyObject *input, int nfc, int k)
return 1; /* certainly normalized */ return 1; /* certainly normalized */
} }
PyDoc_STRVAR(unicodedata_normalize__doc__, /*[clinic input]
"normalize(form, unistr)\n\ unicodedata.UCD.normalize
\n\
Return the normal form 'form' for the Unicode string unistr. Valid\n\
values for form are 'NFC', 'NFKC', 'NFD', and 'NFKD'.");
static PyObject* self: self
unicodedata_normalize(PyObject *self, PyObject *args) form: str
{ unistr as input: object(subclass_of='&PyUnicode_Type')
char *form; /
PyObject *input;
if(!PyArg_ParseTuple(args, "sO!:normalize", Return the normal form 'form' for the Unicode string unistr.
&form, &PyUnicode_Type, &input))
return NULL; Valid values for form are 'NFC', 'NFKC', 'NFD', and 'NFKD'.
[clinic start generated code]*/
static PyObject *
unicodedata_UCD_normalize_impl(PyObject *self, const char *form,
PyObject *input)
/*[clinic end generated code: output=62d1f8870027efdc input=cd092e631cf11883]*/
{
if (PyUnicode_READY(input) == -1) if (PyUnicode_READY(input) == -1)
return NULL; return NULL;
...@@ -1203,64 +1176,67 @@ static const _PyUnicode_Name_CAPI hashAPI = ...@@ -1203,64 +1176,67 @@ static const _PyUnicode_Name_CAPI hashAPI =
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Python bindings */ /* Python bindings */
PyDoc_STRVAR(unicodedata_name__doc__, /*[clinic input]
"name(unichr[, default])\n\ unicodedata.UCD.name
Returns the name assigned to the Unicode character unichr as a\n\
string. If no name is defined, default is returned, or, if not\n\ self: self
given, ValueError is raised."); chr: int(types={'str'})
default: object=NULL
/
Returns the name assigned to the character chr as a string.
If no name is defined, default is returned, or, if not given,
ValueError is raised.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_name(PyObject* self, PyObject* args) unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value)
/*[clinic end generated code: output=6bbb37a326407707 input=51ee2f971c918113]*/
{ {
char name[NAME_MAXLEN]; char name[NAME_MAXLEN];
Py_UCS4 c; Py_UCS4 c = (Py_UCS4)chr;
PyUnicodeObject* v;
PyObject* defobj = NULL;
if (!PyArg_ParseTuple(args, "O!|O:name", &PyUnicode_Type, &v, &defobj))
return NULL;
c = getuchar(v);
if (c == (Py_UCS4)-1)
return NULL;
if (!_getucname(self, c, name, sizeof(name), 0)) { if (!_getucname(self, c, name, sizeof(name), 0)) {
if (defobj == NULL) { if (default_value == NULL) {
PyErr_SetString(PyExc_ValueError, "no such name"); PyErr_SetString(PyExc_ValueError, "no such name");
return NULL; return NULL;
} }
else { else {
Py_INCREF(defobj); Py_INCREF(default_value);
return defobj; return default_value;
} }
} }
return PyUnicode_FromString(name); return PyUnicode_FromString(name);
} }
PyDoc_STRVAR(unicodedata_lookup__doc__, /*[clinic input]
"lookup(name)\n\ unicodedata.UCD.lookup
\n\
Look up character by name. If a character with the\n\ self: self
given name is found, return the corresponding Unicode\n\ name: str(types={'str', 'robuffer'}, length=True)
character. If not found, KeyError is raised."); /
Look up character by name.
If a character with the given name is found, return the
corresponding character. If not found, KeyError is raised.
[clinic start generated code]*/
static PyObject * static PyObject *
unicodedata_lookup(PyObject* self, PyObject* args) unicodedata_UCD_lookup_impl(PyObject *self, const char *name,
Py_ssize_clean_t name_length)
/*[clinic end generated code: output=765cb8186788e6be input=f2bf29706135a590]*/
{ {
Py_UCS4 code; Py_UCS4 code;
char* name;
Py_ssize_t namelen;
unsigned int index; unsigned int index;
if (!PyArg_ParseTuple(args, "s#:lookup", &name, &namelen)) if (name_length > INT_MAX) {
return NULL;
if (namelen > INT_MAX) {
PyErr_SetString(PyExc_KeyError, "name too long"); PyErr_SetString(PyExc_KeyError, "name too long");
return NULL; return NULL;
} }
if (!_getcode(self, name, (int)namelen, &code, 1)) { if (!_getcode(self, name, (int)name_length, &code, 1)) {
PyErr_Format(PyExc_KeyError, "undefined character name '%s'", name); PyErr_Format(PyExc_KeyError, "undefined character name '%s'", name);
return NULL; return NULL;
} }
...@@ -1279,24 +1255,17 @@ unicodedata_lookup(PyObject* self, PyObject* args) ...@@ -1279,24 +1255,17 @@ unicodedata_lookup(PyObject* self, PyObject* args)
static PyMethodDef unicodedata_functions[] = { static PyMethodDef unicodedata_functions[] = {
UNICODEDATA_UCD_DECIMAL_METHODDEF UNICODEDATA_UCD_DECIMAL_METHODDEF
{"digit", unicodedata_digit, METH_VARARGS, unicodedata_digit__doc__}, UNICODEDATA_UCD_DIGIT_METHODDEF
{"numeric", unicodedata_numeric, METH_VARARGS, unicodedata_numeric__doc__}, UNICODEDATA_UCD_NUMERIC_METHODDEF
{"category", unicodedata_category, METH_VARARGS, UNICODEDATA_UCD_CATEGORY_METHODDEF
unicodedata_category__doc__}, UNICODEDATA_UCD_BIDIRECTIONAL_METHODDEF
{"bidirectional", unicodedata_bidirectional, METH_VARARGS, UNICODEDATA_UCD_COMBINING_METHODDEF
unicodedata_bidirectional__doc__}, UNICODEDATA_UCD_MIRRORED_METHODDEF
{"combining", unicodedata_combining, METH_VARARGS, UNICODEDATA_UCD_EAST_ASIAN_WIDTH_METHODDEF
unicodedata_combining__doc__}, UNICODEDATA_UCD_DECOMPOSITION_METHODDEF
{"mirrored", unicodedata_mirrored, METH_VARARGS, UNICODEDATA_UCD_NAME_METHODDEF
unicodedata_mirrored__doc__}, UNICODEDATA_UCD_LOOKUP_METHODDEF
{"east_asian_width", unicodedata_east_asian_width, METH_VARARGS, UNICODEDATA_UCD_NORMALIZE_METHODDEF
unicodedata_east_asian_width__doc__},
{"decomposition", unicodedata_decomposition, METH_VARARGS,
unicodedata_decomposition__doc__},
{"name", unicodedata_name, METH_VARARGS, unicodedata_name__doc__},
{"lookup", unicodedata_lookup, METH_VARARGS, unicodedata_lookup__doc__},
{"normalize", unicodedata_normalize, METH_VARARGS,
unicodedata_normalize__doc__},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment