Debian Codegraph @

Modules/clinic/unicodedata.c.h

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