• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(unicode_title__doc__,
6 "title($self, /)\n"
7 "--\n"
8 "\n"
9 "Return a version of the string where each word is titlecased.\n"
10 "\n"
11 "More specifically, words start with uppercased characters and all remaining\n"
12 "cased characters have lower case.");
13 
14 #define UNICODE_TITLE_METHODDEF    \
15     {"title", (PyCFunction)unicode_title, METH_NOARGS, unicode_title__doc__},
16 
17 static PyObject *
18 unicode_title_impl(PyObject *self);
19 
20 static PyObject *
unicode_title(PyObject * self,PyObject * Py_UNUSED (ignored))21 unicode_title(PyObject *self, PyObject *Py_UNUSED(ignored))
22 {
23     return unicode_title_impl(self);
24 }
25 
26 PyDoc_STRVAR(unicode_capitalize__doc__,
27 "capitalize($self, /)\n"
28 "--\n"
29 "\n"
30 "Return a capitalized version of the string.\n"
31 "\n"
32 "More specifically, make the first character have upper case and the rest lower\n"
33 "case.");
34 
35 #define UNICODE_CAPITALIZE_METHODDEF    \
36     {"capitalize", (PyCFunction)unicode_capitalize, METH_NOARGS, unicode_capitalize__doc__},
37 
38 static PyObject *
39 unicode_capitalize_impl(PyObject *self);
40 
41 static PyObject *
unicode_capitalize(PyObject * self,PyObject * Py_UNUSED (ignored))42 unicode_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored))
43 {
44     return unicode_capitalize_impl(self);
45 }
46 
47 PyDoc_STRVAR(unicode_casefold__doc__,
48 "casefold($self, /)\n"
49 "--\n"
50 "\n"
51 "Return a version of the string suitable for caseless comparisons.");
52 
53 #define UNICODE_CASEFOLD_METHODDEF    \
54     {"casefold", (PyCFunction)unicode_casefold, METH_NOARGS, unicode_casefold__doc__},
55 
56 static PyObject *
57 unicode_casefold_impl(PyObject *self);
58 
59 static PyObject *
unicode_casefold(PyObject * self,PyObject * Py_UNUSED (ignored))60 unicode_casefold(PyObject *self, PyObject *Py_UNUSED(ignored))
61 {
62     return unicode_casefold_impl(self);
63 }
64 
65 PyDoc_STRVAR(unicode_center__doc__,
66 "center($self, width, fillchar=\' \', /)\n"
67 "--\n"
68 "\n"
69 "Return a centered string of length width.\n"
70 "\n"
71 "Padding is done using the specified fill character (default is a space).");
72 
73 #define UNICODE_CENTER_METHODDEF    \
74     {"center", (PyCFunction)(void(*)(void))unicode_center, METH_FASTCALL, unicode_center__doc__},
75 
76 static PyObject *
77 unicode_center_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
78 
79 static PyObject *
unicode_center(PyObject * self,PyObject * const * args,Py_ssize_t nargs)80 unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
81 {
82     PyObject *return_value = NULL;
83     Py_ssize_t width;
84     Py_UCS4 fillchar = ' ';
85 
86     if (!_PyArg_CheckPositional("center", nargs, 1, 2)) {
87         goto exit;
88     }
89     {
90         Py_ssize_t ival = -1;
91         PyObject *iobj = _PyNumber_Index(args[0]);
92         if (iobj != NULL) {
93             ival = PyLong_AsSsize_t(iobj);
94             Py_DECREF(iobj);
95         }
96         if (ival == -1 && PyErr_Occurred()) {
97             goto exit;
98         }
99         width = ival;
100     }
101     if (nargs < 2) {
102         goto skip_optional;
103     }
104     if (!convert_uc(args[1], &fillchar)) {
105         goto exit;
106     }
107 skip_optional:
108     return_value = unicode_center_impl(self, width, fillchar);
109 
110 exit:
111     return return_value;
112 }
113 
114 PyDoc_STRVAR(unicode_encode__doc__,
115 "encode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
116 "--\n"
117 "\n"
118 "Encode the string using the codec registered for encoding.\n"
119 "\n"
120 "  encoding\n"
121 "    The encoding in which to encode the string.\n"
122 "  errors\n"
123 "    The error handling scheme to use for encoding errors.\n"
124 "    The default is \'strict\' meaning that encoding errors raise a\n"
125 "    UnicodeEncodeError.  Other possible values are \'ignore\', \'replace\' and\n"
126 "    \'xmlcharrefreplace\' as well as any other name registered with\n"
127 "    codecs.register_error that can handle UnicodeEncodeErrors.");
128 
129 #define UNICODE_ENCODE_METHODDEF    \
130     {"encode", (PyCFunction)(void(*)(void))unicode_encode, METH_FASTCALL|METH_KEYWORDS, unicode_encode__doc__},
131 
132 static PyObject *
133 unicode_encode_impl(PyObject *self, const char *encoding, const char *errors);
134 
135 static PyObject *
unicode_encode(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)136 unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
137 {
138     PyObject *return_value = NULL;
139     static const char * const _keywords[] = {"encoding", "errors", NULL};
140     static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0};
141     PyObject *argsbuf[2];
142     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
143     const char *encoding = NULL;
144     const char *errors = NULL;
145 
146     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
147     if (!args) {
148         goto exit;
149     }
150     if (!noptargs) {
151         goto skip_optional_pos;
152     }
153     if (args[0]) {
154         if (!PyUnicode_Check(args[0])) {
155             _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]);
156             goto exit;
157         }
158         Py_ssize_t encoding_length;
159         encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
160         if (encoding == NULL) {
161             goto exit;
162         }
163         if (strlen(encoding) != (size_t)encoding_length) {
164             PyErr_SetString(PyExc_ValueError, "embedded null character");
165             goto exit;
166         }
167         if (!--noptargs) {
168             goto skip_optional_pos;
169         }
170     }
171     if (!PyUnicode_Check(args[1])) {
172         _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]);
173         goto exit;
174     }
175     Py_ssize_t errors_length;
176     errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
177     if (errors == NULL) {
178         goto exit;
179     }
180     if (strlen(errors) != (size_t)errors_length) {
181         PyErr_SetString(PyExc_ValueError, "embedded null character");
182         goto exit;
183     }
184 skip_optional_pos:
185     return_value = unicode_encode_impl(self, encoding, errors);
186 
187 exit:
188     return return_value;
189 }
190 
191 PyDoc_STRVAR(unicode_expandtabs__doc__,
192 "expandtabs($self, /, tabsize=8)\n"
193 "--\n"
194 "\n"
195 "Return a copy where all tab characters are expanded using spaces.\n"
196 "\n"
197 "If tabsize is not given, a tab size of 8 characters is assumed.");
198 
199 #define UNICODE_EXPANDTABS_METHODDEF    \
200     {"expandtabs", (PyCFunction)(void(*)(void))unicode_expandtabs, METH_FASTCALL|METH_KEYWORDS, unicode_expandtabs__doc__},
201 
202 static PyObject *
203 unicode_expandtabs_impl(PyObject *self, int tabsize);
204 
205 static PyObject *
unicode_expandtabs(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)206 unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
207 {
208     PyObject *return_value = NULL;
209     static const char * const _keywords[] = {"tabsize", NULL};
210     static _PyArg_Parser _parser = {NULL, _keywords, "expandtabs", 0};
211     PyObject *argsbuf[1];
212     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
213     int tabsize = 8;
214 
215     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
216     if (!args) {
217         goto exit;
218     }
219     if (!noptargs) {
220         goto skip_optional_pos;
221     }
222     tabsize = _PyLong_AsInt(args[0]);
223     if (tabsize == -1 && PyErr_Occurred()) {
224         goto exit;
225     }
226 skip_optional_pos:
227     return_value = unicode_expandtabs_impl(self, tabsize);
228 
229 exit:
230     return return_value;
231 }
232 
233 PyDoc_STRVAR(unicode_isascii__doc__,
234 "isascii($self, /)\n"
235 "--\n"
236 "\n"
237 "Return True if all characters in the string are ASCII, False otherwise.\n"
238 "\n"
239 "ASCII characters have code points in the range U+0000-U+007F.\n"
240 "Empty string is ASCII too.");
241 
242 #define UNICODE_ISASCII_METHODDEF    \
243     {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__},
244 
245 static PyObject *
246 unicode_isascii_impl(PyObject *self);
247 
248 static PyObject *
unicode_isascii(PyObject * self,PyObject * Py_UNUSED (ignored))249 unicode_isascii(PyObject *self, PyObject *Py_UNUSED(ignored))
250 {
251     return unicode_isascii_impl(self);
252 }
253 
254 PyDoc_STRVAR(unicode_islower__doc__,
255 "islower($self, /)\n"
256 "--\n"
257 "\n"
258 "Return True if the string is a lowercase string, False otherwise.\n"
259 "\n"
260 "A string is lowercase if all cased characters in the string are lowercase and\n"
261 "there is at least one cased character in the string.");
262 
263 #define UNICODE_ISLOWER_METHODDEF    \
264     {"islower", (PyCFunction)unicode_islower, METH_NOARGS, unicode_islower__doc__},
265 
266 static PyObject *
267 unicode_islower_impl(PyObject *self);
268 
269 static PyObject *
unicode_islower(PyObject * self,PyObject * Py_UNUSED (ignored))270 unicode_islower(PyObject *self, PyObject *Py_UNUSED(ignored))
271 {
272     return unicode_islower_impl(self);
273 }
274 
275 PyDoc_STRVAR(unicode_isupper__doc__,
276 "isupper($self, /)\n"
277 "--\n"
278 "\n"
279 "Return True if the string is an uppercase string, False otherwise.\n"
280 "\n"
281 "A string is uppercase if all cased characters in the string are uppercase and\n"
282 "there is at least one cased character in the string.");
283 
284 #define UNICODE_ISUPPER_METHODDEF    \
285     {"isupper", (PyCFunction)unicode_isupper, METH_NOARGS, unicode_isupper__doc__},
286 
287 static PyObject *
288 unicode_isupper_impl(PyObject *self);
289 
290 static PyObject *
unicode_isupper(PyObject * self,PyObject * Py_UNUSED (ignored))291 unicode_isupper(PyObject *self, PyObject *Py_UNUSED(ignored))
292 {
293     return unicode_isupper_impl(self);
294 }
295 
296 PyDoc_STRVAR(unicode_istitle__doc__,
297 "istitle($self, /)\n"
298 "--\n"
299 "\n"
300 "Return True if the string is a title-cased string, False otherwise.\n"
301 "\n"
302 "In a title-cased string, upper- and title-case characters may only\n"
303 "follow uncased characters and lowercase characters only cased ones.");
304 
305 #define UNICODE_ISTITLE_METHODDEF    \
306     {"istitle", (PyCFunction)unicode_istitle, METH_NOARGS, unicode_istitle__doc__},
307 
308 static PyObject *
309 unicode_istitle_impl(PyObject *self);
310 
311 static PyObject *
unicode_istitle(PyObject * self,PyObject * Py_UNUSED (ignored))312 unicode_istitle(PyObject *self, PyObject *Py_UNUSED(ignored))
313 {
314     return unicode_istitle_impl(self);
315 }
316 
317 PyDoc_STRVAR(unicode_isspace__doc__,
318 "isspace($self, /)\n"
319 "--\n"
320 "\n"
321 "Return True if the string is a whitespace string, False otherwise.\n"
322 "\n"
323 "A string is whitespace if all characters in the string are whitespace and there\n"
324 "is at least one character in the string.");
325 
326 #define UNICODE_ISSPACE_METHODDEF    \
327     {"isspace", (PyCFunction)unicode_isspace, METH_NOARGS, unicode_isspace__doc__},
328 
329 static PyObject *
330 unicode_isspace_impl(PyObject *self);
331 
332 static PyObject *
unicode_isspace(PyObject * self,PyObject * Py_UNUSED (ignored))333 unicode_isspace(PyObject *self, PyObject *Py_UNUSED(ignored))
334 {
335     return unicode_isspace_impl(self);
336 }
337 
338 PyDoc_STRVAR(unicode_isalpha__doc__,
339 "isalpha($self, /)\n"
340 "--\n"
341 "\n"
342 "Return True if the string is an alphabetic string, False otherwise.\n"
343 "\n"
344 "A string is alphabetic if all characters in the string are alphabetic and there\n"
345 "is at least one character in the string.");
346 
347 #define UNICODE_ISALPHA_METHODDEF    \
348     {"isalpha", (PyCFunction)unicode_isalpha, METH_NOARGS, unicode_isalpha__doc__},
349 
350 static PyObject *
351 unicode_isalpha_impl(PyObject *self);
352 
353 static PyObject *
unicode_isalpha(PyObject * self,PyObject * Py_UNUSED (ignored))354 unicode_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored))
355 {
356     return unicode_isalpha_impl(self);
357 }
358 
359 PyDoc_STRVAR(unicode_isalnum__doc__,
360 "isalnum($self, /)\n"
361 "--\n"
362 "\n"
363 "Return True if the string is an alpha-numeric string, False otherwise.\n"
364 "\n"
365 "A string is alpha-numeric if all characters in the string are alpha-numeric and\n"
366 "there is at least one character in the string.");
367 
368 #define UNICODE_ISALNUM_METHODDEF    \
369     {"isalnum", (PyCFunction)unicode_isalnum, METH_NOARGS, unicode_isalnum__doc__},
370 
371 static PyObject *
372 unicode_isalnum_impl(PyObject *self);
373 
374 static PyObject *
unicode_isalnum(PyObject * self,PyObject * Py_UNUSED (ignored))375 unicode_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored))
376 {
377     return unicode_isalnum_impl(self);
378 }
379 
380 PyDoc_STRVAR(unicode_isdecimal__doc__,
381 "isdecimal($self, /)\n"
382 "--\n"
383 "\n"
384 "Return True if the string is a decimal string, False otherwise.\n"
385 "\n"
386 "A string is a decimal string if all characters in the string are decimal and\n"
387 "there is at least one character in the string.");
388 
389 #define UNICODE_ISDECIMAL_METHODDEF    \
390     {"isdecimal", (PyCFunction)unicode_isdecimal, METH_NOARGS, unicode_isdecimal__doc__},
391 
392 static PyObject *
393 unicode_isdecimal_impl(PyObject *self);
394 
395 static PyObject *
unicode_isdecimal(PyObject * self,PyObject * Py_UNUSED (ignored))396 unicode_isdecimal(PyObject *self, PyObject *Py_UNUSED(ignored))
397 {
398     return unicode_isdecimal_impl(self);
399 }
400 
401 PyDoc_STRVAR(unicode_isdigit__doc__,
402 "isdigit($self, /)\n"
403 "--\n"
404 "\n"
405 "Return True if the string is a digit string, False otherwise.\n"
406 "\n"
407 "A string is a digit string if all characters in the string are digits and there\n"
408 "is at least one character in the string.");
409 
410 #define UNICODE_ISDIGIT_METHODDEF    \
411     {"isdigit", (PyCFunction)unicode_isdigit, METH_NOARGS, unicode_isdigit__doc__},
412 
413 static PyObject *
414 unicode_isdigit_impl(PyObject *self);
415 
416 static PyObject *
unicode_isdigit(PyObject * self,PyObject * Py_UNUSED (ignored))417 unicode_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored))
418 {
419     return unicode_isdigit_impl(self);
420 }
421 
422 PyDoc_STRVAR(unicode_isnumeric__doc__,
423 "isnumeric($self, /)\n"
424 "--\n"
425 "\n"
426 "Return True if the string is a numeric string, False otherwise.\n"
427 "\n"
428 "A string is numeric if all characters in the string are numeric and there is at\n"
429 "least one character in the string.");
430 
431 #define UNICODE_ISNUMERIC_METHODDEF    \
432     {"isnumeric", (PyCFunction)unicode_isnumeric, METH_NOARGS, unicode_isnumeric__doc__},
433 
434 static PyObject *
435 unicode_isnumeric_impl(PyObject *self);
436 
437 static PyObject *
unicode_isnumeric(PyObject * self,PyObject * Py_UNUSED (ignored))438 unicode_isnumeric(PyObject *self, PyObject *Py_UNUSED(ignored))
439 {
440     return unicode_isnumeric_impl(self);
441 }
442 
443 PyDoc_STRVAR(unicode_isidentifier__doc__,
444 "isidentifier($self, /)\n"
445 "--\n"
446 "\n"
447 "Return True if the string is a valid Python identifier, False otherwise.\n"
448 "\n"
449 "Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n"
450 "such as \"def\" or \"class\".");
451 
452 #define UNICODE_ISIDENTIFIER_METHODDEF    \
453     {"isidentifier", (PyCFunction)unicode_isidentifier, METH_NOARGS, unicode_isidentifier__doc__},
454 
455 static PyObject *
456 unicode_isidentifier_impl(PyObject *self);
457 
458 static PyObject *
unicode_isidentifier(PyObject * self,PyObject * Py_UNUSED (ignored))459 unicode_isidentifier(PyObject *self, PyObject *Py_UNUSED(ignored))
460 {
461     return unicode_isidentifier_impl(self);
462 }
463 
464 PyDoc_STRVAR(unicode_isprintable__doc__,
465 "isprintable($self, /)\n"
466 "--\n"
467 "\n"
468 "Return True if the string is printable, False otherwise.\n"
469 "\n"
470 "A string is printable if all of its characters are considered printable in\n"
471 "repr() or if it is empty.");
472 
473 #define UNICODE_ISPRINTABLE_METHODDEF    \
474     {"isprintable", (PyCFunction)unicode_isprintable, METH_NOARGS, unicode_isprintable__doc__},
475 
476 static PyObject *
477 unicode_isprintable_impl(PyObject *self);
478 
479 static PyObject *
unicode_isprintable(PyObject * self,PyObject * Py_UNUSED (ignored))480 unicode_isprintable(PyObject *self, PyObject *Py_UNUSED(ignored))
481 {
482     return unicode_isprintable_impl(self);
483 }
484 
485 PyDoc_STRVAR(unicode_join__doc__,
486 "join($self, iterable, /)\n"
487 "--\n"
488 "\n"
489 "Concatenate any number of strings.\n"
490 "\n"
491 "The string whose method is called is inserted in between each given string.\n"
492 "The result is returned as a new string.\n"
493 "\n"
494 "Example: \'.\'.join([\'ab\', \'pq\', \'rs\']) -> \'ab.pq.rs\'");
495 
496 #define UNICODE_JOIN_METHODDEF    \
497     {"join", (PyCFunction)unicode_join, METH_O, unicode_join__doc__},
498 
499 PyDoc_STRVAR(unicode_ljust__doc__,
500 "ljust($self, width, fillchar=\' \', /)\n"
501 "--\n"
502 "\n"
503 "Return a left-justified string of length width.\n"
504 "\n"
505 "Padding is done using the specified fill character (default is a space).");
506 
507 #define UNICODE_LJUST_METHODDEF    \
508     {"ljust", (PyCFunction)(void(*)(void))unicode_ljust, METH_FASTCALL, unicode_ljust__doc__},
509 
510 static PyObject *
511 unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
512 
513 static PyObject *
unicode_ljust(PyObject * self,PyObject * const * args,Py_ssize_t nargs)514 unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
515 {
516     PyObject *return_value = NULL;
517     Py_ssize_t width;
518     Py_UCS4 fillchar = ' ';
519 
520     if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {
521         goto exit;
522     }
523     {
524         Py_ssize_t ival = -1;
525         PyObject *iobj = _PyNumber_Index(args[0]);
526         if (iobj != NULL) {
527             ival = PyLong_AsSsize_t(iobj);
528             Py_DECREF(iobj);
529         }
530         if (ival == -1 && PyErr_Occurred()) {
531             goto exit;
532         }
533         width = ival;
534     }
535     if (nargs < 2) {
536         goto skip_optional;
537     }
538     if (!convert_uc(args[1], &fillchar)) {
539         goto exit;
540     }
541 skip_optional:
542     return_value = unicode_ljust_impl(self, width, fillchar);
543 
544 exit:
545     return return_value;
546 }
547 
548 PyDoc_STRVAR(unicode_lower__doc__,
549 "lower($self, /)\n"
550 "--\n"
551 "\n"
552 "Return a copy of the string converted to lowercase.");
553 
554 #define UNICODE_LOWER_METHODDEF    \
555     {"lower", (PyCFunction)unicode_lower, METH_NOARGS, unicode_lower__doc__},
556 
557 static PyObject *
558 unicode_lower_impl(PyObject *self);
559 
560 static PyObject *
unicode_lower(PyObject * self,PyObject * Py_UNUSED (ignored))561 unicode_lower(PyObject *self, PyObject *Py_UNUSED(ignored))
562 {
563     return unicode_lower_impl(self);
564 }
565 
566 PyDoc_STRVAR(unicode_strip__doc__,
567 "strip($self, chars=None, /)\n"
568 "--\n"
569 "\n"
570 "Return a copy of the string with leading and trailing whitespace removed.\n"
571 "\n"
572 "If chars is given and not None, remove characters in chars instead.");
573 
574 #define UNICODE_STRIP_METHODDEF    \
575     {"strip", (PyCFunction)(void(*)(void))unicode_strip, METH_FASTCALL, unicode_strip__doc__},
576 
577 static PyObject *
578 unicode_strip_impl(PyObject *self, PyObject *chars);
579 
580 static PyObject *
unicode_strip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)581 unicode_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
582 {
583     PyObject *return_value = NULL;
584     PyObject *chars = Py_None;
585 
586     if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
587         goto exit;
588     }
589     if (nargs < 1) {
590         goto skip_optional;
591     }
592     chars = args[0];
593 skip_optional:
594     return_value = unicode_strip_impl(self, chars);
595 
596 exit:
597     return return_value;
598 }
599 
600 PyDoc_STRVAR(unicode_lstrip__doc__,
601 "lstrip($self, chars=None, /)\n"
602 "--\n"
603 "\n"
604 "Return a copy of the string with leading whitespace removed.\n"
605 "\n"
606 "If chars is given and not None, remove characters in chars instead.");
607 
608 #define UNICODE_LSTRIP_METHODDEF    \
609     {"lstrip", (PyCFunction)(void(*)(void))unicode_lstrip, METH_FASTCALL, unicode_lstrip__doc__},
610 
611 static PyObject *
612 unicode_lstrip_impl(PyObject *self, PyObject *chars);
613 
614 static PyObject *
unicode_lstrip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)615 unicode_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
616 {
617     PyObject *return_value = NULL;
618     PyObject *chars = Py_None;
619 
620     if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
621         goto exit;
622     }
623     if (nargs < 1) {
624         goto skip_optional;
625     }
626     chars = args[0];
627 skip_optional:
628     return_value = unicode_lstrip_impl(self, chars);
629 
630 exit:
631     return return_value;
632 }
633 
634 PyDoc_STRVAR(unicode_rstrip__doc__,
635 "rstrip($self, chars=None, /)\n"
636 "--\n"
637 "\n"
638 "Return a copy of the string with trailing whitespace removed.\n"
639 "\n"
640 "If chars is given and not None, remove characters in chars instead.");
641 
642 #define UNICODE_RSTRIP_METHODDEF    \
643     {"rstrip", (PyCFunction)(void(*)(void))unicode_rstrip, METH_FASTCALL, unicode_rstrip__doc__},
644 
645 static PyObject *
646 unicode_rstrip_impl(PyObject *self, PyObject *chars);
647 
648 static PyObject *
unicode_rstrip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)649 unicode_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
650 {
651     PyObject *return_value = NULL;
652     PyObject *chars = Py_None;
653 
654     if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
655         goto exit;
656     }
657     if (nargs < 1) {
658         goto skip_optional;
659     }
660     chars = args[0];
661 skip_optional:
662     return_value = unicode_rstrip_impl(self, chars);
663 
664 exit:
665     return return_value;
666 }
667 
668 PyDoc_STRVAR(unicode_replace__doc__,
669 "replace($self, old, new, count=-1, /)\n"
670 "--\n"
671 "\n"
672 "Return a copy with all occurrences of substring old replaced by new.\n"
673 "\n"
674 "  count\n"
675 "    Maximum number of occurrences to replace.\n"
676 "    -1 (the default value) means replace all occurrences.\n"
677 "\n"
678 "If the optional argument count is given, only the first count occurrences are\n"
679 "replaced.");
680 
681 #define UNICODE_REPLACE_METHODDEF    \
682     {"replace", (PyCFunction)(void(*)(void))unicode_replace, METH_FASTCALL, unicode_replace__doc__},
683 
684 static PyObject *
685 unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new,
686                      Py_ssize_t count);
687 
688 static PyObject *
unicode_replace(PyObject * self,PyObject * const * args,Py_ssize_t nargs)689 unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
690 {
691     PyObject *return_value = NULL;
692     PyObject *old;
693     PyObject *new;
694     Py_ssize_t count = -1;
695 
696     if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
697         goto exit;
698     }
699     if (!PyUnicode_Check(args[0])) {
700         _PyArg_BadArgument("replace", "argument 1", "str", args[0]);
701         goto exit;
702     }
703     if (PyUnicode_READY(args[0]) == -1) {
704         goto exit;
705     }
706     old = args[0];
707     if (!PyUnicode_Check(args[1])) {
708         _PyArg_BadArgument("replace", "argument 2", "str", args[1]);
709         goto exit;
710     }
711     if (PyUnicode_READY(args[1]) == -1) {
712         goto exit;
713     }
714     new = args[1];
715     if (nargs < 3) {
716         goto skip_optional;
717     }
718     {
719         Py_ssize_t ival = -1;
720         PyObject *iobj = _PyNumber_Index(args[2]);
721         if (iobj != NULL) {
722             ival = PyLong_AsSsize_t(iobj);
723             Py_DECREF(iobj);
724         }
725         if (ival == -1 && PyErr_Occurred()) {
726             goto exit;
727         }
728         count = ival;
729     }
730 skip_optional:
731     return_value = unicode_replace_impl(self, old, new, count);
732 
733 exit:
734     return return_value;
735 }
736 
737 PyDoc_STRVAR(unicode_removeprefix__doc__,
738 "removeprefix($self, prefix, /)\n"
739 "--\n"
740 "\n"
741 "Return a str with the given prefix string removed if present.\n"
742 "\n"
743 "If the string starts with the prefix string, return string[len(prefix):].\n"
744 "Otherwise, return a copy of the original string.");
745 
746 #define UNICODE_REMOVEPREFIX_METHODDEF    \
747     {"removeprefix", (PyCFunction)unicode_removeprefix, METH_O, unicode_removeprefix__doc__},
748 
749 static PyObject *
750 unicode_removeprefix_impl(PyObject *self, PyObject *prefix);
751 
752 static PyObject *
unicode_removeprefix(PyObject * self,PyObject * arg)753 unicode_removeprefix(PyObject *self, PyObject *arg)
754 {
755     PyObject *return_value = NULL;
756     PyObject *prefix;
757 
758     if (!PyUnicode_Check(arg)) {
759         _PyArg_BadArgument("removeprefix", "argument", "str", arg);
760         goto exit;
761     }
762     if (PyUnicode_READY(arg) == -1) {
763         goto exit;
764     }
765     prefix = arg;
766     return_value = unicode_removeprefix_impl(self, prefix);
767 
768 exit:
769     return return_value;
770 }
771 
772 PyDoc_STRVAR(unicode_removesuffix__doc__,
773 "removesuffix($self, suffix, /)\n"
774 "--\n"
775 "\n"
776 "Return a str with the given suffix string removed if present.\n"
777 "\n"
778 "If the string ends with the suffix string and that suffix is not empty,\n"
779 "return string[:-len(suffix)]. Otherwise, return a copy of the original\n"
780 "string.");
781 
782 #define UNICODE_REMOVESUFFIX_METHODDEF    \
783     {"removesuffix", (PyCFunction)unicode_removesuffix, METH_O, unicode_removesuffix__doc__},
784 
785 static PyObject *
786 unicode_removesuffix_impl(PyObject *self, PyObject *suffix);
787 
788 static PyObject *
unicode_removesuffix(PyObject * self,PyObject * arg)789 unicode_removesuffix(PyObject *self, PyObject *arg)
790 {
791     PyObject *return_value = NULL;
792     PyObject *suffix;
793 
794     if (!PyUnicode_Check(arg)) {
795         _PyArg_BadArgument("removesuffix", "argument", "str", arg);
796         goto exit;
797     }
798     if (PyUnicode_READY(arg) == -1) {
799         goto exit;
800     }
801     suffix = arg;
802     return_value = unicode_removesuffix_impl(self, suffix);
803 
804 exit:
805     return return_value;
806 }
807 
808 PyDoc_STRVAR(unicode_rjust__doc__,
809 "rjust($self, width, fillchar=\' \', /)\n"
810 "--\n"
811 "\n"
812 "Return a right-justified string of length width.\n"
813 "\n"
814 "Padding is done using the specified fill character (default is a space).");
815 
816 #define UNICODE_RJUST_METHODDEF    \
817     {"rjust", (PyCFunction)(void(*)(void))unicode_rjust, METH_FASTCALL, unicode_rjust__doc__},
818 
819 static PyObject *
820 unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
821 
822 static PyObject *
unicode_rjust(PyObject * self,PyObject * const * args,Py_ssize_t nargs)823 unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
824 {
825     PyObject *return_value = NULL;
826     Py_ssize_t width;
827     Py_UCS4 fillchar = ' ';
828 
829     if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) {
830         goto exit;
831     }
832     {
833         Py_ssize_t ival = -1;
834         PyObject *iobj = _PyNumber_Index(args[0]);
835         if (iobj != NULL) {
836             ival = PyLong_AsSsize_t(iobj);
837             Py_DECREF(iobj);
838         }
839         if (ival == -1 && PyErr_Occurred()) {
840             goto exit;
841         }
842         width = ival;
843     }
844     if (nargs < 2) {
845         goto skip_optional;
846     }
847     if (!convert_uc(args[1], &fillchar)) {
848         goto exit;
849     }
850 skip_optional:
851     return_value = unicode_rjust_impl(self, width, fillchar);
852 
853 exit:
854     return return_value;
855 }
856 
857 PyDoc_STRVAR(unicode_split__doc__,
858 "split($self, /, sep=None, maxsplit=-1)\n"
859 "--\n"
860 "\n"
861 "Return a list of the words in the string, using sep as the delimiter string.\n"
862 "\n"
863 "  sep\n"
864 "    The delimiter according which to split the string.\n"
865 "    None (the default value) means split according to any whitespace,\n"
866 "    and discard empty strings from the result.\n"
867 "  maxsplit\n"
868 "    Maximum number of splits to do.\n"
869 "    -1 (the default value) means no limit.");
870 
871 #define UNICODE_SPLIT_METHODDEF    \
872     {"split", (PyCFunction)(void(*)(void))unicode_split, METH_FASTCALL|METH_KEYWORDS, unicode_split__doc__},
873 
874 static PyObject *
875 unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
876 
877 static PyObject *
unicode_split(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)878 unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
879 {
880     PyObject *return_value = NULL;
881     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
882     static _PyArg_Parser _parser = {NULL, _keywords, "split", 0};
883     PyObject *argsbuf[2];
884     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
885     PyObject *sep = Py_None;
886     Py_ssize_t maxsplit = -1;
887 
888     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
889     if (!args) {
890         goto exit;
891     }
892     if (!noptargs) {
893         goto skip_optional_pos;
894     }
895     if (args[0]) {
896         sep = args[0];
897         if (!--noptargs) {
898             goto skip_optional_pos;
899         }
900     }
901     {
902         Py_ssize_t ival = -1;
903         PyObject *iobj = _PyNumber_Index(args[1]);
904         if (iobj != NULL) {
905             ival = PyLong_AsSsize_t(iobj);
906             Py_DECREF(iobj);
907         }
908         if (ival == -1 && PyErr_Occurred()) {
909             goto exit;
910         }
911         maxsplit = ival;
912     }
913 skip_optional_pos:
914     return_value = unicode_split_impl(self, sep, maxsplit);
915 
916 exit:
917     return return_value;
918 }
919 
920 PyDoc_STRVAR(unicode_partition__doc__,
921 "partition($self, sep, /)\n"
922 "--\n"
923 "\n"
924 "Partition the string into three parts using the given separator.\n"
925 "\n"
926 "This will search for the separator in the string.  If the separator is found,\n"
927 "returns a 3-tuple containing the part before the separator, the separator\n"
928 "itself, and the part after it.\n"
929 "\n"
930 "If the separator is not found, returns a 3-tuple containing the original string\n"
931 "and two empty strings.");
932 
933 #define UNICODE_PARTITION_METHODDEF    \
934     {"partition", (PyCFunction)unicode_partition, METH_O, unicode_partition__doc__},
935 
936 PyDoc_STRVAR(unicode_rpartition__doc__,
937 "rpartition($self, sep, /)\n"
938 "--\n"
939 "\n"
940 "Partition the string into three parts using the given separator.\n"
941 "\n"
942 "This will search for the separator in the string, starting at the end. If\n"
943 "the separator is found, returns a 3-tuple containing the part before the\n"
944 "separator, the separator itself, and the part after it.\n"
945 "\n"
946 "If the separator is not found, returns a 3-tuple containing two empty strings\n"
947 "and the original string.");
948 
949 #define UNICODE_RPARTITION_METHODDEF    \
950     {"rpartition", (PyCFunction)unicode_rpartition, METH_O, unicode_rpartition__doc__},
951 
952 PyDoc_STRVAR(unicode_rsplit__doc__,
953 "rsplit($self, /, sep=None, maxsplit=-1)\n"
954 "--\n"
955 "\n"
956 "Return a list of the words in the string, using sep as the delimiter string.\n"
957 "\n"
958 "  sep\n"
959 "    The delimiter according which to split the string.\n"
960 "    None (the default value) means split according to any whitespace,\n"
961 "    and discard empty strings from the result.\n"
962 "  maxsplit\n"
963 "    Maximum number of splits to do.\n"
964 "    -1 (the default value) means no limit.\n"
965 "\n"
966 "Splits are done starting at the end of the string and working to the front.");
967 
968 #define UNICODE_RSPLIT_METHODDEF    \
969     {"rsplit", (PyCFunction)(void(*)(void))unicode_rsplit, METH_FASTCALL|METH_KEYWORDS, unicode_rsplit__doc__},
970 
971 static PyObject *
972 unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
973 
974 static PyObject *
unicode_rsplit(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)975 unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
976 {
977     PyObject *return_value = NULL;
978     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
979     static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0};
980     PyObject *argsbuf[2];
981     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
982     PyObject *sep = Py_None;
983     Py_ssize_t maxsplit = -1;
984 
985     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
986     if (!args) {
987         goto exit;
988     }
989     if (!noptargs) {
990         goto skip_optional_pos;
991     }
992     if (args[0]) {
993         sep = args[0];
994         if (!--noptargs) {
995             goto skip_optional_pos;
996         }
997     }
998     {
999         Py_ssize_t ival = -1;
1000         PyObject *iobj = _PyNumber_Index(args[1]);
1001         if (iobj != NULL) {
1002             ival = PyLong_AsSsize_t(iobj);
1003             Py_DECREF(iobj);
1004         }
1005         if (ival == -1 && PyErr_Occurred()) {
1006             goto exit;
1007         }
1008         maxsplit = ival;
1009     }
1010 skip_optional_pos:
1011     return_value = unicode_rsplit_impl(self, sep, maxsplit);
1012 
1013 exit:
1014     return return_value;
1015 }
1016 
1017 PyDoc_STRVAR(unicode_splitlines__doc__,
1018 "splitlines($self, /, keepends=False)\n"
1019 "--\n"
1020 "\n"
1021 "Return a list of the lines in the string, breaking at line boundaries.\n"
1022 "\n"
1023 "Line breaks are not included in the resulting list unless keepends is given and\n"
1024 "true.");
1025 
1026 #define UNICODE_SPLITLINES_METHODDEF    \
1027     {"splitlines", (PyCFunction)(void(*)(void))unicode_splitlines, METH_FASTCALL|METH_KEYWORDS, unicode_splitlines__doc__},
1028 
1029 static PyObject *
1030 unicode_splitlines_impl(PyObject *self, int keepends);
1031 
1032 static PyObject *
unicode_splitlines(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1033 unicode_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1034 {
1035     PyObject *return_value = NULL;
1036     static const char * const _keywords[] = {"keepends", NULL};
1037     static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0};
1038     PyObject *argsbuf[1];
1039     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1040     int keepends = 0;
1041 
1042     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1043     if (!args) {
1044         goto exit;
1045     }
1046     if (!noptargs) {
1047         goto skip_optional_pos;
1048     }
1049     keepends = _PyLong_AsInt(args[0]);
1050     if (keepends == -1 && PyErr_Occurred()) {
1051         goto exit;
1052     }
1053 skip_optional_pos:
1054     return_value = unicode_splitlines_impl(self, keepends);
1055 
1056 exit:
1057     return return_value;
1058 }
1059 
1060 PyDoc_STRVAR(unicode_swapcase__doc__,
1061 "swapcase($self, /)\n"
1062 "--\n"
1063 "\n"
1064 "Convert uppercase characters to lowercase and lowercase characters to uppercase.");
1065 
1066 #define UNICODE_SWAPCASE_METHODDEF    \
1067     {"swapcase", (PyCFunction)unicode_swapcase, METH_NOARGS, unicode_swapcase__doc__},
1068 
1069 static PyObject *
1070 unicode_swapcase_impl(PyObject *self);
1071 
1072 static PyObject *
unicode_swapcase(PyObject * self,PyObject * Py_UNUSED (ignored))1073 unicode_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
1074 {
1075     return unicode_swapcase_impl(self);
1076 }
1077 
1078 PyDoc_STRVAR(unicode_maketrans__doc__,
1079 "maketrans(x, y=<unrepresentable>, z=<unrepresentable>, /)\n"
1080 "--\n"
1081 "\n"
1082 "Return a translation table usable for str.translate().\n"
1083 "\n"
1084 "If there is only one argument, it must be a dictionary mapping Unicode\n"
1085 "ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
1086 "Character keys will be then converted to ordinals.\n"
1087 "If there are two arguments, they must be strings of equal length, and\n"
1088 "in the resulting dictionary, each character in x will be mapped to the\n"
1089 "character at the same position in y. If there is a third argument, it\n"
1090 "must be a string, whose characters will be mapped to None in the result.");
1091 
1092 #define UNICODE_MAKETRANS_METHODDEF    \
1093     {"maketrans", (PyCFunction)(void(*)(void))unicode_maketrans, METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__},
1094 
1095 static PyObject *
1096 unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
1097 
1098 static PyObject *
unicode_maketrans(void * null,PyObject * const * args,Py_ssize_t nargs)1099 unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
1100 {
1101     PyObject *return_value = NULL;
1102     PyObject *x;
1103     PyObject *y = NULL;
1104     PyObject *z = NULL;
1105 
1106     if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) {
1107         goto exit;
1108     }
1109     x = args[0];
1110     if (nargs < 2) {
1111         goto skip_optional;
1112     }
1113     if (!PyUnicode_Check(args[1])) {
1114         _PyArg_BadArgument("maketrans", "argument 2", "str", args[1]);
1115         goto exit;
1116     }
1117     if (PyUnicode_READY(args[1]) == -1) {
1118         goto exit;
1119     }
1120     y = args[1];
1121     if (nargs < 3) {
1122         goto skip_optional;
1123     }
1124     if (!PyUnicode_Check(args[2])) {
1125         _PyArg_BadArgument("maketrans", "argument 3", "str", args[2]);
1126         goto exit;
1127     }
1128     if (PyUnicode_READY(args[2]) == -1) {
1129         goto exit;
1130     }
1131     z = args[2];
1132 skip_optional:
1133     return_value = unicode_maketrans_impl(x, y, z);
1134 
1135 exit:
1136     return return_value;
1137 }
1138 
1139 PyDoc_STRVAR(unicode_translate__doc__,
1140 "translate($self, table, /)\n"
1141 "--\n"
1142 "\n"
1143 "Replace each character in the string using the given translation table.\n"
1144 "\n"
1145 "  table\n"
1146 "    Translation table, which must be a mapping of Unicode ordinals to\n"
1147 "    Unicode ordinals, strings, or None.\n"
1148 "\n"
1149 "The table must implement lookup/indexing via __getitem__, for instance a\n"
1150 "dictionary or list.  If this operation raises LookupError, the character is\n"
1151 "left untouched.  Characters mapped to None are deleted.");
1152 
1153 #define UNICODE_TRANSLATE_METHODDEF    \
1154     {"translate", (PyCFunction)unicode_translate, METH_O, unicode_translate__doc__},
1155 
1156 PyDoc_STRVAR(unicode_upper__doc__,
1157 "upper($self, /)\n"
1158 "--\n"
1159 "\n"
1160 "Return a copy of the string converted to uppercase.");
1161 
1162 #define UNICODE_UPPER_METHODDEF    \
1163     {"upper", (PyCFunction)unicode_upper, METH_NOARGS, unicode_upper__doc__},
1164 
1165 static PyObject *
1166 unicode_upper_impl(PyObject *self);
1167 
1168 static PyObject *
unicode_upper(PyObject * self,PyObject * Py_UNUSED (ignored))1169 unicode_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
1170 {
1171     return unicode_upper_impl(self);
1172 }
1173 
1174 PyDoc_STRVAR(unicode_zfill__doc__,
1175 "zfill($self, width, /)\n"
1176 "--\n"
1177 "\n"
1178 "Pad a numeric string with zeros on the left, to fill a field of the given width.\n"
1179 "\n"
1180 "The string is never truncated.");
1181 
1182 #define UNICODE_ZFILL_METHODDEF    \
1183     {"zfill", (PyCFunction)unicode_zfill, METH_O, unicode_zfill__doc__},
1184 
1185 static PyObject *
1186 unicode_zfill_impl(PyObject *self, Py_ssize_t width);
1187 
1188 static PyObject *
unicode_zfill(PyObject * self,PyObject * arg)1189 unicode_zfill(PyObject *self, PyObject *arg)
1190 {
1191     PyObject *return_value = NULL;
1192     Py_ssize_t width;
1193 
1194     {
1195         Py_ssize_t ival = -1;
1196         PyObject *iobj = _PyNumber_Index(arg);
1197         if (iobj != NULL) {
1198             ival = PyLong_AsSsize_t(iobj);
1199             Py_DECREF(iobj);
1200         }
1201         if (ival == -1 && PyErr_Occurred()) {
1202             goto exit;
1203         }
1204         width = ival;
1205     }
1206     return_value = unicode_zfill_impl(self, width);
1207 
1208 exit:
1209     return return_value;
1210 }
1211 
1212 PyDoc_STRVAR(unicode___format____doc__,
1213 "__format__($self, format_spec, /)\n"
1214 "--\n"
1215 "\n"
1216 "Return a formatted version of the string as described by format_spec.");
1217 
1218 #define UNICODE___FORMAT___METHODDEF    \
1219     {"__format__", (PyCFunction)unicode___format__, METH_O, unicode___format____doc__},
1220 
1221 static PyObject *
1222 unicode___format___impl(PyObject *self, PyObject *format_spec);
1223 
1224 static PyObject *
unicode___format__(PyObject * self,PyObject * arg)1225 unicode___format__(PyObject *self, PyObject *arg)
1226 {
1227     PyObject *return_value = NULL;
1228     PyObject *format_spec;
1229 
1230     if (!PyUnicode_Check(arg)) {
1231         _PyArg_BadArgument("__format__", "argument", "str", arg);
1232         goto exit;
1233     }
1234     if (PyUnicode_READY(arg) == -1) {
1235         goto exit;
1236     }
1237     format_spec = arg;
1238     return_value = unicode___format___impl(self, format_spec);
1239 
1240 exit:
1241     return return_value;
1242 }
1243 
1244 PyDoc_STRVAR(unicode_sizeof__doc__,
1245 "__sizeof__($self, /)\n"
1246 "--\n"
1247 "\n"
1248 "Return the size of the string in memory, in bytes.");
1249 
1250 #define UNICODE_SIZEOF_METHODDEF    \
1251     {"__sizeof__", (PyCFunction)unicode_sizeof, METH_NOARGS, unicode_sizeof__doc__},
1252 
1253 static PyObject *
1254 unicode_sizeof_impl(PyObject *self);
1255 
1256 static PyObject *
unicode_sizeof(PyObject * self,PyObject * Py_UNUSED (ignored))1257 unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
1258 {
1259     return unicode_sizeof_impl(self);
1260 }
1261 
1262 static PyObject *
1263 unicode_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
1264                  const char *errors);
1265 
1266 static PyObject *
unicode_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)1267 unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1268 {
1269     PyObject *return_value = NULL;
1270     static const char * const _keywords[] = {"object", "encoding", "errors", NULL};
1271     static _PyArg_Parser _parser = {NULL, _keywords, "str", 0};
1272     PyObject *argsbuf[3];
1273     PyObject * const *fastargs;
1274     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1275     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
1276     PyObject *x = NULL;
1277     const char *encoding = NULL;
1278     const char *errors = NULL;
1279 
1280     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
1281     if (!fastargs) {
1282         goto exit;
1283     }
1284     if (!noptargs) {
1285         goto skip_optional_pos;
1286     }
1287     if (fastargs[0]) {
1288         x = fastargs[0];
1289         if (!--noptargs) {
1290             goto skip_optional_pos;
1291         }
1292     }
1293     if (fastargs[1]) {
1294         if (!PyUnicode_Check(fastargs[1])) {
1295             _PyArg_BadArgument("str", "argument 'encoding'", "str", fastargs[1]);
1296             goto exit;
1297         }
1298         Py_ssize_t encoding_length;
1299         encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
1300         if (encoding == NULL) {
1301             goto exit;
1302         }
1303         if (strlen(encoding) != (size_t)encoding_length) {
1304             PyErr_SetString(PyExc_ValueError, "embedded null character");
1305             goto exit;
1306         }
1307         if (!--noptargs) {
1308             goto skip_optional_pos;
1309         }
1310     }
1311     if (!PyUnicode_Check(fastargs[2])) {
1312         _PyArg_BadArgument("str", "argument 'errors'", "str", fastargs[2]);
1313         goto exit;
1314     }
1315     Py_ssize_t errors_length;
1316     errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
1317     if (errors == NULL) {
1318         goto exit;
1319     }
1320     if (strlen(errors) != (size_t)errors_length) {
1321         PyErr_SetString(PyExc_ValueError, "embedded null character");
1322         goto exit;
1323     }
1324 skip_optional_pos:
1325     return_value = unicode_new_impl(type, x, encoding, errors);
1326 
1327 exit:
1328     return return_value;
1329 }
1330 /*[clinic end generated code: output=f10cf85d3935b3b7 input=a9049054013a1b77]*/
1331