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