Line data Source code
1 : /*[clinic input]
2 : preserve
3 : [clinic start generated code]*/
4 :
5 : PyDoc_STRVAR(unicodedata_UCD_decimal__doc__,
6 : "decimal($self, chr, default=<unrepresentable>, /)\n"
7 : "--\n"
8 : "\n"
9 : "Converts a Unicode character into its equivalent decimal value.\n"
10 : "\n"
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.");
14 :
15 : #define UNICODEDATA_UCD_DECIMAL_METHODDEF \
16 : {"decimal", _PyCFunction_CAST(unicodedata_UCD_decimal), METH_FASTCALL, unicodedata_UCD_decimal__doc__},
17 :
18 : static PyObject *
19 : unicodedata_UCD_decimal_impl(PyObject *self, int chr,
20 : PyObject *default_value);
21 :
22 : static PyObject *
23 1179660 : unicodedata_UCD_decimal(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
24 : {
25 1179660 : PyObject *return_value = NULL;
26 : int chr;
27 1179660 : PyObject *default_value = NULL;
28 :
29 1179660 : if (!_PyArg_CheckPositional("decimal", nargs, 1, 2)) {
30 1 : goto exit;
31 : }
32 1179660 : if (!PyUnicode_Check(args[0])) {
33 0 : _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
34 0 : goto exit;
35 : }
36 1179660 : if (PyUnicode_READY(args[0])) {
37 0 : goto exit;
38 : }
39 1179660 : if (PyUnicode_GET_LENGTH(args[0]) != 1) {
40 1 : _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
41 1 : goto exit;
42 : }
43 1179660 : chr = PyUnicode_READ_CHAR(args[0], 0);
44 1179660 : if (nargs < 2) {
45 3 : goto skip_optional;
46 : }
47 1179650 : default_value = args[1];
48 1179660 : skip_optional:
49 1179660 : return_value = unicodedata_UCD_decimal_impl(self, chr, default_value);
50 :
51 1179660 : exit:
52 1179660 : return return_value;
53 : }
54 :
55 : PyDoc_STRVAR(unicodedata_UCD_digit__doc__,
56 : "digit($self, chr, default=<unrepresentable>, /)\n"
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 \
66 : {"digit", _PyCFunction_CAST(unicodedata_UCD_digit), METH_FASTCALL, unicodedata_UCD_digit__doc__},
67 :
68 : static PyObject *
69 : unicodedata_UCD_digit_impl(PyObject *self, int chr, PyObject *default_value);
70 :
71 : static PyObject *
72 1179660 : unicodedata_UCD_digit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
73 : {
74 1179660 : PyObject *return_value = NULL;
75 : int chr;
76 1179660 : PyObject *default_value = NULL;
77 :
78 1179660 : if (!_PyArg_CheckPositional("digit", nargs, 1, 2)) {
79 1 : goto exit;
80 : }
81 1179660 : if (!PyUnicode_Check(args[0])) {
82 0 : _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
83 0 : goto exit;
84 : }
85 1179660 : if (PyUnicode_READY(args[0])) {
86 0 : goto exit;
87 : }
88 1179660 : if (PyUnicode_GET_LENGTH(args[0]) != 1) {
89 1 : _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
90 1 : goto exit;
91 : }
92 1179660 : chr = PyUnicode_READ_CHAR(args[0], 0);
93 1179660 : if (nargs < 2) {
94 4 : goto skip_optional;
95 : }
96 1179650 : default_value = args[1];
97 1179660 : skip_optional:
98 1179660 : return_value = unicodedata_UCD_digit_impl(self, chr, default_value);
99 :
100 1179660 : exit:
101 1179660 : return return_value;
102 : }
103 :
104 : PyDoc_STRVAR(unicodedata_UCD_numeric__doc__,
105 : "numeric($self, chr, default=<unrepresentable>, /)\n"
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 \
115 : {"numeric", _PyCFunction_CAST(unicodedata_UCD_numeric), METH_FASTCALL, unicodedata_UCD_numeric__doc__},
116 :
117 : static PyObject *
118 : unicodedata_UCD_numeric_impl(PyObject *self, int chr,
119 : PyObject *default_value);
120 :
121 : static PyObject *
122 1114960 : unicodedata_UCD_numeric(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
123 : {
124 1114960 : PyObject *return_value = NULL;
125 : int chr;
126 1114960 : PyObject *default_value = NULL;
127 :
128 1114960 : if (!_PyArg_CheckPositional("numeric", nargs, 1, 2)) {
129 1 : goto exit;
130 : }
131 1114960 : if (!PyUnicode_Check(args[0])) {
132 0 : _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
133 0 : goto exit;
134 : }
135 1114960 : if (PyUnicode_READY(args[0])) {
136 0 : goto exit;
137 : }
138 1114960 : if (PyUnicode_GET_LENGTH(args[0]) != 1) {
139 1 : _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
140 1 : goto exit;
141 : }
142 1114960 : chr = PyUnicode_READ_CHAR(args[0], 0);
143 1114960 : if (nargs < 2) {
144 841 : goto skip_optional;
145 : }
146 1114110 : default_value = args[1];
147 1114960 : skip_optional:
148 1114960 : return_value = unicodedata_UCD_numeric_impl(self, chr, default_value);
149 :
150 1114960 : exit:
151 1114960 : 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 2229040 : unicodedata_UCD_category(PyObject *self, PyObject *arg)
168 : {
169 2229040 : PyObject *return_value = NULL;
170 : int chr;
171 :
172 2229040 : if (!PyUnicode_Check(arg)) {
173 0 : _PyArg_BadArgument("category", "argument", "a unicode character", arg);
174 0 : goto exit;
175 : }
176 2229040 : if (PyUnicode_READY(arg)) {
177 0 : goto exit;
178 : }
179 2229040 : if (PyUnicode_GET_LENGTH(arg) != 1) {
180 1 : _PyArg_BadArgument("category", "argument", "a unicode character", arg);
181 1 : goto exit;
182 : }
183 2229040 : chr = PyUnicode_READ_CHAR(arg, 0);
184 2229040 : return_value = unicodedata_UCD_category_impl(self, chr);
185 :
186 2229040 : exit:
187 2229040 : 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 2228460 : unicodedata_UCD_bidirectional(PyObject *self, PyObject *arg)
206 : {
207 2228460 : PyObject *return_value = NULL;
208 : int chr;
209 :
210 2228460 : if (!PyUnicode_Check(arg)) {
211 0 : _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
212 0 : goto exit;
213 : }
214 2228460 : if (PyUnicode_READY(arg)) {
215 0 : goto exit;
216 : }
217 2228460 : if (PyUnicode_GET_LENGTH(arg) != 1) {
218 1 : _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
219 1 : goto exit;
220 : }
221 2228460 : chr = PyUnicode_READ_CHAR(arg, 0);
222 2228460 : return_value = unicodedata_UCD_bidirectional_impl(self, chr);
223 :
224 2228460 : exit:
225 2228460 : 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 1114120 : unicodedata_UCD_combining(PyObject *self, PyObject *arg)
244 : {
245 1114120 : PyObject *return_value = NULL;
246 : int chr;
247 : int _return_value;
248 :
249 1114120 : if (!PyUnicode_Check(arg)) {
250 0 : _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
251 0 : goto exit;
252 : }
253 1114120 : if (PyUnicode_READY(arg)) {
254 0 : goto exit;
255 : }
256 1114120 : if (PyUnicode_GET_LENGTH(arg) != 1) {
257 1 : _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
258 1 : goto exit;
259 : }
260 1114120 : chr = PyUnicode_READ_CHAR(arg, 0);
261 1114120 : _return_value = unicodedata_UCD_combining_impl(self, chr);
262 1114120 : if ((_return_value == -1) && PyErr_Occurred()) {
263 0 : goto exit;
264 : }
265 1114120 : return_value = PyLong_FromLong((long)_return_value);
266 :
267 1114120 : exit:
268 1114120 : 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 1114120 : unicodedata_UCD_mirrored(PyObject *self, PyObject *arg)
288 : {
289 1114120 : PyObject *return_value = NULL;
290 : int chr;
291 : int _return_value;
292 :
293 1114120 : if (!PyUnicode_Check(arg)) {
294 0 : _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
295 0 : goto exit;
296 : }
297 1114120 : if (PyUnicode_READY(arg)) {
298 0 : goto exit;
299 : }
300 1114120 : if (PyUnicode_GET_LENGTH(arg) != 1) {
301 1 : _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
302 1 : goto exit;
303 : }
304 1114120 : chr = PyUnicode_READ_CHAR(arg, 0);
305 1114120 : _return_value = unicodedata_UCD_mirrored_impl(self, chr);
306 1114120 : if ((_return_value == -1) && PyErr_Occurred()) {
307 0 : goto exit;
308 : }
309 1114120 : return_value = PyLong_FromLong((long)_return_value);
310 :
311 1114120 : exit:
312 1114120 : 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 13 : unicodedata_UCD_east_asian_width(PyObject *self, PyObject *arg)
329 : {
330 13 : PyObject *return_value = NULL;
331 : int chr;
332 :
333 13 : if (!PyUnicode_Check(arg)) {
334 2 : _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
335 2 : goto exit;
336 : }
337 11 : if (PyUnicode_READY(arg)) {
338 0 : goto exit;
339 : }
340 11 : if (PyUnicode_GET_LENGTH(arg) != 1) {
341 2 : _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
342 2 : goto exit;
343 : }
344 9 : chr = PyUnicode_READ_CHAR(arg, 0);
345 9 : return_value = unicodedata_UCD_east_asian_width_impl(self, chr);
346 :
347 13 : exit:
348 13 : 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 2233890 : unicodedata_UCD_decomposition(PyObject *self, PyObject *arg)
367 : {
368 2233890 : PyObject *return_value = NULL;
369 : int chr;
370 :
371 2233890 : if (!PyUnicode_Check(arg)) {
372 0 : _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
373 0 : goto exit;
374 : }
375 2233890 : if (PyUnicode_READY(arg)) {
376 0 : goto exit;
377 : }
378 2233890 : if (PyUnicode_GET_LENGTH(arg) != 1) {
379 1 : _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
380 1 : goto exit;
381 : }
382 2233890 : chr = PyUnicode_READ_CHAR(arg, 0);
383 2233890 : return_value = unicodedata_UCD_decomposition_impl(self, chr);
384 :
385 2233890 : exit:
386 2233890 : return return_value;
387 : }
388 :
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 \
398 : {"is_normalized", _PyCFunction_CAST(unicodedata_UCD_is_normalized), METH_FASTCALL, unicodedata_UCD_is_normalized__doc__},
399 :
400 : static PyObject *
401 : unicodedata_UCD_is_normalized_impl(PyObject *self, PyObject *form,
402 : PyObject *input);
403 :
404 : static PyObject *
405 113952 : unicodedata_UCD_is_normalized(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
406 : {
407 113952 : PyObject *return_value = NULL;
408 : PyObject *form;
409 : PyObject *input;
410 :
411 113952 : if (!_PyArg_CheckPositional("is_normalized", nargs, 2, 2)) {
412 0 : goto exit;
413 : }
414 113952 : if (!PyUnicode_Check(args[0])) {
415 0 : _PyArg_BadArgument("is_normalized", "argument 1", "str", args[0]);
416 0 : goto exit;
417 : }
418 113952 : if (PyUnicode_READY(args[0]) == -1) {
419 0 : goto exit;
420 : }
421 113952 : form = args[0];
422 113952 : if (!PyUnicode_Check(args[1])) {
423 0 : _PyArg_BadArgument("is_normalized", "argument 2", "str", args[1]);
424 0 : goto exit;
425 : }
426 113952 : if (PyUnicode_READY(args[1]) == -1) {
427 0 : goto exit;
428 : }
429 113952 : input = args[1];
430 113952 : return_value = unicodedata_UCD_is_normalized_impl(self, form, input);
431 :
432 113952 : exit:
433 113952 : return return_value;
434 : }
435 :
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 \
445 : {"normalize", _PyCFunction_CAST(unicodedata_UCD_normalize), METH_FASTCALL, unicodedata_UCD_normalize__doc__},
446 :
447 : static PyObject *
448 : unicodedata_UCD_normalize_impl(PyObject *self, PyObject *form,
449 : PyObject *input);
450 :
451 : static PyObject *
452 4770480 : unicodedata_UCD_normalize(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
453 : {
454 4770480 : PyObject *return_value = NULL;
455 : PyObject *form;
456 : PyObject *input;
457 :
458 4770480 : if (!_PyArg_CheckPositional("normalize", nargs, 2, 2)) {
459 1 : goto exit;
460 : }
461 4770480 : if (!PyUnicode_Check(args[0])) {
462 0 : _PyArg_BadArgument("normalize", "argument 1", "str", args[0]);
463 0 : goto exit;
464 : }
465 4770480 : if (PyUnicode_READY(args[0]) == -1) {
466 0 : goto exit;
467 : }
468 4770480 : form = args[0];
469 4770480 : if (!PyUnicode_Check(args[1])) {
470 0 : _PyArg_BadArgument("normalize", "argument 2", "str", args[1]);
471 0 : goto exit;
472 : }
473 4770480 : if (PyUnicode_READY(args[1]) == -1) {
474 0 : goto exit;
475 : }
476 4770480 : input = args[1];
477 4770480 : return_value = unicodedata_UCD_normalize_impl(self, form, input);
478 :
479 4770480 : exit:
480 4770480 : return return_value;
481 : }
482 :
483 : PyDoc_STRVAR(unicodedata_UCD_name__doc__,
484 : "name($self, chr, default=<unrepresentable>, /)\n"
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 \
493 : {"name", _PyCFunction_CAST(unicodedata_UCD_name), METH_FASTCALL, unicodedata_UCD_name__doc__},
494 :
495 : static PyObject *
496 : unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value);
497 :
498 : static PyObject *
499 69679 : unicodedata_UCD_name(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
500 : {
501 69679 : PyObject *return_value = NULL;
502 : int chr;
503 69679 : PyObject *default_value = NULL;
504 :
505 69679 : if (!_PyArg_CheckPositional("name", nargs, 1, 2)) {
506 1 : goto exit;
507 : }
508 69678 : if (!PyUnicode_Check(args[0])) {
509 0 : _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
510 0 : goto exit;
511 : }
512 69678 : if (PyUnicode_READY(args[0])) {
513 0 : goto exit;
514 : }
515 69678 : if (PyUnicode_GET_LENGTH(args[0]) != 1) {
516 1 : _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
517 1 : goto exit;
518 : }
519 69677 : chr = PyUnicode_READ_CHAR(args[0], 0);
520 69677 : if (nargs < 2) {
521 4132 : goto skip_optional;
522 : }
523 65545 : default_value = args[1];
524 69677 : skip_optional:
525 69677 : return_value = unicodedata_UCD_name_impl(self, chr, default_value);
526 :
527 69679 : exit:
528 69679 : 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_t name_length);
546 :
547 : static PyObject *
548 56570 : unicodedata_UCD_lookup(PyObject *self, PyObject *arg)
549 : {
550 56570 : PyObject *return_value = NULL;
551 : const char *name;
552 : Py_ssize_t name_length;
553 :
554 56570 : if (!PyArg_Parse(arg, "s#:lookup", &name, &name_length)) {
555 0 : goto exit;
556 : }
557 56570 : return_value = unicodedata_UCD_lookup_impl(self, name, name_length);
558 :
559 56570 : exit:
560 56570 : return return_value;
561 : }
562 : /*[clinic end generated code: output=78d7a7ae57014502 input=a9049054013a1b77]*/
|