1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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)(void(*)(void))unicodedata_UCD_decimal, METH_FASTCALL, unicodedata_UCD_decimal__doc__},
17
18static PyObject *
19unicodedata_UCD_decimal_impl(PyObject *self, int chr,
20 PyObject *default_value);
21
22static PyObject *
23unicodedata_UCD_decimal(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
24{
25 PyObject *return_value = NULL;
26 int chr;
27 PyObject *default_value = NULL;
28
29 if (!_PyArg_CheckPositional("decimal", nargs, 1, 2)) {
30 goto exit;
31 }
32 if (!PyUnicode_Check(args[0])) {
33 _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
34 goto exit;
35 }
36 if (PyUnicode_READY(args[0])) {
37 goto exit;
38 }
39 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
40 _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
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];
48skip_optional:
49 return_value = unicodedata_UCD_decimal_impl(self, chr, default_value);
50
51exit:
52 return return_value;
53}
54
55PyDoc_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)(void(*)(void))unicodedata_UCD_digit, METH_FASTCALL, unicodedata_UCD_digit__doc__},
67
68static PyObject *
69unicodedata_UCD_digit_impl(PyObject *self, int chr, PyObject *default_value);
70
71static PyObject *
72unicodedata_UCD_digit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
73{
74 PyObject *return_value = NULL;
75 int chr;
76 PyObject *default_value = NULL;
77
78 if (!_PyArg_CheckPositional("digit", nargs, 1, 2)) {
79 goto exit;
80 }
81 if (!PyUnicode_Check(args[0])) {
82 _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
83 goto exit;
84 }
85 if (PyUnicode_READY(args[0])) {
86 goto exit;
87 }
88 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
89 _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
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];
97skip_optional:
98 return_value = unicodedata_UCD_digit_impl(self, chr, default_value);
99
100exit:
101 return return_value;
102}
103
104PyDoc_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)(void(*)(void))unicodedata_UCD_numeric, METH_FASTCALL, unicodedata_UCD_numeric__doc__},
116
117static PyObject *
118unicodedata_UCD_numeric_impl(PyObject *self, int chr,
119 PyObject *default_value);
120
121static PyObject *
122unicodedata_UCD_numeric(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
123{
124 PyObject *return_value = NULL;
125 int chr;
126 PyObject *default_value = NULL;
127
128 if (!_PyArg_CheckPositional("numeric", nargs, 1, 2)) {
129 goto exit;
130 }
131 if (!PyUnicode_Check(args[0])) {
132 _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
133 goto exit;
134 }
135 if (PyUnicode_READY(args[0])) {
136 goto exit;
137 }
138 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
139 _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
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];
147skip_optional:
148 return_value = unicodedata_UCD_numeric_impl(self, chr, default_value);
149
150exit:
151 return return_value;
152}
153
154PyDoc_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
163static PyObject *
164unicodedata_UCD_category_impl(PyObject *self, int chr);
165
166static PyObject *
167unicodedata_UCD_category(PyObject *self, PyObject *arg)
168{
169 PyObject *return_value = NULL;
170 int chr;
171
172 if (!PyUnicode_Check(arg)) {
173 _PyArg_BadArgument("category", "argument", "a unicode character", arg);
174 goto exit;
175 }
176 if (PyUnicode_READY(arg)) {
177 goto exit;
178 }
179 if (PyUnicode_GET_LENGTH(arg) != 1) {
180 _PyArg_BadArgument("category", "argument", "a unicode character", arg);
181 goto exit;
182 }
183 chr = PyUnicode_READ_CHAR(arg, 0);
184 return_value = unicodedata_UCD_category_impl(self, chr);
185
186exit:
187 return return_value;
188}
189
190PyDoc_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
201static PyObject *
202unicodedata_UCD_bidirectional_impl(PyObject *self, int chr);
203
204static PyObject *
205unicodedata_UCD_bidirectional(PyObject *self, PyObject *arg)
206{
207 PyObject *return_value = NULL;
208 int chr;
209
210 if (!PyUnicode_Check(arg)) {
211 _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
212 goto exit;
213 }
214 if (PyUnicode_READY(arg)) {
215 goto exit;
216 }
217 if (PyUnicode_GET_LENGTH(arg) != 1) {
218 _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
219 goto exit;
220 }
221 chr = PyUnicode_READ_CHAR(arg, 0);
222 return_value = unicodedata_UCD_bidirectional_impl(self, chr);
223
224exit:
225 return return_value;
226}
227
228PyDoc_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
239static int
240unicodedata_UCD_combining_impl(PyObject *self, int chr);
241
242static PyObject *
243unicodedata_UCD_combining(PyObject *self, PyObject *arg)
244{
245 PyObject *return_value = NULL;
246 int chr;
247 int _return_value;
248
249 if (!PyUnicode_Check(arg)) {
250 _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
251 goto exit;
252 }
253 if (PyUnicode_READY(arg)) {
254 goto exit;
255 }
256 if (PyUnicode_GET_LENGTH(arg) != 1) {
257 _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
258 goto exit;
259 }
260 chr = PyUnicode_READ_CHAR(arg, 0);
261 _return_value = unicodedata_UCD_combining_impl(self, chr);
262 if ((_return_value == -1) && PyErr_Occurred()) {
263 goto exit;
264 }
265 return_value = PyLong_FromLong((long)_return_value);
266
267exit:
268 return return_value;
269}
270
271PyDoc_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
283static int
284unicodedata_UCD_mirrored_impl(PyObject *self, int chr);
285
286static PyObject *
287unicodedata_UCD_mirrored(PyObject *self, PyObject *arg)
288{
289 PyObject *return_value = NULL;
290 int chr;
291 int _return_value;
292
293 if (!PyUnicode_Check(arg)) {
294 _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
295 goto exit;
296 }
297 if (PyUnicode_READY(arg)) {
298 goto exit;
299 }
300 if (PyUnicode_GET_LENGTH(arg) != 1) {
301 _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
302 goto exit;
303 }
304 chr = PyUnicode_READ_CHAR(arg, 0);
305 _return_value = unicodedata_UCD_mirrored_impl(self, chr);
306 if ((_return_value == -1) && PyErr_Occurred()) {
307 goto exit;
308 }
309 return_value = PyLong_FromLong((long)_return_value);
310
311exit:
312 return return_value;
313}
314
315PyDoc_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
324static PyObject *
325unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr);
326
327static PyObject *
328unicodedata_UCD_east_asian_width(PyObject *self, PyObject *arg)
329{
330 PyObject *return_value = NULL;
331 int chr;
332
333 if (!PyUnicode_Check(arg)) {
334 _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
335 goto exit;
336 }
337 if (PyUnicode_READY(arg)) {
338 goto exit;
339 }
340 if (PyUnicode_GET_LENGTH(arg) != 1) {
341 _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
342 goto exit;
343 }
344 chr = PyUnicode_READ_CHAR(arg, 0);
345 return_value = unicodedata_UCD_east_asian_width_impl(self, chr);
346
347exit:
348 return return_value;
349}
350
351PyDoc_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
362static PyObject *
363unicodedata_UCD_decomposition_impl(PyObject *self, int chr);
364
365static PyObject *
366unicodedata_UCD_decomposition(PyObject *self, PyObject *arg)
367{
368 PyObject *return_value = NULL;
369 int chr;
370
371 if (!PyUnicode_Check(arg)) {
372 _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
373 goto exit;
374 }
375 if (PyUnicode_READY(arg)) {
376 goto exit;
377 }
378 if (PyUnicode_GET_LENGTH(arg) != 1) {
379 _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
380 goto exit;
381 }
382 chr = PyUnicode_READ_CHAR(arg, 0);
383 return_value = unicodedata_UCD_decomposition_impl(self, chr);
384
385exit:
386 return return_value;
387}
388
389PyDoc_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)(void(*)(void))unicodedata_UCD_is_normalized, METH_FASTCALL, unicodedata_UCD_is_normalized__doc__},
399
400static PyObject *
401unicodedata_UCD_is_normalized_impl(PyObject *self, PyObject *form,
402 PyObject *input);
403
404static PyObject *
405unicodedata_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
411 if (!_PyArg_CheckPositional("is_normalized", nargs, 2, 2)) {
412 goto exit;
413 }
414 if (!PyUnicode_Check(args[0])) {
415 _PyArg_BadArgument("is_normalized", "argument 1", "str", args[0]);
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])) {
423 _PyArg_BadArgument("is_normalized", "argument 2", "str", args[1]);
424 goto exit;
425 }
426 if (PyUnicode_READY(args[1]) == -1) {
427 goto exit;
428 }
429 input = args[1];
430 return_value = unicodedata_UCD_is_normalized_impl(self, form, input);
431
432exit:
433 return return_value;
434}
435
436PyDoc_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)(void(*)(void))unicodedata_UCD_normalize, METH_FASTCALL, unicodedata_UCD_normalize__doc__},
446
447static PyObject *
448unicodedata_UCD_normalize_impl(PyObject *self, PyObject *form,
449 PyObject *input);
450
451static PyObject *
452unicodedata_UCD_normalize(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
453{
454 PyObject *return_value = NULL;
455 PyObject *form;
456 PyObject *input;
457
458 if (!_PyArg_CheckPositional("normalize", nargs, 2, 2)) {
459 goto exit;
460 }
461 if (!PyUnicode_Check(args[0])) {
462 _PyArg_BadArgument("normalize", "argument 1", "str", args[0]);
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])) {
470 _PyArg_BadArgument("normalize", "argument 2", "str", args[1]);
471 goto exit;
472 }
473 if (PyUnicode_READY(args[1]) == -1) {
474 goto exit;
475 }
476 input = args[1];
477 return_value = unicodedata_UCD_normalize_impl(self, form, input);
478
479exit:
480 return return_value;
481}
482
483PyDoc_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)(void(*)(void))unicodedata_UCD_name, METH_FASTCALL, unicodedata_UCD_name__doc__},
494
495static PyObject *
496unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value);
497
498static PyObject *
499unicodedata_UCD_name(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
500{
501 PyObject *return_value = NULL;
502 int chr;
503 PyObject *default_value = NULL;
504
505 if (!_PyArg_CheckPositional("name", nargs, 1, 2)) {
506 goto exit;
507 }
508 if (!PyUnicode_Check(args[0])) {
509 _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
510 goto exit;
511 }
512 if (PyUnicode_READY(args[0])) {
513 goto exit;
514 }
515 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
516 _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
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];
524skip_optional:
525 return_value = unicodedata_UCD_name_impl(self, chr, default_value);
526
527exit:
528 return return_value;
529}
530
531PyDoc_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
543static PyObject *
544unicodedata_UCD_lookup_impl(PyObject *self, const char *name,
545 Py_ssize_clean_t name_length);
546
547static PyObject *
548unicodedata_UCD_lookup(PyObject *self, PyObject *arg)
549{
550 PyObject *return_value = NULL;
551 const char *name;
552 Py_ssize_clean_t name_length;
553
554 if (!PyArg_Parse(arg, "s#:lookup", &name, &name_length)) {
555 goto exit;
556 }
557 return_value = unicodedata_UCD_lookup_impl(self, name, name_length);
558
559exit:
560 return return_value;
561}
562/*[clinic end generated code: output=10c23477dbe8a202 input=a9049054013a1b77]*/
563