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