• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_abstract.h"      // _PyNumber_Index()
10 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
11 
12 PyDoc_STRVAR(EncodingMap_size__doc__,
13 "size($self, /)\n"
14 "--\n"
15 "\n"
16 "Return the size (in bytes) of this object.");
17 
18 #define ENCODINGMAP_SIZE_METHODDEF    \
19     {"size", (PyCFunction)EncodingMap_size, METH_NOARGS, EncodingMap_size__doc__},
20 
21 static PyObject *
22 EncodingMap_size_impl(struct encoding_map *self);
23 
24 static PyObject *
EncodingMap_size(struct encoding_map * self,PyObject * Py_UNUSED (ignored))25 EncodingMap_size(struct encoding_map *self, PyObject *Py_UNUSED(ignored))
26 {
27     return EncodingMap_size_impl(self);
28 }
29 
30 PyDoc_STRVAR(unicode_title__doc__,
31 "title($self, /)\n"
32 "--\n"
33 "\n"
34 "Return a version of the string where each word is titlecased.\n"
35 "\n"
36 "More specifically, words start with uppercased characters and all remaining\n"
37 "cased characters have lower case.");
38 
39 #define UNICODE_TITLE_METHODDEF    \
40     {"title", (PyCFunction)unicode_title, METH_NOARGS, unicode_title__doc__},
41 
42 static PyObject *
43 unicode_title_impl(PyObject *self);
44 
45 static PyObject *
unicode_title(PyObject * self,PyObject * Py_UNUSED (ignored))46 unicode_title(PyObject *self, PyObject *Py_UNUSED(ignored))
47 {
48     return unicode_title_impl(self);
49 }
50 
51 PyDoc_STRVAR(unicode_capitalize__doc__,
52 "capitalize($self, /)\n"
53 "--\n"
54 "\n"
55 "Return a capitalized version of the string.\n"
56 "\n"
57 "More specifically, make the first character have upper case and the rest lower\n"
58 "case.");
59 
60 #define UNICODE_CAPITALIZE_METHODDEF    \
61     {"capitalize", (PyCFunction)unicode_capitalize, METH_NOARGS, unicode_capitalize__doc__},
62 
63 static PyObject *
64 unicode_capitalize_impl(PyObject *self);
65 
66 static PyObject *
unicode_capitalize(PyObject * self,PyObject * Py_UNUSED (ignored))67 unicode_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored))
68 {
69     return unicode_capitalize_impl(self);
70 }
71 
72 PyDoc_STRVAR(unicode_casefold__doc__,
73 "casefold($self, /)\n"
74 "--\n"
75 "\n"
76 "Return a version of the string suitable for caseless comparisons.");
77 
78 #define UNICODE_CASEFOLD_METHODDEF    \
79     {"casefold", (PyCFunction)unicode_casefold, METH_NOARGS, unicode_casefold__doc__},
80 
81 static PyObject *
82 unicode_casefold_impl(PyObject *self);
83 
84 static PyObject *
unicode_casefold(PyObject * self,PyObject * Py_UNUSED (ignored))85 unicode_casefold(PyObject *self, PyObject *Py_UNUSED(ignored))
86 {
87     return unicode_casefold_impl(self);
88 }
89 
90 PyDoc_STRVAR(unicode_center__doc__,
91 "center($self, width, fillchar=\' \', /)\n"
92 "--\n"
93 "\n"
94 "Return a centered string of length width.\n"
95 "\n"
96 "Padding is done using the specified fill character (default is a space).");
97 
98 #define UNICODE_CENTER_METHODDEF    \
99     {"center", _PyCFunction_CAST(unicode_center), METH_FASTCALL, unicode_center__doc__},
100 
101 static PyObject *
102 unicode_center_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
103 
104 static PyObject *
unicode_center(PyObject * self,PyObject * const * args,Py_ssize_t nargs)105 unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
106 {
107     PyObject *return_value = NULL;
108     Py_ssize_t width;
109     Py_UCS4 fillchar = ' ';
110 
111     if (!_PyArg_CheckPositional("center", nargs, 1, 2)) {
112         goto exit;
113     }
114     {
115         Py_ssize_t ival = -1;
116         PyObject *iobj = _PyNumber_Index(args[0]);
117         if (iobj != NULL) {
118             ival = PyLong_AsSsize_t(iobj);
119             Py_DECREF(iobj);
120         }
121         if (ival == -1 && PyErr_Occurred()) {
122             goto exit;
123         }
124         width = ival;
125     }
126     if (nargs < 2) {
127         goto skip_optional;
128     }
129     if (!convert_uc(args[1], &fillchar)) {
130         goto exit;
131     }
132 skip_optional:
133     return_value = unicode_center_impl(self, width, fillchar);
134 
135 exit:
136     return return_value;
137 }
138 
139 PyDoc_STRVAR(unicode_count__doc__,
140 "count($self, sub[, start[, end]], /)\n"
141 "--\n"
142 "\n"
143 "Return the number of non-overlapping occurrences of substring sub in string S[start:end].\n"
144 "\n"
145 "Optional arguments start and end are interpreted as in slice notation.");
146 
147 #define UNICODE_COUNT_METHODDEF    \
148     {"count", _PyCFunction_CAST(unicode_count), METH_FASTCALL, unicode_count__doc__},
149 
150 static Py_ssize_t
151 unicode_count_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
152                    Py_ssize_t end);
153 
154 static PyObject *
unicode_count(PyObject * str,PyObject * const * args,Py_ssize_t nargs)155 unicode_count(PyObject *str, PyObject *const *args, Py_ssize_t nargs)
156 {
157     PyObject *return_value = NULL;
158     PyObject *substr;
159     Py_ssize_t start = 0;
160     Py_ssize_t end = PY_SSIZE_T_MAX;
161     Py_ssize_t _return_value;
162 
163     if (!_PyArg_CheckPositional("count", nargs, 1, 3)) {
164         goto exit;
165     }
166     if (!PyUnicode_Check(args[0])) {
167         _PyArg_BadArgument("count", "argument 1", "str", args[0]);
168         goto exit;
169     }
170     substr = args[0];
171     if (nargs < 2) {
172         goto skip_optional;
173     }
174     if (!_PyEval_SliceIndex(args[1], &start)) {
175         goto exit;
176     }
177     if (nargs < 3) {
178         goto skip_optional;
179     }
180     if (!_PyEval_SliceIndex(args[2], &end)) {
181         goto exit;
182     }
183 skip_optional:
184     _return_value = unicode_count_impl(str, substr, start, end);
185     if ((_return_value == -1) && PyErr_Occurred()) {
186         goto exit;
187     }
188     return_value = PyLong_FromSsize_t(_return_value);
189 
190 exit:
191     return return_value;
192 }
193 
194 PyDoc_STRVAR(unicode_encode__doc__,
195 "encode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
196 "--\n"
197 "\n"
198 "Encode the string using the codec registered for encoding.\n"
199 "\n"
200 "  encoding\n"
201 "    The encoding in which to encode the string.\n"
202 "  errors\n"
203 "    The error handling scheme to use for encoding errors.\n"
204 "    The default is \'strict\' meaning that encoding errors raise a\n"
205 "    UnicodeEncodeError.  Other possible values are \'ignore\', \'replace\' and\n"
206 "    \'xmlcharrefreplace\' as well as any other name registered with\n"
207 "    codecs.register_error that can handle UnicodeEncodeErrors.");
208 
209 #define UNICODE_ENCODE_METHODDEF    \
210     {"encode", _PyCFunction_CAST(unicode_encode), METH_FASTCALL|METH_KEYWORDS, unicode_encode__doc__},
211 
212 static PyObject *
213 unicode_encode_impl(PyObject *self, const char *encoding, const char *errors);
214 
215 static PyObject *
unicode_encode(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)216 unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
217 {
218     PyObject *return_value = NULL;
219     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
220 
221     #define NUM_KEYWORDS 2
222     static struct {
223         PyGC_Head _this_is_not_used;
224         PyObject_VAR_HEAD
225         PyObject *ob_item[NUM_KEYWORDS];
226     } _kwtuple = {
227         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
228         .ob_item = { &_Py_ID(encoding), &_Py_ID(errors), },
229     };
230     #undef NUM_KEYWORDS
231     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
232 
233     #else  // !Py_BUILD_CORE
234     #  define KWTUPLE NULL
235     #endif  // !Py_BUILD_CORE
236 
237     static const char * const _keywords[] = {"encoding", "errors", NULL};
238     static _PyArg_Parser _parser = {
239         .keywords = _keywords,
240         .fname = "encode",
241         .kwtuple = KWTUPLE,
242     };
243     #undef KWTUPLE
244     PyObject *argsbuf[2];
245     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
246     const char *encoding = NULL;
247     const char *errors = NULL;
248 
249     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
250     if (!args) {
251         goto exit;
252     }
253     if (!noptargs) {
254         goto skip_optional_pos;
255     }
256     if (args[0]) {
257         if (!PyUnicode_Check(args[0])) {
258             _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]);
259             goto exit;
260         }
261         Py_ssize_t encoding_length;
262         encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
263         if (encoding == NULL) {
264             goto exit;
265         }
266         if (strlen(encoding) != (size_t)encoding_length) {
267             PyErr_SetString(PyExc_ValueError, "embedded null character");
268             goto exit;
269         }
270         if (!--noptargs) {
271             goto skip_optional_pos;
272         }
273     }
274     if (!PyUnicode_Check(args[1])) {
275         _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]);
276         goto exit;
277     }
278     Py_ssize_t errors_length;
279     errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
280     if (errors == NULL) {
281         goto exit;
282     }
283     if (strlen(errors) != (size_t)errors_length) {
284         PyErr_SetString(PyExc_ValueError, "embedded null character");
285         goto exit;
286     }
287 skip_optional_pos:
288     return_value = unicode_encode_impl(self, encoding, errors);
289 
290 exit:
291     return return_value;
292 }
293 
294 PyDoc_STRVAR(unicode_expandtabs__doc__,
295 "expandtabs($self, /, tabsize=8)\n"
296 "--\n"
297 "\n"
298 "Return a copy where all tab characters are expanded using spaces.\n"
299 "\n"
300 "If tabsize is not given, a tab size of 8 characters is assumed.");
301 
302 #define UNICODE_EXPANDTABS_METHODDEF    \
303     {"expandtabs", _PyCFunction_CAST(unicode_expandtabs), METH_FASTCALL|METH_KEYWORDS, unicode_expandtabs__doc__},
304 
305 static PyObject *
306 unicode_expandtabs_impl(PyObject *self, int tabsize);
307 
308 static PyObject *
unicode_expandtabs(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)309 unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
310 {
311     PyObject *return_value = NULL;
312     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
313 
314     #define NUM_KEYWORDS 1
315     static struct {
316         PyGC_Head _this_is_not_used;
317         PyObject_VAR_HEAD
318         PyObject *ob_item[NUM_KEYWORDS];
319     } _kwtuple = {
320         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
321         .ob_item = { &_Py_ID(tabsize), },
322     };
323     #undef NUM_KEYWORDS
324     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
325 
326     #else  // !Py_BUILD_CORE
327     #  define KWTUPLE NULL
328     #endif  // !Py_BUILD_CORE
329 
330     static const char * const _keywords[] = {"tabsize", NULL};
331     static _PyArg_Parser _parser = {
332         .keywords = _keywords,
333         .fname = "expandtabs",
334         .kwtuple = KWTUPLE,
335     };
336     #undef KWTUPLE
337     PyObject *argsbuf[1];
338     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
339     int tabsize = 8;
340 
341     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
342     if (!args) {
343         goto exit;
344     }
345     if (!noptargs) {
346         goto skip_optional_pos;
347     }
348     tabsize = PyLong_AsInt(args[0]);
349     if (tabsize == -1 && PyErr_Occurred()) {
350         goto exit;
351     }
352 skip_optional_pos:
353     return_value = unicode_expandtabs_impl(self, tabsize);
354 
355 exit:
356     return return_value;
357 }
358 
359 PyDoc_STRVAR(unicode_find__doc__,
360 "find($self, sub[, start[, end]], /)\n"
361 "--\n"
362 "\n"
363 "Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].\n"
364 "\n"
365 "Optional arguments start and end are interpreted as in slice notation.\n"
366 "Return -1 on failure.");
367 
368 #define UNICODE_FIND_METHODDEF    \
369     {"find", _PyCFunction_CAST(unicode_find), METH_FASTCALL, unicode_find__doc__},
370 
371 static Py_ssize_t
372 unicode_find_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
373                   Py_ssize_t end);
374 
375 static PyObject *
unicode_find(PyObject * str,PyObject * const * args,Py_ssize_t nargs)376 unicode_find(PyObject *str, PyObject *const *args, Py_ssize_t nargs)
377 {
378     PyObject *return_value = NULL;
379     PyObject *substr;
380     Py_ssize_t start = 0;
381     Py_ssize_t end = PY_SSIZE_T_MAX;
382     Py_ssize_t _return_value;
383 
384     if (!_PyArg_CheckPositional("find", nargs, 1, 3)) {
385         goto exit;
386     }
387     if (!PyUnicode_Check(args[0])) {
388         _PyArg_BadArgument("find", "argument 1", "str", args[0]);
389         goto exit;
390     }
391     substr = args[0];
392     if (nargs < 2) {
393         goto skip_optional;
394     }
395     if (!_PyEval_SliceIndex(args[1], &start)) {
396         goto exit;
397     }
398     if (nargs < 3) {
399         goto skip_optional;
400     }
401     if (!_PyEval_SliceIndex(args[2], &end)) {
402         goto exit;
403     }
404 skip_optional:
405     _return_value = unicode_find_impl(str, substr, start, end);
406     if ((_return_value == -1) && PyErr_Occurred()) {
407         goto exit;
408     }
409     return_value = PyLong_FromSsize_t(_return_value);
410 
411 exit:
412     return return_value;
413 }
414 
415 PyDoc_STRVAR(unicode_index__doc__,
416 "index($self, sub[, start[, end]], /)\n"
417 "--\n"
418 "\n"
419 "Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].\n"
420 "\n"
421 "Optional arguments start and end are interpreted as in slice notation.\n"
422 "Raises ValueError when the substring is not found.");
423 
424 #define UNICODE_INDEX_METHODDEF    \
425     {"index", _PyCFunction_CAST(unicode_index), METH_FASTCALL, unicode_index__doc__},
426 
427 static Py_ssize_t
428 unicode_index_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
429                    Py_ssize_t end);
430 
431 static PyObject *
unicode_index(PyObject * str,PyObject * const * args,Py_ssize_t nargs)432 unicode_index(PyObject *str, PyObject *const *args, Py_ssize_t nargs)
433 {
434     PyObject *return_value = NULL;
435     PyObject *substr;
436     Py_ssize_t start = 0;
437     Py_ssize_t end = PY_SSIZE_T_MAX;
438     Py_ssize_t _return_value;
439 
440     if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
441         goto exit;
442     }
443     if (!PyUnicode_Check(args[0])) {
444         _PyArg_BadArgument("index", "argument 1", "str", args[0]);
445         goto exit;
446     }
447     substr = args[0];
448     if (nargs < 2) {
449         goto skip_optional;
450     }
451     if (!_PyEval_SliceIndex(args[1], &start)) {
452         goto exit;
453     }
454     if (nargs < 3) {
455         goto skip_optional;
456     }
457     if (!_PyEval_SliceIndex(args[2], &end)) {
458         goto exit;
459     }
460 skip_optional:
461     _return_value = unicode_index_impl(str, substr, start, end);
462     if ((_return_value == -1) && PyErr_Occurred()) {
463         goto exit;
464     }
465     return_value = PyLong_FromSsize_t(_return_value);
466 
467 exit:
468     return return_value;
469 }
470 
471 PyDoc_STRVAR(unicode_isascii__doc__,
472 "isascii($self, /)\n"
473 "--\n"
474 "\n"
475 "Return True if all characters in the string are ASCII, False otherwise.\n"
476 "\n"
477 "ASCII characters have code points in the range U+0000-U+007F.\n"
478 "Empty string is ASCII too.");
479 
480 #define UNICODE_ISASCII_METHODDEF    \
481     {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__},
482 
483 static PyObject *
484 unicode_isascii_impl(PyObject *self);
485 
486 static PyObject *
unicode_isascii(PyObject * self,PyObject * Py_UNUSED (ignored))487 unicode_isascii(PyObject *self, PyObject *Py_UNUSED(ignored))
488 {
489     return unicode_isascii_impl(self);
490 }
491 
492 PyDoc_STRVAR(unicode_islower__doc__,
493 "islower($self, /)\n"
494 "--\n"
495 "\n"
496 "Return True if the string is a lowercase string, False otherwise.\n"
497 "\n"
498 "A string is lowercase if all cased characters in the string are lowercase and\n"
499 "there is at least one cased character in the string.");
500 
501 #define UNICODE_ISLOWER_METHODDEF    \
502     {"islower", (PyCFunction)unicode_islower, METH_NOARGS, unicode_islower__doc__},
503 
504 static PyObject *
505 unicode_islower_impl(PyObject *self);
506 
507 static PyObject *
unicode_islower(PyObject * self,PyObject * Py_UNUSED (ignored))508 unicode_islower(PyObject *self, PyObject *Py_UNUSED(ignored))
509 {
510     return unicode_islower_impl(self);
511 }
512 
513 PyDoc_STRVAR(unicode_isupper__doc__,
514 "isupper($self, /)\n"
515 "--\n"
516 "\n"
517 "Return True if the string is an uppercase string, False otherwise.\n"
518 "\n"
519 "A string is uppercase if all cased characters in the string are uppercase and\n"
520 "there is at least one cased character in the string.");
521 
522 #define UNICODE_ISUPPER_METHODDEF    \
523     {"isupper", (PyCFunction)unicode_isupper, METH_NOARGS, unicode_isupper__doc__},
524 
525 static PyObject *
526 unicode_isupper_impl(PyObject *self);
527 
528 static PyObject *
unicode_isupper(PyObject * self,PyObject * Py_UNUSED (ignored))529 unicode_isupper(PyObject *self, PyObject *Py_UNUSED(ignored))
530 {
531     return unicode_isupper_impl(self);
532 }
533 
534 PyDoc_STRVAR(unicode_istitle__doc__,
535 "istitle($self, /)\n"
536 "--\n"
537 "\n"
538 "Return True if the string is a title-cased string, False otherwise.\n"
539 "\n"
540 "In a title-cased string, upper- and title-case characters may only\n"
541 "follow uncased characters and lowercase characters only cased ones.");
542 
543 #define UNICODE_ISTITLE_METHODDEF    \
544     {"istitle", (PyCFunction)unicode_istitle, METH_NOARGS, unicode_istitle__doc__},
545 
546 static PyObject *
547 unicode_istitle_impl(PyObject *self);
548 
549 static PyObject *
unicode_istitle(PyObject * self,PyObject * Py_UNUSED (ignored))550 unicode_istitle(PyObject *self, PyObject *Py_UNUSED(ignored))
551 {
552     return unicode_istitle_impl(self);
553 }
554 
555 PyDoc_STRVAR(unicode_isspace__doc__,
556 "isspace($self, /)\n"
557 "--\n"
558 "\n"
559 "Return True if the string is a whitespace string, False otherwise.\n"
560 "\n"
561 "A string is whitespace if all characters in the string are whitespace and there\n"
562 "is at least one character in the string.");
563 
564 #define UNICODE_ISSPACE_METHODDEF    \
565     {"isspace", (PyCFunction)unicode_isspace, METH_NOARGS, unicode_isspace__doc__},
566 
567 static PyObject *
568 unicode_isspace_impl(PyObject *self);
569 
570 static PyObject *
unicode_isspace(PyObject * self,PyObject * Py_UNUSED (ignored))571 unicode_isspace(PyObject *self, PyObject *Py_UNUSED(ignored))
572 {
573     return unicode_isspace_impl(self);
574 }
575 
576 PyDoc_STRVAR(unicode_isalpha__doc__,
577 "isalpha($self, /)\n"
578 "--\n"
579 "\n"
580 "Return True if the string is an alphabetic string, False otherwise.\n"
581 "\n"
582 "A string is alphabetic if all characters in the string are alphabetic and there\n"
583 "is at least one character in the string.");
584 
585 #define UNICODE_ISALPHA_METHODDEF    \
586     {"isalpha", (PyCFunction)unicode_isalpha, METH_NOARGS, unicode_isalpha__doc__},
587 
588 static PyObject *
589 unicode_isalpha_impl(PyObject *self);
590 
591 static PyObject *
unicode_isalpha(PyObject * self,PyObject * Py_UNUSED (ignored))592 unicode_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored))
593 {
594     return unicode_isalpha_impl(self);
595 }
596 
597 PyDoc_STRVAR(unicode_isalnum__doc__,
598 "isalnum($self, /)\n"
599 "--\n"
600 "\n"
601 "Return True if the string is an alpha-numeric string, False otherwise.\n"
602 "\n"
603 "A string is alpha-numeric if all characters in the string are alpha-numeric and\n"
604 "there is at least one character in the string.");
605 
606 #define UNICODE_ISALNUM_METHODDEF    \
607     {"isalnum", (PyCFunction)unicode_isalnum, METH_NOARGS, unicode_isalnum__doc__},
608 
609 static PyObject *
610 unicode_isalnum_impl(PyObject *self);
611 
612 static PyObject *
unicode_isalnum(PyObject * self,PyObject * Py_UNUSED (ignored))613 unicode_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored))
614 {
615     return unicode_isalnum_impl(self);
616 }
617 
618 PyDoc_STRVAR(unicode_isdecimal__doc__,
619 "isdecimal($self, /)\n"
620 "--\n"
621 "\n"
622 "Return True if the string is a decimal string, False otherwise.\n"
623 "\n"
624 "A string is a decimal string if all characters in the string are decimal and\n"
625 "there is at least one character in the string.");
626 
627 #define UNICODE_ISDECIMAL_METHODDEF    \
628     {"isdecimal", (PyCFunction)unicode_isdecimal, METH_NOARGS, unicode_isdecimal__doc__},
629 
630 static PyObject *
631 unicode_isdecimal_impl(PyObject *self);
632 
633 static PyObject *
unicode_isdecimal(PyObject * self,PyObject * Py_UNUSED (ignored))634 unicode_isdecimal(PyObject *self, PyObject *Py_UNUSED(ignored))
635 {
636     return unicode_isdecimal_impl(self);
637 }
638 
639 PyDoc_STRVAR(unicode_isdigit__doc__,
640 "isdigit($self, /)\n"
641 "--\n"
642 "\n"
643 "Return True if the string is a digit string, False otherwise.\n"
644 "\n"
645 "A string is a digit string if all characters in the string are digits and there\n"
646 "is at least one character in the string.");
647 
648 #define UNICODE_ISDIGIT_METHODDEF    \
649     {"isdigit", (PyCFunction)unicode_isdigit, METH_NOARGS, unicode_isdigit__doc__},
650 
651 static PyObject *
652 unicode_isdigit_impl(PyObject *self);
653 
654 static PyObject *
unicode_isdigit(PyObject * self,PyObject * Py_UNUSED (ignored))655 unicode_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored))
656 {
657     return unicode_isdigit_impl(self);
658 }
659 
660 PyDoc_STRVAR(unicode_isnumeric__doc__,
661 "isnumeric($self, /)\n"
662 "--\n"
663 "\n"
664 "Return True if the string is a numeric string, False otherwise.\n"
665 "\n"
666 "A string is numeric if all characters in the string are numeric and there is at\n"
667 "least one character in the string.");
668 
669 #define UNICODE_ISNUMERIC_METHODDEF    \
670     {"isnumeric", (PyCFunction)unicode_isnumeric, METH_NOARGS, unicode_isnumeric__doc__},
671 
672 static PyObject *
673 unicode_isnumeric_impl(PyObject *self);
674 
675 static PyObject *
unicode_isnumeric(PyObject * self,PyObject * Py_UNUSED (ignored))676 unicode_isnumeric(PyObject *self, PyObject *Py_UNUSED(ignored))
677 {
678     return unicode_isnumeric_impl(self);
679 }
680 
681 PyDoc_STRVAR(unicode_isidentifier__doc__,
682 "isidentifier($self, /)\n"
683 "--\n"
684 "\n"
685 "Return True if the string is a valid Python identifier, False otherwise.\n"
686 "\n"
687 "Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n"
688 "such as \"def\" or \"class\".");
689 
690 #define UNICODE_ISIDENTIFIER_METHODDEF    \
691     {"isidentifier", (PyCFunction)unicode_isidentifier, METH_NOARGS, unicode_isidentifier__doc__},
692 
693 static PyObject *
694 unicode_isidentifier_impl(PyObject *self);
695 
696 static PyObject *
unicode_isidentifier(PyObject * self,PyObject * Py_UNUSED (ignored))697 unicode_isidentifier(PyObject *self, PyObject *Py_UNUSED(ignored))
698 {
699     return unicode_isidentifier_impl(self);
700 }
701 
702 PyDoc_STRVAR(unicode_isprintable__doc__,
703 "isprintable($self, /)\n"
704 "--\n"
705 "\n"
706 "Return True if the string is printable, False otherwise.\n"
707 "\n"
708 "A string is printable if all of its characters are considered printable in\n"
709 "repr() or if it is empty.");
710 
711 #define UNICODE_ISPRINTABLE_METHODDEF    \
712     {"isprintable", (PyCFunction)unicode_isprintable, METH_NOARGS, unicode_isprintable__doc__},
713 
714 static PyObject *
715 unicode_isprintable_impl(PyObject *self);
716 
717 static PyObject *
unicode_isprintable(PyObject * self,PyObject * Py_UNUSED (ignored))718 unicode_isprintable(PyObject *self, PyObject *Py_UNUSED(ignored))
719 {
720     return unicode_isprintable_impl(self);
721 }
722 
723 PyDoc_STRVAR(unicode_join__doc__,
724 "join($self, iterable, /)\n"
725 "--\n"
726 "\n"
727 "Concatenate any number of strings.\n"
728 "\n"
729 "The string whose method is called is inserted in between each given string.\n"
730 "The result is returned as a new string.\n"
731 "\n"
732 "Example: \'.\'.join([\'ab\', \'pq\', \'rs\']) -> \'ab.pq.rs\'");
733 
734 #define UNICODE_JOIN_METHODDEF    \
735     {"join", (PyCFunction)unicode_join, METH_O, unicode_join__doc__},
736 
737 PyDoc_STRVAR(unicode_ljust__doc__,
738 "ljust($self, width, fillchar=\' \', /)\n"
739 "--\n"
740 "\n"
741 "Return a left-justified string of length width.\n"
742 "\n"
743 "Padding is done using the specified fill character (default is a space).");
744 
745 #define UNICODE_LJUST_METHODDEF    \
746     {"ljust", _PyCFunction_CAST(unicode_ljust), METH_FASTCALL, unicode_ljust__doc__},
747 
748 static PyObject *
749 unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
750 
751 static PyObject *
unicode_ljust(PyObject * self,PyObject * const * args,Py_ssize_t nargs)752 unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
753 {
754     PyObject *return_value = NULL;
755     Py_ssize_t width;
756     Py_UCS4 fillchar = ' ';
757 
758     if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {
759         goto exit;
760     }
761     {
762         Py_ssize_t ival = -1;
763         PyObject *iobj = _PyNumber_Index(args[0]);
764         if (iobj != NULL) {
765             ival = PyLong_AsSsize_t(iobj);
766             Py_DECREF(iobj);
767         }
768         if (ival == -1 && PyErr_Occurred()) {
769             goto exit;
770         }
771         width = ival;
772     }
773     if (nargs < 2) {
774         goto skip_optional;
775     }
776     if (!convert_uc(args[1], &fillchar)) {
777         goto exit;
778     }
779 skip_optional:
780     return_value = unicode_ljust_impl(self, width, fillchar);
781 
782 exit:
783     return return_value;
784 }
785 
786 PyDoc_STRVAR(unicode_lower__doc__,
787 "lower($self, /)\n"
788 "--\n"
789 "\n"
790 "Return a copy of the string converted to lowercase.");
791 
792 #define UNICODE_LOWER_METHODDEF    \
793     {"lower", (PyCFunction)unicode_lower, METH_NOARGS, unicode_lower__doc__},
794 
795 static PyObject *
796 unicode_lower_impl(PyObject *self);
797 
798 static PyObject *
unicode_lower(PyObject * self,PyObject * Py_UNUSED (ignored))799 unicode_lower(PyObject *self, PyObject *Py_UNUSED(ignored))
800 {
801     return unicode_lower_impl(self);
802 }
803 
804 PyDoc_STRVAR(unicode_strip__doc__,
805 "strip($self, chars=None, /)\n"
806 "--\n"
807 "\n"
808 "Return a copy of the string with leading and trailing whitespace removed.\n"
809 "\n"
810 "If chars is given and not None, remove characters in chars instead.");
811 
812 #define UNICODE_STRIP_METHODDEF    \
813     {"strip", _PyCFunction_CAST(unicode_strip), METH_FASTCALL, unicode_strip__doc__},
814 
815 static PyObject *
816 unicode_strip_impl(PyObject *self, PyObject *chars);
817 
818 static PyObject *
unicode_strip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)819 unicode_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
820 {
821     PyObject *return_value = NULL;
822     PyObject *chars = Py_None;
823 
824     if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
825         goto exit;
826     }
827     if (nargs < 1) {
828         goto skip_optional;
829     }
830     chars = args[0];
831 skip_optional:
832     return_value = unicode_strip_impl(self, chars);
833 
834 exit:
835     return return_value;
836 }
837 
838 PyDoc_STRVAR(unicode_lstrip__doc__,
839 "lstrip($self, chars=None, /)\n"
840 "--\n"
841 "\n"
842 "Return a copy of the string with leading whitespace removed.\n"
843 "\n"
844 "If chars is given and not None, remove characters in chars instead.");
845 
846 #define UNICODE_LSTRIP_METHODDEF    \
847     {"lstrip", _PyCFunction_CAST(unicode_lstrip), METH_FASTCALL, unicode_lstrip__doc__},
848 
849 static PyObject *
850 unicode_lstrip_impl(PyObject *self, PyObject *chars);
851 
852 static PyObject *
unicode_lstrip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)853 unicode_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
854 {
855     PyObject *return_value = NULL;
856     PyObject *chars = Py_None;
857 
858     if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
859         goto exit;
860     }
861     if (nargs < 1) {
862         goto skip_optional;
863     }
864     chars = args[0];
865 skip_optional:
866     return_value = unicode_lstrip_impl(self, chars);
867 
868 exit:
869     return return_value;
870 }
871 
872 PyDoc_STRVAR(unicode_rstrip__doc__,
873 "rstrip($self, chars=None, /)\n"
874 "--\n"
875 "\n"
876 "Return a copy of the string with trailing whitespace removed.\n"
877 "\n"
878 "If chars is given and not None, remove characters in chars instead.");
879 
880 #define UNICODE_RSTRIP_METHODDEF    \
881     {"rstrip", _PyCFunction_CAST(unicode_rstrip), METH_FASTCALL, unicode_rstrip__doc__},
882 
883 static PyObject *
884 unicode_rstrip_impl(PyObject *self, PyObject *chars);
885 
886 static PyObject *
unicode_rstrip(PyObject * self,PyObject * const * args,Py_ssize_t nargs)887 unicode_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
888 {
889     PyObject *return_value = NULL;
890     PyObject *chars = Py_None;
891 
892     if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
893         goto exit;
894     }
895     if (nargs < 1) {
896         goto skip_optional;
897     }
898     chars = args[0];
899 skip_optional:
900     return_value = unicode_rstrip_impl(self, chars);
901 
902 exit:
903     return return_value;
904 }
905 
906 PyDoc_STRVAR(unicode_replace__doc__,
907 "replace($self, old, new, /, count=-1)\n"
908 "--\n"
909 "\n"
910 "Return a copy with all occurrences of substring old replaced by new.\n"
911 "\n"
912 "  count\n"
913 "    Maximum number of occurrences to replace.\n"
914 "    -1 (the default value) means replace all occurrences.\n"
915 "\n"
916 "If the optional argument count is given, only the first count occurrences are\n"
917 "replaced.");
918 
919 #define UNICODE_REPLACE_METHODDEF    \
920     {"replace", _PyCFunction_CAST(unicode_replace), METH_FASTCALL|METH_KEYWORDS, unicode_replace__doc__},
921 
922 static PyObject *
923 unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new,
924                      Py_ssize_t count);
925 
926 static PyObject *
unicode_replace(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)927 unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
928 {
929     PyObject *return_value = NULL;
930     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
931 
932     #define NUM_KEYWORDS 1
933     static struct {
934         PyGC_Head _this_is_not_used;
935         PyObject_VAR_HEAD
936         PyObject *ob_item[NUM_KEYWORDS];
937     } _kwtuple = {
938         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
939         .ob_item = { &_Py_ID(count), },
940     };
941     #undef NUM_KEYWORDS
942     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
943 
944     #else  // !Py_BUILD_CORE
945     #  define KWTUPLE NULL
946     #endif  // !Py_BUILD_CORE
947 
948     static const char * const _keywords[] = {"", "", "count", NULL};
949     static _PyArg_Parser _parser = {
950         .keywords = _keywords,
951         .fname = "replace",
952         .kwtuple = KWTUPLE,
953     };
954     #undef KWTUPLE
955     PyObject *argsbuf[3];
956     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
957     PyObject *old;
958     PyObject *new;
959     Py_ssize_t count = -1;
960 
961     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
962     if (!args) {
963         goto exit;
964     }
965     if (!PyUnicode_Check(args[0])) {
966         _PyArg_BadArgument("replace", "argument 1", "str", args[0]);
967         goto exit;
968     }
969     old = args[0];
970     if (!PyUnicode_Check(args[1])) {
971         _PyArg_BadArgument("replace", "argument 2", "str", args[1]);
972         goto exit;
973     }
974     new = args[1];
975     if (!noptargs) {
976         goto skip_optional_pos;
977     }
978     {
979         Py_ssize_t ival = -1;
980         PyObject *iobj = _PyNumber_Index(args[2]);
981         if (iobj != NULL) {
982             ival = PyLong_AsSsize_t(iobj);
983             Py_DECREF(iobj);
984         }
985         if (ival == -1 && PyErr_Occurred()) {
986             goto exit;
987         }
988         count = ival;
989     }
990 skip_optional_pos:
991     return_value = unicode_replace_impl(self, old, new, count);
992 
993 exit:
994     return return_value;
995 }
996 
997 PyDoc_STRVAR(unicode_removeprefix__doc__,
998 "removeprefix($self, prefix, /)\n"
999 "--\n"
1000 "\n"
1001 "Return a str with the given prefix string removed if present.\n"
1002 "\n"
1003 "If the string starts with the prefix string, return string[len(prefix):].\n"
1004 "Otherwise, return a copy of the original string.");
1005 
1006 #define UNICODE_REMOVEPREFIX_METHODDEF    \
1007     {"removeprefix", (PyCFunction)unicode_removeprefix, METH_O, unicode_removeprefix__doc__},
1008 
1009 static PyObject *
1010 unicode_removeprefix_impl(PyObject *self, PyObject *prefix);
1011 
1012 static PyObject *
unicode_removeprefix(PyObject * self,PyObject * arg)1013 unicode_removeprefix(PyObject *self, PyObject *arg)
1014 {
1015     PyObject *return_value = NULL;
1016     PyObject *prefix;
1017 
1018     if (!PyUnicode_Check(arg)) {
1019         _PyArg_BadArgument("removeprefix", "argument", "str", arg);
1020         goto exit;
1021     }
1022     prefix = arg;
1023     return_value = unicode_removeprefix_impl(self, prefix);
1024 
1025 exit:
1026     return return_value;
1027 }
1028 
1029 PyDoc_STRVAR(unicode_removesuffix__doc__,
1030 "removesuffix($self, suffix, /)\n"
1031 "--\n"
1032 "\n"
1033 "Return a str with the given suffix string removed if present.\n"
1034 "\n"
1035 "If the string ends with the suffix string and that suffix is not empty,\n"
1036 "return string[:-len(suffix)]. Otherwise, return a copy of the original\n"
1037 "string.");
1038 
1039 #define UNICODE_REMOVESUFFIX_METHODDEF    \
1040     {"removesuffix", (PyCFunction)unicode_removesuffix, METH_O, unicode_removesuffix__doc__},
1041 
1042 static PyObject *
1043 unicode_removesuffix_impl(PyObject *self, PyObject *suffix);
1044 
1045 static PyObject *
unicode_removesuffix(PyObject * self,PyObject * arg)1046 unicode_removesuffix(PyObject *self, PyObject *arg)
1047 {
1048     PyObject *return_value = NULL;
1049     PyObject *suffix;
1050 
1051     if (!PyUnicode_Check(arg)) {
1052         _PyArg_BadArgument("removesuffix", "argument", "str", arg);
1053         goto exit;
1054     }
1055     suffix = arg;
1056     return_value = unicode_removesuffix_impl(self, suffix);
1057 
1058 exit:
1059     return return_value;
1060 }
1061 
1062 PyDoc_STRVAR(unicode_rfind__doc__,
1063 "rfind($self, sub[, start[, end]], /)\n"
1064 "--\n"
1065 "\n"
1066 "Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].\n"
1067 "\n"
1068 "Optional arguments start and end are interpreted as in slice notation.\n"
1069 "Return -1 on failure.");
1070 
1071 #define UNICODE_RFIND_METHODDEF    \
1072     {"rfind", _PyCFunction_CAST(unicode_rfind), METH_FASTCALL, unicode_rfind__doc__},
1073 
1074 static Py_ssize_t
1075 unicode_rfind_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
1076                    Py_ssize_t end);
1077 
1078 static PyObject *
unicode_rfind(PyObject * str,PyObject * const * args,Py_ssize_t nargs)1079 unicode_rfind(PyObject *str, PyObject *const *args, Py_ssize_t nargs)
1080 {
1081     PyObject *return_value = NULL;
1082     PyObject *substr;
1083     Py_ssize_t start = 0;
1084     Py_ssize_t end = PY_SSIZE_T_MAX;
1085     Py_ssize_t _return_value;
1086 
1087     if (!_PyArg_CheckPositional("rfind", nargs, 1, 3)) {
1088         goto exit;
1089     }
1090     if (!PyUnicode_Check(args[0])) {
1091         _PyArg_BadArgument("rfind", "argument 1", "str", args[0]);
1092         goto exit;
1093     }
1094     substr = args[0];
1095     if (nargs < 2) {
1096         goto skip_optional;
1097     }
1098     if (!_PyEval_SliceIndex(args[1], &start)) {
1099         goto exit;
1100     }
1101     if (nargs < 3) {
1102         goto skip_optional;
1103     }
1104     if (!_PyEval_SliceIndex(args[2], &end)) {
1105         goto exit;
1106     }
1107 skip_optional:
1108     _return_value = unicode_rfind_impl(str, substr, start, end);
1109     if ((_return_value == -1) && PyErr_Occurred()) {
1110         goto exit;
1111     }
1112     return_value = PyLong_FromSsize_t(_return_value);
1113 
1114 exit:
1115     return return_value;
1116 }
1117 
1118 PyDoc_STRVAR(unicode_rindex__doc__,
1119 "rindex($self, sub[, start[, end]], /)\n"
1120 "--\n"
1121 "\n"
1122 "Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].\n"
1123 "\n"
1124 "Optional arguments start and end are interpreted as in slice notation.\n"
1125 "Raises ValueError when the substring is not found.");
1126 
1127 #define UNICODE_RINDEX_METHODDEF    \
1128     {"rindex", _PyCFunction_CAST(unicode_rindex), METH_FASTCALL, unicode_rindex__doc__},
1129 
1130 static Py_ssize_t
1131 unicode_rindex_impl(PyObject *str, PyObject *substr, Py_ssize_t start,
1132                     Py_ssize_t end);
1133 
1134 static PyObject *
unicode_rindex(PyObject * str,PyObject * const * args,Py_ssize_t nargs)1135 unicode_rindex(PyObject *str, PyObject *const *args, Py_ssize_t nargs)
1136 {
1137     PyObject *return_value = NULL;
1138     PyObject *substr;
1139     Py_ssize_t start = 0;
1140     Py_ssize_t end = PY_SSIZE_T_MAX;
1141     Py_ssize_t _return_value;
1142 
1143     if (!_PyArg_CheckPositional("rindex", nargs, 1, 3)) {
1144         goto exit;
1145     }
1146     if (!PyUnicode_Check(args[0])) {
1147         _PyArg_BadArgument("rindex", "argument 1", "str", args[0]);
1148         goto exit;
1149     }
1150     substr = args[0];
1151     if (nargs < 2) {
1152         goto skip_optional;
1153     }
1154     if (!_PyEval_SliceIndex(args[1], &start)) {
1155         goto exit;
1156     }
1157     if (nargs < 3) {
1158         goto skip_optional;
1159     }
1160     if (!_PyEval_SliceIndex(args[2], &end)) {
1161         goto exit;
1162     }
1163 skip_optional:
1164     _return_value = unicode_rindex_impl(str, substr, start, end);
1165     if ((_return_value == -1) && PyErr_Occurred()) {
1166         goto exit;
1167     }
1168     return_value = PyLong_FromSsize_t(_return_value);
1169 
1170 exit:
1171     return return_value;
1172 }
1173 
1174 PyDoc_STRVAR(unicode_rjust__doc__,
1175 "rjust($self, width, fillchar=\' \', /)\n"
1176 "--\n"
1177 "\n"
1178 "Return a right-justified string of length width.\n"
1179 "\n"
1180 "Padding is done using the specified fill character (default is a space).");
1181 
1182 #define UNICODE_RJUST_METHODDEF    \
1183     {"rjust", _PyCFunction_CAST(unicode_rjust), METH_FASTCALL, unicode_rjust__doc__},
1184 
1185 static PyObject *
1186 unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
1187 
1188 static PyObject *
unicode_rjust(PyObject * self,PyObject * const * args,Py_ssize_t nargs)1189 unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1190 {
1191     PyObject *return_value = NULL;
1192     Py_ssize_t width;
1193     Py_UCS4 fillchar = ' ';
1194 
1195     if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) {
1196         goto exit;
1197     }
1198     {
1199         Py_ssize_t ival = -1;
1200         PyObject *iobj = _PyNumber_Index(args[0]);
1201         if (iobj != NULL) {
1202             ival = PyLong_AsSsize_t(iobj);
1203             Py_DECREF(iobj);
1204         }
1205         if (ival == -1 && PyErr_Occurred()) {
1206             goto exit;
1207         }
1208         width = ival;
1209     }
1210     if (nargs < 2) {
1211         goto skip_optional;
1212     }
1213     if (!convert_uc(args[1], &fillchar)) {
1214         goto exit;
1215     }
1216 skip_optional:
1217     return_value = unicode_rjust_impl(self, width, fillchar);
1218 
1219 exit:
1220     return return_value;
1221 }
1222 
1223 PyDoc_STRVAR(unicode_split__doc__,
1224 "split($self, /, sep=None, maxsplit=-1)\n"
1225 "--\n"
1226 "\n"
1227 "Return a list of the substrings in the string, using sep as the separator string.\n"
1228 "\n"
1229 "  sep\n"
1230 "    The separator used to split the string.\n"
1231 "\n"
1232 "    When set to None (the default value), will split on any whitespace\n"
1233 "    character (including \\n \\r \\t \\f and spaces) and will discard\n"
1234 "    empty strings from the result.\n"
1235 "  maxsplit\n"
1236 "    Maximum number of splits.\n"
1237 "    -1 (the default value) means no limit.\n"
1238 "\n"
1239 "Splitting starts at the front of the string and works to the end.\n"
1240 "\n"
1241 "Note, str.split() is mainly useful for data that has been intentionally\n"
1242 "delimited.  With natural text that includes punctuation, consider using\n"
1243 "the regular expression module.");
1244 
1245 #define UNICODE_SPLIT_METHODDEF    \
1246     {"split", _PyCFunction_CAST(unicode_split), METH_FASTCALL|METH_KEYWORDS, unicode_split__doc__},
1247 
1248 static PyObject *
1249 unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
1250 
1251 static PyObject *
unicode_split(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1252 unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1253 {
1254     PyObject *return_value = NULL;
1255     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1256 
1257     #define NUM_KEYWORDS 2
1258     static struct {
1259         PyGC_Head _this_is_not_used;
1260         PyObject_VAR_HEAD
1261         PyObject *ob_item[NUM_KEYWORDS];
1262     } _kwtuple = {
1263         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1264         .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
1265     };
1266     #undef NUM_KEYWORDS
1267     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1268 
1269     #else  // !Py_BUILD_CORE
1270     #  define KWTUPLE NULL
1271     #endif  // !Py_BUILD_CORE
1272 
1273     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
1274     static _PyArg_Parser _parser = {
1275         .keywords = _keywords,
1276         .fname = "split",
1277         .kwtuple = KWTUPLE,
1278     };
1279     #undef KWTUPLE
1280     PyObject *argsbuf[2];
1281     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1282     PyObject *sep = Py_None;
1283     Py_ssize_t maxsplit = -1;
1284 
1285     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
1286     if (!args) {
1287         goto exit;
1288     }
1289     if (!noptargs) {
1290         goto skip_optional_pos;
1291     }
1292     if (args[0]) {
1293         sep = args[0];
1294         if (!--noptargs) {
1295             goto skip_optional_pos;
1296         }
1297     }
1298     {
1299         Py_ssize_t ival = -1;
1300         PyObject *iobj = _PyNumber_Index(args[1]);
1301         if (iobj != NULL) {
1302             ival = PyLong_AsSsize_t(iobj);
1303             Py_DECREF(iobj);
1304         }
1305         if (ival == -1 && PyErr_Occurred()) {
1306             goto exit;
1307         }
1308         maxsplit = ival;
1309     }
1310 skip_optional_pos:
1311     return_value = unicode_split_impl(self, sep, maxsplit);
1312 
1313 exit:
1314     return return_value;
1315 }
1316 
1317 PyDoc_STRVAR(unicode_partition__doc__,
1318 "partition($self, sep, /)\n"
1319 "--\n"
1320 "\n"
1321 "Partition the string into three parts using the given separator.\n"
1322 "\n"
1323 "This will search for the separator in the string.  If the separator is found,\n"
1324 "returns a 3-tuple containing the part before the separator, the separator\n"
1325 "itself, and the part after it.\n"
1326 "\n"
1327 "If the separator is not found, returns a 3-tuple containing the original string\n"
1328 "and two empty strings.");
1329 
1330 #define UNICODE_PARTITION_METHODDEF    \
1331     {"partition", (PyCFunction)unicode_partition, METH_O, unicode_partition__doc__},
1332 
1333 PyDoc_STRVAR(unicode_rpartition__doc__,
1334 "rpartition($self, sep, /)\n"
1335 "--\n"
1336 "\n"
1337 "Partition the string into three parts using the given separator.\n"
1338 "\n"
1339 "This will search for the separator in the string, starting at the end. If\n"
1340 "the separator is found, returns a 3-tuple containing the part before the\n"
1341 "separator, the separator itself, and the part after it.\n"
1342 "\n"
1343 "If the separator is not found, returns a 3-tuple containing two empty strings\n"
1344 "and the original string.");
1345 
1346 #define UNICODE_RPARTITION_METHODDEF    \
1347     {"rpartition", (PyCFunction)unicode_rpartition, METH_O, unicode_rpartition__doc__},
1348 
1349 PyDoc_STRVAR(unicode_rsplit__doc__,
1350 "rsplit($self, /, sep=None, maxsplit=-1)\n"
1351 "--\n"
1352 "\n"
1353 "Return a list of the substrings in the string, using sep as the separator string.\n"
1354 "\n"
1355 "  sep\n"
1356 "    The separator used to split the string.\n"
1357 "\n"
1358 "    When set to None (the default value), will split on any whitespace\n"
1359 "    character (including \\n \\r \\t \\f and spaces) and will discard\n"
1360 "    empty strings from the result.\n"
1361 "  maxsplit\n"
1362 "    Maximum number of splits.\n"
1363 "    -1 (the default value) means no limit.\n"
1364 "\n"
1365 "Splitting starts at the end of the string and works to the front.");
1366 
1367 #define UNICODE_RSPLIT_METHODDEF    \
1368     {"rsplit", _PyCFunction_CAST(unicode_rsplit), METH_FASTCALL|METH_KEYWORDS, unicode_rsplit__doc__},
1369 
1370 static PyObject *
1371 unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
1372 
1373 static PyObject *
unicode_rsplit(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1374 unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1375 {
1376     PyObject *return_value = NULL;
1377     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1378 
1379     #define NUM_KEYWORDS 2
1380     static struct {
1381         PyGC_Head _this_is_not_used;
1382         PyObject_VAR_HEAD
1383         PyObject *ob_item[NUM_KEYWORDS];
1384     } _kwtuple = {
1385         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1386         .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
1387     };
1388     #undef NUM_KEYWORDS
1389     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1390 
1391     #else  // !Py_BUILD_CORE
1392     #  define KWTUPLE NULL
1393     #endif  // !Py_BUILD_CORE
1394 
1395     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
1396     static _PyArg_Parser _parser = {
1397         .keywords = _keywords,
1398         .fname = "rsplit",
1399         .kwtuple = KWTUPLE,
1400     };
1401     #undef KWTUPLE
1402     PyObject *argsbuf[2];
1403     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1404     PyObject *sep = Py_None;
1405     Py_ssize_t maxsplit = -1;
1406 
1407     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
1408     if (!args) {
1409         goto exit;
1410     }
1411     if (!noptargs) {
1412         goto skip_optional_pos;
1413     }
1414     if (args[0]) {
1415         sep = args[0];
1416         if (!--noptargs) {
1417             goto skip_optional_pos;
1418         }
1419     }
1420     {
1421         Py_ssize_t ival = -1;
1422         PyObject *iobj = _PyNumber_Index(args[1]);
1423         if (iobj != NULL) {
1424             ival = PyLong_AsSsize_t(iobj);
1425             Py_DECREF(iobj);
1426         }
1427         if (ival == -1 && PyErr_Occurred()) {
1428             goto exit;
1429         }
1430         maxsplit = ival;
1431     }
1432 skip_optional_pos:
1433     return_value = unicode_rsplit_impl(self, sep, maxsplit);
1434 
1435 exit:
1436     return return_value;
1437 }
1438 
1439 PyDoc_STRVAR(unicode_splitlines__doc__,
1440 "splitlines($self, /, keepends=False)\n"
1441 "--\n"
1442 "\n"
1443 "Return a list of the lines in the string, breaking at line boundaries.\n"
1444 "\n"
1445 "Line breaks are not included in the resulting list unless keepends is given and\n"
1446 "true.");
1447 
1448 #define UNICODE_SPLITLINES_METHODDEF    \
1449     {"splitlines", _PyCFunction_CAST(unicode_splitlines), METH_FASTCALL|METH_KEYWORDS, unicode_splitlines__doc__},
1450 
1451 static PyObject *
1452 unicode_splitlines_impl(PyObject *self, int keepends);
1453 
1454 static PyObject *
unicode_splitlines(PyObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1455 unicode_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1456 {
1457     PyObject *return_value = NULL;
1458     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1459 
1460     #define NUM_KEYWORDS 1
1461     static struct {
1462         PyGC_Head _this_is_not_used;
1463         PyObject_VAR_HEAD
1464         PyObject *ob_item[NUM_KEYWORDS];
1465     } _kwtuple = {
1466         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1467         .ob_item = { &_Py_ID(keepends), },
1468     };
1469     #undef NUM_KEYWORDS
1470     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1471 
1472     #else  // !Py_BUILD_CORE
1473     #  define KWTUPLE NULL
1474     #endif  // !Py_BUILD_CORE
1475 
1476     static const char * const _keywords[] = {"keepends", NULL};
1477     static _PyArg_Parser _parser = {
1478         .keywords = _keywords,
1479         .fname = "splitlines",
1480         .kwtuple = KWTUPLE,
1481     };
1482     #undef KWTUPLE
1483     PyObject *argsbuf[1];
1484     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1485     int keepends = 0;
1486 
1487     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1488     if (!args) {
1489         goto exit;
1490     }
1491     if (!noptargs) {
1492         goto skip_optional_pos;
1493     }
1494     keepends = PyObject_IsTrue(args[0]);
1495     if (keepends < 0) {
1496         goto exit;
1497     }
1498 skip_optional_pos:
1499     return_value = unicode_splitlines_impl(self, keepends);
1500 
1501 exit:
1502     return return_value;
1503 }
1504 
1505 PyDoc_STRVAR(unicode_swapcase__doc__,
1506 "swapcase($self, /)\n"
1507 "--\n"
1508 "\n"
1509 "Convert uppercase characters to lowercase and lowercase characters to uppercase.");
1510 
1511 #define UNICODE_SWAPCASE_METHODDEF    \
1512     {"swapcase", (PyCFunction)unicode_swapcase, METH_NOARGS, unicode_swapcase__doc__},
1513 
1514 static PyObject *
1515 unicode_swapcase_impl(PyObject *self);
1516 
1517 static PyObject *
unicode_swapcase(PyObject * self,PyObject * Py_UNUSED (ignored))1518 unicode_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
1519 {
1520     return unicode_swapcase_impl(self);
1521 }
1522 
1523 PyDoc_STRVAR(unicode_maketrans__doc__,
1524 "maketrans(x, y=<unrepresentable>, z=<unrepresentable>, /)\n"
1525 "--\n"
1526 "\n"
1527 "Return a translation table usable for str.translate().\n"
1528 "\n"
1529 "If there is only one argument, it must be a dictionary mapping Unicode\n"
1530 "ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
1531 "Character keys will be then converted to ordinals.\n"
1532 "If there are two arguments, they must be strings of equal length, and\n"
1533 "in the resulting dictionary, each character in x will be mapped to the\n"
1534 "character at the same position in y. If there is a third argument, it\n"
1535 "must be a string, whose characters will be mapped to None in the result.");
1536 
1537 #define UNICODE_MAKETRANS_METHODDEF    \
1538     {"maketrans", _PyCFunction_CAST(unicode_maketrans), METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__},
1539 
1540 static PyObject *
1541 unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
1542 
1543 static PyObject *
unicode_maketrans(void * null,PyObject * const * args,Py_ssize_t nargs)1544 unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
1545 {
1546     PyObject *return_value = NULL;
1547     PyObject *x;
1548     PyObject *y = NULL;
1549     PyObject *z = NULL;
1550 
1551     if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) {
1552         goto exit;
1553     }
1554     x = args[0];
1555     if (nargs < 2) {
1556         goto skip_optional;
1557     }
1558     if (!PyUnicode_Check(args[1])) {
1559         _PyArg_BadArgument("maketrans", "argument 2", "str", args[1]);
1560         goto exit;
1561     }
1562     y = args[1];
1563     if (nargs < 3) {
1564         goto skip_optional;
1565     }
1566     if (!PyUnicode_Check(args[2])) {
1567         _PyArg_BadArgument("maketrans", "argument 3", "str", args[2]);
1568         goto exit;
1569     }
1570     z = args[2];
1571 skip_optional:
1572     return_value = unicode_maketrans_impl(x, y, z);
1573 
1574 exit:
1575     return return_value;
1576 }
1577 
1578 PyDoc_STRVAR(unicode_translate__doc__,
1579 "translate($self, table, /)\n"
1580 "--\n"
1581 "\n"
1582 "Replace each character in the string using the given translation table.\n"
1583 "\n"
1584 "  table\n"
1585 "    Translation table, which must be a mapping of Unicode ordinals to\n"
1586 "    Unicode ordinals, strings, or None.\n"
1587 "\n"
1588 "The table must implement lookup/indexing via __getitem__, for instance a\n"
1589 "dictionary or list.  If this operation raises LookupError, the character is\n"
1590 "left untouched.  Characters mapped to None are deleted.");
1591 
1592 #define UNICODE_TRANSLATE_METHODDEF    \
1593     {"translate", (PyCFunction)unicode_translate, METH_O, unicode_translate__doc__},
1594 
1595 PyDoc_STRVAR(unicode_upper__doc__,
1596 "upper($self, /)\n"
1597 "--\n"
1598 "\n"
1599 "Return a copy of the string converted to uppercase.");
1600 
1601 #define UNICODE_UPPER_METHODDEF    \
1602     {"upper", (PyCFunction)unicode_upper, METH_NOARGS, unicode_upper__doc__},
1603 
1604 static PyObject *
1605 unicode_upper_impl(PyObject *self);
1606 
1607 static PyObject *
unicode_upper(PyObject * self,PyObject * Py_UNUSED (ignored))1608 unicode_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
1609 {
1610     return unicode_upper_impl(self);
1611 }
1612 
1613 PyDoc_STRVAR(unicode_zfill__doc__,
1614 "zfill($self, width, /)\n"
1615 "--\n"
1616 "\n"
1617 "Pad a numeric string with zeros on the left, to fill a field of the given width.\n"
1618 "\n"
1619 "The string is never truncated.");
1620 
1621 #define UNICODE_ZFILL_METHODDEF    \
1622     {"zfill", (PyCFunction)unicode_zfill, METH_O, unicode_zfill__doc__},
1623 
1624 static PyObject *
1625 unicode_zfill_impl(PyObject *self, Py_ssize_t width);
1626 
1627 static PyObject *
unicode_zfill(PyObject * self,PyObject * arg)1628 unicode_zfill(PyObject *self, PyObject *arg)
1629 {
1630     PyObject *return_value = NULL;
1631     Py_ssize_t width;
1632 
1633     {
1634         Py_ssize_t ival = -1;
1635         PyObject *iobj = _PyNumber_Index(arg);
1636         if (iobj != NULL) {
1637             ival = PyLong_AsSsize_t(iobj);
1638             Py_DECREF(iobj);
1639         }
1640         if (ival == -1 && PyErr_Occurred()) {
1641             goto exit;
1642         }
1643         width = ival;
1644     }
1645     return_value = unicode_zfill_impl(self, width);
1646 
1647 exit:
1648     return return_value;
1649 }
1650 
1651 PyDoc_STRVAR(unicode_startswith__doc__,
1652 "startswith($self, prefix[, start[, end]], /)\n"
1653 "--\n"
1654 "\n"
1655 "Return True if the string starts with the specified prefix, False otherwise.\n"
1656 "\n"
1657 "  prefix\n"
1658 "    A string or a tuple of strings to try.\n"
1659 "  start\n"
1660 "    Optional start position. Default: start of the string.\n"
1661 "  end\n"
1662 "    Optional stop position. Default: end of the string.");
1663 
1664 #define UNICODE_STARTSWITH_METHODDEF    \
1665     {"startswith", _PyCFunction_CAST(unicode_startswith), METH_FASTCALL, unicode_startswith__doc__},
1666 
1667 static PyObject *
1668 unicode_startswith_impl(PyObject *self, PyObject *subobj, Py_ssize_t start,
1669                         Py_ssize_t end);
1670 
1671 static PyObject *
unicode_startswith(PyObject * self,PyObject * const * args,Py_ssize_t nargs)1672 unicode_startswith(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1673 {
1674     PyObject *return_value = NULL;
1675     PyObject *subobj;
1676     Py_ssize_t start = 0;
1677     Py_ssize_t end = PY_SSIZE_T_MAX;
1678 
1679     if (!_PyArg_CheckPositional("startswith", nargs, 1, 3)) {
1680         goto exit;
1681     }
1682     subobj = args[0];
1683     if (nargs < 2) {
1684         goto skip_optional;
1685     }
1686     if (!_PyEval_SliceIndex(args[1], &start)) {
1687         goto exit;
1688     }
1689     if (nargs < 3) {
1690         goto skip_optional;
1691     }
1692     if (!_PyEval_SliceIndex(args[2], &end)) {
1693         goto exit;
1694     }
1695 skip_optional:
1696     return_value = unicode_startswith_impl(self, subobj, start, end);
1697 
1698 exit:
1699     return return_value;
1700 }
1701 
1702 PyDoc_STRVAR(unicode_endswith__doc__,
1703 "endswith($self, suffix[, start[, end]], /)\n"
1704 "--\n"
1705 "\n"
1706 "Return True if the string ends with the specified suffix, False otherwise.\n"
1707 "\n"
1708 "  suffix\n"
1709 "    A string or a tuple of strings to try.\n"
1710 "  start\n"
1711 "    Optional start position. Default: start of the string.\n"
1712 "  end\n"
1713 "    Optional stop position. Default: end of the string.");
1714 
1715 #define UNICODE_ENDSWITH_METHODDEF    \
1716     {"endswith", _PyCFunction_CAST(unicode_endswith), METH_FASTCALL, unicode_endswith__doc__},
1717 
1718 static PyObject *
1719 unicode_endswith_impl(PyObject *self, PyObject *subobj, Py_ssize_t start,
1720                       Py_ssize_t end);
1721 
1722 static PyObject *
unicode_endswith(PyObject * self,PyObject * const * args,Py_ssize_t nargs)1723 unicode_endswith(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1724 {
1725     PyObject *return_value = NULL;
1726     PyObject *subobj;
1727     Py_ssize_t start = 0;
1728     Py_ssize_t end = PY_SSIZE_T_MAX;
1729 
1730     if (!_PyArg_CheckPositional("endswith", nargs, 1, 3)) {
1731         goto exit;
1732     }
1733     subobj = args[0];
1734     if (nargs < 2) {
1735         goto skip_optional;
1736     }
1737     if (!_PyEval_SliceIndex(args[1], &start)) {
1738         goto exit;
1739     }
1740     if (nargs < 3) {
1741         goto skip_optional;
1742     }
1743     if (!_PyEval_SliceIndex(args[2], &end)) {
1744         goto exit;
1745     }
1746 skip_optional:
1747     return_value = unicode_endswith_impl(self, subobj, start, end);
1748 
1749 exit:
1750     return return_value;
1751 }
1752 
1753 PyDoc_STRVAR(unicode___format____doc__,
1754 "__format__($self, format_spec, /)\n"
1755 "--\n"
1756 "\n"
1757 "Return a formatted version of the string as described by format_spec.");
1758 
1759 #define UNICODE___FORMAT___METHODDEF    \
1760     {"__format__", (PyCFunction)unicode___format__, METH_O, unicode___format____doc__},
1761 
1762 static PyObject *
1763 unicode___format___impl(PyObject *self, PyObject *format_spec);
1764 
1765 static PyObject *
unicode___format__(PyObject * self,PyObject * arg)1766 unicode___format__(PyObject *self, PyObject *arg)
1767 {
1768     PyObject *return_value = NULL;
1769     PyObject *format_spec;
1770 
1771     if (!PyUnicode_Check(arg)) {
1772         _PyArg_BadArgument("__format__", "argument", "str", arg);
1773         goto exit;
1774     }
1775     format_spec = arg;
1776     return_value = unicode___format___impl(self, format_spec);
1777 
1778 exit:
1779     return return_value;
1780 }
1781 
1782 PyDoc_STRVAR(unicode_sizeof__doc__,
1783 "__sizeof__($self, /)\n"
1784 "--\n"
1785 "\n"
1786 "Return the size of the string in memory, in bytes.");
1787 
1788 #define UNICODE_SIZEOF_METHODDEF    \
1789     {"__sizeof__", (PyCFunction)unicode_sizeof, METH_NOARGS, unicode_sizeof__doc__},
1790 
1791 static PyObject *
1792 unicode_sizeof_impl(PyObject *self);
1793 
1794 static PyObject *
unicode_sizeof(PyObject * self,PyObject * Py_UNUSED (ignored))1795 unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
1796 {
1797     return unicode_sizeof_impl(self);
1798 }
1799 
1800 static PyObject *
1801 unicode_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
1802                  const char *errors);
1803 
1804 static PyObject *
unicode_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)1805 unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1806 {
1807     PyObject *return_value = NULL;
1808     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1809 
1810     #define NUM_KEYWORDS 3
1811     static struct {
1812         PyGC_Head _this_is_not_used;
1813         PyObject_VAR_HEAD
1814         PyObject *ob_item[NUM_KEYWORDS];
1815     } _kwtuple = {
1816         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1817         .ob_item = { &_Py_ID(object), &_Py_ID(encoding), &_Py_ID(errors), },
1818     };
1819     #undef NUM_KEYWORDS
1820     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1821 
1822     #else  // !Py_BUILD_CORE
1823     #  define KWTUPLE NULL
1824     #endif  // !Py_BUILD_CORE
1825 
1826     static const char * const _keywords[] = {"object", "encoding", "errors", NULL};
1827     static _PyArg_Parser _parser = {
1828         .keywords = _keywords,
1829         .fname = "str",
1830         .kwtuple = KWTUPLE,
1831     };
1832     #undef KWTUPLE
1833     PyObject *argsbuf[3];
1834     PyObject * const *fastargs;
1835     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1836     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
1837     PyObject *x = NULL;
1838     const char *encoding = NULL;
1839     const char *errors = NULL;
1840 
1841     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
1842     if (!fastargs) {
1843         goto exit;
1844     }
1845     if (!noptargs) {
1846         goto skip_optional_pos;
1847     }
1848     if (fastargs[0]) {
1849         x = fastargs[0];
1850         if (!--noptargs) {
1851             goto skip_optional_pos;
1852         }
1853     }
1854     if (fastargs[1]) {
1855         if (!PyUnicode_Check(fastargs[1])) {
1856             _PyArg_BadArgument("str", "argument 'encoding'", "str", fastargs[1]);
1857             goto exit;
1858         }
1859         Py_ssize_t encoding_length;
1860         encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
1861         if (encoding == NULL) {
1862             goto exit;
1863         }
1864         if (strlen(encoding) != (size_t)encoding_length) {
1865             PyErr_SetString(PyExc_ValueError, "embedded null character");
1866             goto exit;
1867         }
1868         if (!--noptargs) {
1869             goto skip_optional_pos;
1870         }
1871     }
1872     if (!PyUnicode_Check(fastargs[2])) {
1873         _PyArg_BadArgument("str", "argument 'errors'", "str", fastargs[2]);
1874         goto exit;
1875     }
1876     Py_ssize_t errors_length;
1877     errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
1878     if (errors == NULL) {
1879         goto exit;
1880     }
1881     if (strlen(errors) != (size_t)errors_length) {
1882         PyErr_SetString(PyExc_ValueError, "embedded null character");
1883         goto exit;
1884     }
1885 skip_optional_pos:
1886     return_value = unicode_new_impl(type, x, encoding, errors);
1887 
1888 exit:
1889     return return_value;
1890 }
1891 /*[clinic end generated code: output=9fee62bd337f809b input=a9049054013a1b77]*/
1892