Coverage Report

Created: 2025-07-04 06:49

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