Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(unicodedata_UCD_decimal__doc__, |
Serhiy Storchaka | d322abb | 2019-09-14 13:31:50 +0300 | [diff] [blame^] | 6 | "decimal($self, chr, default=<unrepresentable>, /)\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 7 | "--\n" |
| 8 | "\n" |
| 9 | "Converts a Unicode character into its equivalent decimal value.\n" |
| 10 | "\n" |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 11 | "Returns the decimal value assigned to the character chr as integer.\n" |
| 12 | "If no such value is defined, default is returned, or, if not given,\n" |
| 13 | "ValueError is raised."); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 14 | |
| 15 | #define UNICODEDATA_UCD_DECIMAL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 16 | {"decimal", (PyCFunction)(void(*)(void))unicodedata_UCD_decimal, METH_FASTCALL, unicodedata_UCD_decimal__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 17 | |
| 18 | static PyObject * |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 19 | unicodedata_UCD_decimal_impl(PyObject *self, int chr, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 20 | PyObject *default_value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 21 | |
| 22 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 23 | unicodedata_UCD_decimal(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 24 | { |
| 25 | PyObject *return_value = NULL; |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 26 | int chr; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 27 | PyObject *default_value = NULL; |
| 28 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 29 | if (!_PyArg_CheckPositional("decimal", nargs, 1, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 30 | goto exit; |
| 31 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 32 | if (!PyUnicode_Check(args[0])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 33 | _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 34 | goto exit; |
| 35 | } |
| 36 | if (PyUnicode_READY(args[0])) { |
| 37 | goto exit; |
| 38 | } |
| 39 | if (PyUnicode_GET_LENGTH(args[0]) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 40 | _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 41 | goto exit; |
| 42 | } |
| 43 | chr = PyUnicode_READ_CHAR(args[0], 0); |
| 44 | if (nargs < 2) { |
| 45 | goto skip_optional; |
| 46 | } |
| 47 | default_value = args[1]; |
| 48 | skip_optional: |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 49 | return_value = unicodedata_UCD_decimal_impl(self, chr, default_value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 50 | |
| 51 | exit: |
| 52 | return return_value; |
| 53 | } |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 54 | |
| 55 | PyDoc_STRVAR(unicodedata_UCD_digit__doc__, |
Serhiy Storchaka | d322abb | 2019-09-14 13:31:50 +0300 | [diff] [blame^] | 56 | "digit($self, chr, default=<unrepresentable>, /)\n" |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 57 | "--\n" |
| 58 | "\n" |
| 59 | "Converts a Unicode character into its equivalent digit value.\n" |
| 60 | "\n" |
| 61 | "Returns the digit value assigned to the character chr as integer.\n" |
| 62 | "If no such value is defined, default is returned, or, if not given,\n" |
| 63 | "ValueError is raised."); |
| 64 | |
| 65 | #define UNICODEDATA_UCD_DIGIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 66 | {"digit", (PyCFunction)(void(*)(void))unicodedata_UCD_digit, METH_FASTCALL, unicodedata_UCD_digit__doc__}, |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 67 | |
| 68 | static PyObject * |
| 69 | unicodedata_UCD_digit_impl(PyObject *self, int chr, PyObject *default_value); |
| 70 | |
| 71 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 72 | unicodedata_UCD_digit(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 73 | { |
| 74 | PyObject *return_value = NULL; |
| 75 | int chr; |
| 76 | PyObject *default_value = NULL; |
| 77 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 78 | if (!_PyArg_CheckPositional("digit", nargs, 1, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 79 | goto exit; |
| 80 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 81 | if (!PyUnicode_Check(args[0])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 82 | _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 83 | goto exit; |
| 84 | } |
| 85 | if (PyUnicode_READY(args[0])) { |
| 86 | goto exit; |
| 87 | } |
| 88 | if (PyUnicode_GET_LENGTH(args[0]) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 89 | _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 90 | goto exit; |
| 91 | } |
| 92 | chr = PyUnicode_READ_CHAR(args[0], 0); |
| 93 | if (nargs < 2) { |
| 94 | goto skip_optional; |
| 95 | } |
| 96 | default_value = args[1]; |
| 97 | skip_optional: |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 98 | return_value = unicodedata_UCD_digit_impl(self, chr, default_value); |
| 99 | |
| 100 | exit: |
| 101 | return return_value; |
| 102 | } |
| 103 | |
| 104 | PyDoc_STRVAR(unicodedata_UCD_numeric__doc__, |
Serhiy Storchaka | d322abb | 2019-09-14 13:31:50 +0300 | [diff] [blame^] | 105 | "numeric($self, chr, default=<unrepresentable>, /)\n" |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 106 | "--\n" |
| 107 | "\n" |
| 108 | "Converts a Unicode character into its equivalent numeric value.\n" |
| 109 | "\n" |
| 110 | "Returns the numeric value assigned to the character chr as float.\n" |
| 111 | "If no such value is defined, default is returned, or, if not given,\n" |
| 112 | "ValueError is raised."); |
| 113 | |
| 114 | #define UNICODEDATA_UCD_NUMERIC_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 115 | {"numeric", (PyCFunction)(void(*)(void))unicodedata_UCD_numeric, METH_FASTCALL, unicodedata_UCD_numeric__doc__}, |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 116 | |
| 117 | static PyObject * |
| 118 | unicodedata_UCD_numeric_impl(PyObject *self, int chr, |
| 119 | PyObject *default_value); |
| 120 | |
| 121 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 122 | unicodedata_UCD_numeric(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 123 | { |
| 124 | PyObject *return_value = NULL; |
| 125 | int chr; |
| 126 | PyObject *default_value = NULL; |
| 127 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 128 | if (!_PyArg_CheckPositional("numeric", nargs, 1, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 129 | goto exit; |
| 130 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 131 | if (!PyUnicode_Check(args[0])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 132 | _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 133 | goto exit; |
| 134 | } |
| 135 | if (PyUnicode_READY(args[0])) { |
| 136 | goto exit; |
| 137 | } |
| 138 | if (PyUnicode_GET_LENGTH(args[0]) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 139 | _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 140 | goto exit; |
| 141 | } |
| 142 | chr = PyUnicode_READ_CHAR(args[0], 0); |
| 143 | if (nargs < 2) { |
| 144 | goto skip_optional; |
| 145 | } |
| 146 | default_value = args[1]; |
| 147 | skip_optional: |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 148 | return_value = unicodedata_UCD_numeric_impl(self, chr, default_value); |
| 149 | |
| 150 | exit: |
| 151 | return return_value; |
| 152 | } |
| 153 | |
| 154 | PyDoc_STRVAR(unicodedata_UCD_category__doc__, |
| 155 | "category($self, chr, /)\n" |
| 156 | "--\n" |
| 157 | "\n" |
| 158 | "Returns the general category assigned to the character chr as string."); |
| 159 | |
| 160 | #define UNICODEDATA_UCD_CATEGORY_METHODDEF \ |
| 161 | {"category", (PyCFunction)unicodedata_UCD_category, METH_O, unicodedata_UCD_category__doc__}, |
| 162 | |
| 163 | static PyObject * |
| 164 | unicodedata_UCD_category_impl(PyObject *self, int chr); |
| 165 | |
| 166 | static PyObject * |
| 167 | unicodedata_UCD_category(PyObject *self, PyObject *arg) |
| 168 | { |
| 169 | PyObject *return_value = NULL; |
| 170 | int chr; |
| 171 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 172 | if (!PyUnicode_Check(arg)) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 173 | _PyArg_BadArgument("category", "argument", "a unicode character", arg); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 174 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 175 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 176 | if (PyUnicode_READY(arg)) { |
| 177 | goto exit; |
| 178 | } |
| 179 | if (PyUnicode_GET_LENGTH(arg) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 180 | _PyArg_BadArgument("category", "argument", "a unicode character", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 181 | goto exit; |
| 182 | } |
| 183 | chr = PyUnicode_READ_CHAR(arg, 0); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 184 | return_value = unicodedata_UCD_category_impl(self, chr); |
| 185 | |
| 186 | exit: |
| 187 | return return_value; |
| 188 | } |
| 189 | |
| 190 | PyDoc_STRVAR(unicodedata_UCD_bidirectional__doc__, |
| 191 | "bidirectional($self, chr, /)\n" |
| 192 | "--\n" |
| 193 | "\n" |
| 194 | "Returns the bidirectional class assigned to the character chr as string.\n" |
| 195 | "\n" |
| 196 | "If no such value is defined, an empty string is returned."); |
| 197 | |
| 198 | #define UNICODEDATA_UCD_BIDIRECTIONAL_METHODDEF \ |
| 199 | {"bidirectional", (PyCFunction)unicodedata_UCD_bidirectional, METH_O, unicodedata_UCD_bidirectional__doc__}, |
| 200 | |
| 201 | static PyObject * |
| 202 | unicodedata_UCD_bidirectional_impl(PyObject *self, int chr); |
| 203 | |
| 204 | static PyObject * |
| 205 | unicodedata_UCD_bidirectional(PyObject *self, PyObject *arg) |
| 206 | { |
| 207 | PyObject *return_value = NULL; |
| 208 | int chr; |
| 209 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 210 | if (!PyUnicode_Check(arg)) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 211 | _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 212 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 213 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 214 | if (PyUnicode_READY(arg)) { |
| 215 | goto exit; |
| 216 | } |
| 217 | if (PyUnicode_GET_LENGTH(arg) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 218 | _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 219 | goto exit; |
| 220 | } |
| 221 | chr = PyUnicode_READ_CHAR(arg, 0); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 222 | return_value = unicodedata_UCD_bidirectional_impl(self, chr); |
| 223 | |
| 224 | exit: |
| 225 | return return_value; |
| 226 | } |
| 227 | |
| 228 | PyDoc_STRVAR(unicodedata_UCD_combining__doc__, |
| 229 | "combining($self, chr, /)\n" |
| 230 | "--\n" |
| 231 | "\n" |
| 232 | "Returns the canonical combining class assigned to the character chr as integer.\n" |
| 233 | "\n" |
| 234 | "Returns 0 if no combining class is defined."); |
| 235 | |
| 236 | #define UNICODEDATA_UCD_COMBINING_METHODDEF \ |
| 237 | {"combining", (PyCFunction)unicodedata_UCD_combining, METH_O, unicodedata_UCD_combining__doc__}, |
| 238 | |
| 239 | static int |
| 240 | unicodedata_UCD_combining_impl(PyObject *self, int chr); |
| 241 | |
| 242 | static PyObject * |
| 243 | unicodedata_UCD_combining(PyObject *self, PyObject *arg) |
| 244 | { |
| 245 | PyObject *return_value = NULL; |
| 246 | int chr; |
| 247 | int _return_value; |
| 248 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 249 | if (!PyUnicode_Check(arg)) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 250 | _PyArg_BadArgument("combining", "argument", "a unicode character", arg); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 251 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 252 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 253 | if (PyUnicode_READY(arg)) { |
| 254 | goto exit; |
| 255 | } |
| 256 | if (PyUnicode_GET_LENGTH(arg) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 257 | _PyArg_BadArgument("combining", "argument", "a unicode character", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 258 | goto exit; |
| 259 | } |
| 260 | chr = PyUnicode_READ_CHAR(arg, 0); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 261 | _return_value = unicodedata_UCD_combining_impl(self, chr); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 262 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 263 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 264 | } |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 265 | return_value = PyLong_FromLong((long)_return_value); |
| 266 | |
| 267 | exit: |
| 268 | return return_value; |
| 269 | } |
| 270 | |
| 271 | PyDoc_STRVAR(unicodedata_UCD_mirrored__doc__, |
| 272 | "mirrored($self, chr, /)\n" |
| 273 | "--\n" |
| 274 | "\n" |
| 275 | "Returns the mirrored property assigned to the character chr as integer.\n" |
| 276 | "\n" |
| 277 | "Returns 1 if the character has been identified as a \"mirrored\"\n" |
| 278 | "character in bidirectional text, 0 otherwise."); |
| 279 | |
| 280 | #define UNICODEDATA_UCD_MIRRORED_METHODDEF \ |
| 281 | {"mirrored", (PyCFunction)unicodedata_UCD_mirrored, METH_O, unicodedata_UCD_mirrored__doc__}, |
| 282 | |
| 283 | static int |
| 284 | unicodedata_UCD_mirrored_impl(PyObject *self, int chr); |
| 285 | |
| 286 | static PyObject * |
| 287 | unicodedata_UCD_mirrored(PyObject *self, PyObject *arg) |
| 288 | { |
| 289 | PyObject *return_value = NULL; |
| 290 | int chr; |
| 291 | int _return_value; |
| 292 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 293 | if (!PyUnicode_Check(arg)) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 294 | _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 295 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 296 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 297 | if (PyUnicode_READY(arg)) { |
| 298 | goto exit; |
| 299 | } |
| 300 | if (PyUnicode_GET_LENGTH(arg) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 301 | _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 302 | goto exit; |
| 303 | } |
| 304 | chr = PyUnicode_READ_CHAR(arg, 0); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 305 | _return_value = unicodedata_UCD_mirrored_impl(self, chr); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 306 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 307 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 308 | } |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 309 | return_value = PyLong_FromLong((long)_return_value); |
| 310 | |
| 311 | exit: |
| 312 | return return_value; |
| 313 | } |
| 314 | |
| 315 | PyDoc_STRVAR(unicodedata_UCD_east_asian_width__doc__, |
| 316 | "east_asian_width($self, chr, /)\n" |
| 317 | "--\n" |
| 318 | "\n" |
| 319 | "Returns the east asian width assigned to the character chr as string."); |
| 320 | |
| 321 | #define UNICODEDATA_UCD_EAST_ASIAN_WIDTH_METHODDEF \ |
| 322 | {"east_asian_width", (PyCFunction)unicodedata_UCD_east_asian_width, METH_O, unicodedata_UCD_east_asian_width__doc__}, |
| 323 | |
| 324 | static PyObject * |
| 325 | unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr); |
| 326 | |
| 327 | static PyObject * |
| 328 | unicodedata_UCD_east_asian_width(PyObject *self, PyObject *arg) |
| 329 | { |
| 330 | PyObject *return_value = NULL; |
| 331 | int chr; |
| 332 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 333 | if (!PyUnicode_Check(arg)) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 334 | _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 335 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 336 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 337 | if (PyUnicode_READY(arg)) { |
| 338 | goto exit; |
| 339 | } |
| 340 | if (PyUnicode_GET_LENGTH(arg) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 341 | _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 342 | goto exit; |
| 343 | } |
| 344 | chr = PyUnicode_READ_CHAR(arg, 0); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 345 | return_value = unicodedata_UCD_east_asian_width_impl(self, chr); |
| 346 | |
| 347 | exit: |
| 348 | return return_value; |
| 349 | } |
| 350 | |
| 351 | PyDoc_STRVAR(unicodedata_UCD_decomposition__doc__, |
| 352 | "decomposition($self, chr, /)\n" |
| 353 | "--\n" |
| 354 | "\n" |
| 355 | "Returns the character decomposition mapping assigned to the character chr as string.\n" |
| 356 | "\n" |
| 357 | "An empty string is returned in case no such mapping is defined."); |
| 358 | |
| 359 | #define UNICODEDATA_UCD_DECOMPOSITION_METHODDEF \ |
| 360 | {"decomposition", (PyCFunction)unicodedata_UCD_decomposition, METH_O, unicodedata_UCD_decomposition__doc__}, |
| 361 | |
| 362 | static PyObject * |
| 363 | unicodedata_UCD_decomposition_impl(PyObject *self, int chr); |
| 364 | |
| 365 | static PyObject * |
| 366 | unicodedata_UCD_decomposition(PyObject *self, PyObject *arg) |
| 367 | { |
| 368 | PyObject *return_value = NULL; |
| 369 | int chr; |
| 370 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 371 | if (!PyUnicode_Check(arg)) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 372 | _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 373 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 374 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 375 | if (PyUnicode_READY(arg)) { |
| 376 | goto exit; |
| 377 | } |
| 378 | if (PyUnicode_GET_LENGTH(arg) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 379 | _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 380 | goto exit; |
| 381 | } |
| 382 | chr = PyUnicode_READ_CHAR(arg, 0); |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 383 | return_value = unicodedata_UCD_decomposition_impl(self, chr); |
| 384 | |
| 385 | exit: |
| 386 | return return_value; |
| 387 | } |
| 388 | |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 389 | PyDoc_STRVAR(unicodedata_UCD_is_normalized__doc__, |
| 390 | "is_normalized($self, form, unistr, /)\n" |
| 391 | "--\n" |
| 392 | "\n" |
| 393 | "Return whether the Unicode string unistr is in the normal form \'form\'.\n" |
| 394 | "\n" |
| 395 | "Valid values for form are \'NFC\', \'NFKC\', \'NFD\', and \'NFKD\'."); |
| 396 | |
| 397 | #define UNICODEDATA_UCD_IS_NORMALIZED_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 398 | {"is_normalized", (PyCFunction)(void(*)(void))unicodedata_UCD_is_normalized, METH_FASTCALL, unicodedata_UCD_is_normalized__doc__}, |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 399 | |
| 400 | static PyObject * |
| 401 | unicodedata_UCD_is_normalized_impl(PyObject *self, PyObject *form, |
| 402 | PyObject *input); |
| 403 | |
| 404 | static PyObject * |
| 405 | unicodedata_UCD_is_normalized(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 406 | { |
| 407 | PyObject *return_value = NULL; |
| 408 | PyObject *form; |
| 409 | PyObject *input; |
| 410 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 411 | if (!_PyArg_CheckPositional("is_normalized", nargs, 2, 2)) { |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 412 | goto exit; |
| 413 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 414 | if (!PyUnicode_Check(args[0])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 415 | _PyArg_BadArgument("is_normalized", "argument 1", "str", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 416 | goto exit; |
| 417 | } |
| 418 | if (PyUnicode_READY(args[0]) == -1) { |
| 419 | goto exit; |
| 420 | } |
| 421 | form = args[0]; |
| 422 | if (!PyUnicode_Check(args[1])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 423 | _PyArg_BadArgument("is_normalized", "argument 2", "str", args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 424 | goto exit; |
| 425 | } |
| 426 | if (PyUnicode_READY(args[1]) == -1) { |
| 427 | goto exit; |
| 428 | } |
| 429 | input = args[1]; |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 430 | return_value = unicodedata_UCD_is_normalized_impl(self, form, input); |
| 431 | |
| 432 | exit: |
| 433 | return return_value; |
| 434 | } |
| 435 | |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 436 | PyDoc_STRVAR(unicodedata_UCD_normalize__doc__, |
| 437 | "normalize($self, form, unistr, /)\n" |
| 438 | "--\n" |
| 439 | "\n" |
| 440 | "Return the normal form \'form\' for the Unicode string unistr.\n" |
| 441 | "\n" |
| 442 | "Valid values for form are \'NFC\', \'NFKC\', \'NFD\', and \'NFKD\'."); |
| 443 | |
| 444 | #define UNICODEDATA_UCD_NORMALIZE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 445 | {"normalize", (PyCFunction)(void(*)(void))unicodedata_UCD_normalize, METH_FASTCALL, unicodedata_UCD_normalize__doc__}, |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 446 | |
| 447 | static PyObject * |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 448 | unicodedata_UCD_normalize_impl(PyObject *self, PyObject *form, |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 449 | PyObject *input); |
| 450 | |
| 451 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 452 | unicodedata_UCD_normalize(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 453 | { |
| 454 | PyObject *return_value = NULL; |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 455 | PyObject *form; |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 456 | PyObject *input; |
| 457 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 458 | if (!_PyArg_CheckPositional("normalize", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 459 | goto exit; |
| 460 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 461 | if (!PyUnicode_Check(args[0])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 462 | _PyArg_BadArgument("normalize", "argument 1", "str", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 463 | goto exit; |
| 464 | } |
| 465 | if (PyUnicode_READY(args[0]) == -1) { |
| 466 | goto exit; |
| 467 | } |
| 468 | form = args[0]; |
| 469 | if (!PyUnicode_Check(args[1])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 470 | _PyArg_BadArgument("normalize", "argument 2", "str", args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 471 | goto exit; |
| 472 | } |
| 473 | if (PyUnicode_READY(args[1]) == -1) { |
| 474 | goto exit; |
| 475 | } |
| 476 | input = args[1]; |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 477 | return_value = unicodedata_UCD_normalize_impl(self, form, input); |
| 478 | |
| 479 | exit: |
| 480 | return return_value; |
| 481 | } |
| 482 | |
| 483 | PyDoc_STRVAR(unicodedata_UCD_name__doc__, |
Serhiy Storchaka | d322abb | 2019-09-14 13:31:50 +0300 | [diff] [blame^] | 484 | "name($self, chr, default=<unrepresentable>, /)\n" |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 485 | "--\n" |
| 486 | "\n" |
| 487 | "Returns the name assigned to the character chr as a string.\n" |
| 488 | "\n" |
| 489 | "If no name is defined, default is returned, or, if not given,\n" |
| 490 | "ValueError is raised."); |
| 491 | |
| 492 | #define UNICODEDATA_UCD_NAME_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 493 | {"name", (PyCFunction)(void(*)(void))unicodedata_UCD_name, METH_FASTCALL, unicodedata_UCD_name__doc__}, |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 494 | |
| 495 | static PyObject * |
| 496 | unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value); |
| 497 | |
| 498 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 499 | unicodedata_UCD_name(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 500 | { |
| 501 | PyObject *return_value = NULL; |
| 502 | int chr; |
| 503 | PyObject *default_value = NULL; |
| 504 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 505 | if (!_PyArg_CheckPositional("name", nargs, 1, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 506 | goto exit; |
| 507 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 508 | if (!PyUnicode_Check(args[0])) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 509 | _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 510 | goto exit; |
| 511 | } |
| 512 | if (PyUnicode_READY(args[0])) { |
| 513 | goto exit; |
| 514 | } |
| 515 | if (PyUnicode_GET_LENGTH(args[0]) != 1) { |
Serhiy Storchaka | 96631dc | 2019-08-29 18:29:59 +0300 | [diff] [blame] | 516 | _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 517 | goto exit; |
| 518 | } |
| 519 | chr = PyUnicode_READ_CHAR(args[0], 0); |
| 520 | if (nargs < 2) { |
| 521 | goto skip_optional; |
| 522 | } |
| 523 | default_value = args[1]; |
| 524 | skip_optional: |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 525 | return_value = unicodedata_UCD_name_impl(self, chr, default_value); |
| 526 | |
| 527 | exit: |
| 528 | return return_value; |
| 529 | } |
| 530 | |
| 531 | PyDoc_STRVAR(unicodedata_UCD_lookup__doc__, |
| 532 | "lookup($self, name, /)\n" |
| 533 | "--\n" |
| 534 | "\n" |
| 535 | "Look up character by name.\n" |
| 536 | "\n" |
| 537 | "If a character with the given name is found, return the\n" |
| 538 | "corresponding character. If not found, KeyError is raised."); |
| 539 | |
| 540 | #define UNICODEDATA_UCD_LOOKUP_METHODDEF \ |
| 541 | {"lookup", (PyCFunction)unicodedata_UCD_lookup, METH_O, unicodedata_UCD_lookup__doc__}, |
| 542 | |
| 543 | static PyObject * |
| 544 | unicodedata_UCD_lookup_impl(PyObject *self, const char *name, |
| 545 | Py_ssize_clean_t name_length); |
| 546 | |
| 547 | static PyObject * |
| 548 | unicodedata_UCD_lookup(PyObject *self, PyObject *arg) |
| 549 | { |
| 550 | PyObject *return_value = NULL; |
| 551 | const char *name; |
| 552 | Py_ssize_clean_t name_length; |
| 553 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 554 | if (!PyArg_Parse(arg, "s#:lookup", &name, &name_length)) { |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 555 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 556 | } |
Serhiy Storchaka | 6359641 | 2015-04-17 21:18:49 +0300 | [diff] [blame] | 557 | return_value = unicodedata_UCD_lookup_impl(self, name, name_length); |
| 558 | |
| 559 | exit: |
| 560 | return return_value; |
| 561 | } |
Serhiy Storchaka | d322abb | 2019-09-14 13:31:50 +0300 | [diff] [blame^] | 562 | /*[clinic end generated code: output=10c23477dbe8a202 input=a9049054013a1b77]*/ |