blob: 4251db2edc7b96b62d871c1ccc37acfa1dd9a0a7 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(unicodedata_UCD_decimal__doc__,
Serhiy Storchakad322abb2019-09-14 13:31:50 +03006"decimal($self, chr, default=<unrepresentable>, /)\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007"--\n"
8"\n"
9"Converts a Unicode character into its equivalent decimal value.\n"
10"\n"
Serhiy Storchaka63596412015-04-17 21:18:49 +030011"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 Storchaka1009bf12015-04-03 23:53:51 +030014
15#define UNICODEDATA_UCD_DECIMAL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020016 {"decimal", (PyCFunction)(void(*)(void))unicodedata_UCD_decimal, METH_FASTCALL, unicodedata_UCD_decimal__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030017
18static PyObject *
Serhiy Storchaka63596412015-04-17 21:18:49 +030019unicodedata_UCD_decimal_impl(PyObject *self, int chr,
Larry Hastings89964c42015-04-14 18:07:59 -040020 PyObject *default_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030021
22static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020023unicodedata_UCD_decimal(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030024{
25 PyObject *return_value = NULL;
Serhiy Storchaka63596412015-04-17 21:18:49 +030026 int chr;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030027 PyObject *default_value = NULL;
28
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020029 if (!_PyArg_CheckPositional("decimal", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010030 goto exit;
31 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020032 if (!PyUnicode_Check(args[0])) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +030033 _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020034 goto exit;
35 }
36 if (PyUnicode_READY(args[0])) {
37 goto exit;
38 }
39 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +030040 _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020041 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:
Serhiy Storchaka63596412015-04-17 21:18:49 +030049 return_value = unicodedata_UCD_decimal_impl(self, chr, default_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050
51exit:
52 return return_value;
53}
Serhiy Storchaka63596412015-04-17 21:18:49 +030054
55PyDoc_STRVAR(unicodedata_UCD_digit__doc__,
Serhiy Storchakad322abb2019-09-14 13:31:50 +030056"digit($self, chr, default=<unrepresentable>, /)\n"
Serhiy Storchaka63596412015-04-17 21:18:49 +030057"--\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 Storchaka4a934d42018-11-27 11:27:36 +020066 {"digit", (PyCFunction)(void(*)(void))unicodedata_UCD_digit, METH_FASTCALL, unicodedata_UCD_digit__doc__},
Serhiy Storchaka63596412015-04-17 21:18:49 +030067
68static PyObject *
69unicodedata_UCD_digit_impl(PyObject *self, int chr, PyObject *default_value);
70
71static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020072unicodedata_UCD_digit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka63596412015-04-17 21:18:49 +030073{
74 PyObject *return_value = NULL;
75 int chr;
76 PyObject *default_value = NULL;
77
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020078 if (!_PyArg_CheckPositional("digit", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010079 goto exit;
80 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020081 if (!PyUnicode_Check(args[0])) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +030082 _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020083 goto exit;
84 }
85 if (PyUnicode_READY(args[0])) {
86 goto exit;
87 }
88 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +030089 _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020090 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:
Serhiy Storchaka63596412015-04-17 21:18:49 +030098 return_value = unicodedata_UCD_digit_impl(self, chr, default_value);
99
100exit:
101 return return_value;
102}
103
104PyDoc_STRVAR(unicodedata_UCD_numeric__doc__,
Serhiy Storchakad322abb2019-09-14 13:31:50 +0300105"numeric($self, chr, default=<unrepresentable>, /)\n"
Serhiy Storchaka63596412015-04-17 21:18:49 +0300106"--\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 Storchaka4a934d42018-11-27 11:27:36 +0200115 {"numeric", (PyCFunction)(void(*)(void))unicodedata_UCD_numeric, METH_FASTCALL, unicodedata_UCD_numeric__doc__},
Serhiy Storchaka63596412015-04-17 21:18:49 +0300116
117static PyObject *
118unicodedata_UCD_numeric_impl(PyObject *self, int chr,
119 PyObject *default_value);
120
121static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200122unicodedata_UCD_numeric(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka63596412015-04-17 21:18:49 +0300123{
124 PyObject *return_value = NULL;
125 int chr;
126 PyObject *default_value = NULL;
127
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200128 if (!_PyArg_CheckPositional("numeric", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100129 goto exit;
130 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200131 if (!PyUnicode_Check(args[0])) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300132 _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200133 goto exit;
134 }
135 if (PyUnicode_READY(args[0])) {
136 goto exit;
137 }
138 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300139 _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200140 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:
Serhiy Storchaka63596412015-04-17 21:18:49 +0300148 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200172 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300173 _PyArg_BadArgument("category", "argument", "a unicode character", arg);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300174 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300175 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200176 if (PyUnicode_READY(arg)) {
177 goto exit;
178 }
179 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300180 _PyArg_BadArgument("category", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200181 goto exit;
182 }
183 chr = PyUnicode_READ_CHAR(arg, 0);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300184 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200210 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300211 _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300212 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300213 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200214 if (PyUnicode_READY(arg)) {
215 goto exit;
216 }
217 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300218 _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200219 goto exit;
220 }
221 chr = PyUnicode_READ_CHAR(arg, 0);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300222 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200249 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300250 _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300251 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300252 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200253 if (PyUnicode_READY(arg)) {
254 goto exit;
255 }
256 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300257 _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200258 goto exit;
259 }
260 chr = PyUnicode_READ_CHAR(arg, 0);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300261 _return_value = unicodedata_UCD_combining_impl(self, chr);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300262 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka63596412015-04-17 21:18:49 +0300263 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300264 }
Serhiy Storchaka63596412015-04-17 21:18:49 +0300265 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200293 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300294 _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300295 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300296 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200297 if (PyUnicode_READY(arg)) {
298 goto exit;
299 }
300 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300301 _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200302 goto exit;
303 }
304 chr = PyUnicode_READ_CHAR(arg, 0);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300305 _return_value = unicodedata_UCD_mirrored_impl(self, chr);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300306 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka63596412015-04-17 21:18:49 +0300307 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300308 }
Serhiy Storchaka63596412015-04-17 21:18:49 +0300309 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200333 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300334 _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300335 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300336 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200337 if (PyUnicode_READY(arg)) {
338 goto exit;
339 }
340 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300341 _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200342 goto exit;
343 }
344 chr = PyUnicode_READ_CHAR(arg, 0);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300345 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
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200371 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300372 _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300373 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300374 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200375 if (PyUnicode_READY(arg)) {
376 goto exit;
377 }
378 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300379 _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200380 goto exit;
381 }
382 chr = PyUnicode_READ_CHAR(arg, 0);
Serhiy Storchaka63596412015-04-17 21:18:49 +0300383 return_value = unicodedata_UCD_decomposition_impl(self, chr);
384
385exit:
386 return return_value;
387}
388
Max Bélanger2810dd72018-11-04 15:58:24 -0800389PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200398 {"is_normalized", (PyCFunction)(void(*)(void))unicodedata_UCD_is_normalized, METH_FASTCALL, unicodedata_UCD_is_normalized__doc__},
Max Bélanger2810dd72018-11-04 15:58:24 -0800399
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
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200411 if (!_PyArg_CheckPositional("is_normalized", nargs, 2, 2)) {
Max Bélanger2810dd72018-11-04 15:58:24 -0800412 goto exit;
413 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200414 if (!PyUnicode_Check(args[0])) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300415 _PyArg_BadArgument("is_normalized", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200416 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 Storchaka96631dc2019-08-29 18:29:59 +0300423 _PyArg_BadArgument("is_normalized", "argument 2", "str", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200424 goto exit;
425 }
426 if (PyUnicode_READY(args[1]) == -1) {
427 goto exit;
428 }
429 input = args[1];
Max Bélanger2810dd72018-11-04 15:58:24 -0800430 return_value = unicodedata_UCD_is_normalized_impl(self, form, input);
431
432exit:
433 return return_value;
434}
435
Serhiy Storchaka63596412015-04-17 21:18:49 +0300436PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200445 {"normalize", (PyCFunction)(void(*)(void))unicodedata_UCD_normalize, METH_FASTCALL, unicodedata_UCD_normalize__doc__},
Serhiy Storchaka63596412015-04-17 21:18:49 +0300446
447static PyObject *
Max Bélanger2810dd72018-11-04 15:58:24 -0800448unicodedata_UCD_normalize_impl(PyObject *self, PyObject *form,
Serhiy Storchaka63596412015-04-17 21:18:49 +0300449 PyObject *input);
450
451static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200452unicodedata_UCD_normalize(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka63596412015-04-17 21:18:49 +0300453{
454 PyObject *return_value = NULL;
Max Bélanger2810dd72018-11-04 15:58:24 -0800455 PyObject *form;
Serhiy Storchaka63596412015-04-17 21:18:49 +0300456 PyObject *input;
457
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200458 if (!_PyArg_CheckPositional("normalize", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100459 goto exit;
460 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200461 if (!PyUnicode_Check(args[0])) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300462 _PyArg_BadArgument("normalize", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200463 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 Storchaka96631dc2019-08-29 18:29:59 +0300470 _PyArg_BadArgument("normalize", "argument 2", "str", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200471 goto exit;
472 }
473 if (PyUnicode_READY(args[1]) == -1) {
474 goto exit;
475 }
476 input = args[1];
Serhiy Storchaka63596412015-04-17 21:18:49 +0300477 return_value = unicodedata_UCD_normalize_impl(self, form, input);
478
479exit:
480 return return_value;
481}
482
483PyDoc_STRVAR(unicodedata_UCD_name__doc__,
Serhiy Storchakad322abb2019-09-14 13:31:50 +0300484"name($self, chr, default=<unrepresentable>, /)\n"
Serhiy Storchaka63596412015-04-17 21:18:49 +0300485"--\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 Storchaka4a934d42018-11-27 11:27:36 +0200493 {"name", (PyCFunction)(void(*)(void))unicodedata_UCD_name, METH_FASTCALL, unicodedata_UCD_name__doc__},
Serhiy Storchaka63596412015-04-17 21:18:49 +0300494
495static PyObject *
496unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value);
497
498static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200499unicodedata_UCD_name(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka63596412015-04-17 21:18:49 +0300500{
501 PyObject *return_value = NULL;
502 int chr;
503 PyObject *default_value = NULL;
504
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200505 if (!_PyArg_CheckPositional("name", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100506 goto exit;
507 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200508 if (!PyUnicode_Check(args[0])) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300509 _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200510 goto exit;
511 }
512 if (PyUnicode_READY(args[0])) {
513 goto exit;
514 }
515 if (PyUnicode_GET_LENGTH(args[0]) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300516 _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200517 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:
Serhiy Storchaka63596412015-04-17 21:18:49 +0300525 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
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300554 if (!PyArg_Parse(arg, "s#:lookup", &name, &name_length)) {
Serhiy Storchaka63596412015-04-17 21:18:49 +0300555 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300556 }
Serhiy Storchaka63596412015-04-17 21:18:49 +0300557 return_value = unicodedata_UCD_lookup_impl(self, name, name_length);
558
559exit:
560 return return_value;
561}
Serhiy Storchakad322abb2019-09-14 13:31:50 +0300562/*[clinic end generated code: output=10c23477dbe8a202 input=a9049054013a1b77]*/