Coverage Report

Created: 2026-02-26 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/clinic/unicodeobject.c.h
Line
Count
Source
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
24.2M
{
157
24.2M
    PyObject *return_value = NULL;
158
24.2M
    PyObject *substr;
159
24.2M
    Py_ssize_t start = 0;
160
24.2M
    Py_ssize_t end = PY_SSIZE_T_MAX;
161
24.2M
    Py_ssize_t _return_value;
162
163
24.2M
    if (!_PyArg_CheckPositional("count", nargs, 1, 3)) {
164
0
        goto exit;
165
0
    }
166
24.2M
    if (!PyUnicode_Check(args[0])) {
167
0
        _PyArg_BadArgument("count", "argument 1", "str", args[0]);
168
0
        goto exit;
169
0
    }
170
24.2M
    substr = args[0];
171
24.2M
    if (nargs < 2) {
172
6.71M
        goto skip_optional;
173
6.71M
    }
174
17.5M
    if (!_PyEval_SliceIndex(args[1], &start)) {
175
0
        goto exit;
176
0
    }
177
17.5M
    if (nargs < 3) {
178
0
        goto skip_optional;
179
0
    }
180
17.5M
    if (!_PyEval_SliceIndex(args[2], &end)) {
181
0
        goto exit;
182
0
    }
183
24.2M
skip_optional:
184
24.2M
    _return_value = unicode_count_impl(str, substr, start, end);
185
24.2M
    if ((_return_value == -1) && PyErr_Occurred()) {
186
0
        goto exit;
187
0
    }
188
24.2M
    return_value = PyLong_FromSsize_t(_return_value);
189
190
24.2M
exit:
191
24.2M
    return return_value;
192
24.2M
}
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
16.1M
{
218
16.1M
    PyObject *return_value = NULL;
219
16.1M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
220
221
16.1M
    #define NUM_KEYWORDS 2
222
16.1M
    static struct {
223
16.1M
        PyGC_Head _this_is_not_used;
224
16.1M
        PyObject_VAR_HEAD
225
16.1M
        Py_hash_t ob_hash;
226
16.1M
        PyObject *ob_item[NUM_KEYWORDS];
227
16.1M
    } _kwtuple = {
228
16.1M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
229
16.1M
        .ob_hash = -1,
230
16.1M
        .ob_item = { &_Py_ID(encoding), &_Py_ID(errors), },
231
16.1M
    };
232
16.1M
    #undef NUM_KEYWORDS
233
16.1M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
234
235
    #else  // !Py_BUILD_CORE
236
    #  define KWTUPLE NULL
237
    #endif  // !Py_BUILD_CORE
238
239
16.1M
    static const char * const _keywords[] = {"encoding", "errors", NULL};
240
16.1M
    static _PyArg_Parser _parser = {
241
16.1M
        .keywords = _keywords,
242
16.1M
        .fname = "encode",
243
16.1M
        .kwtuple = KWTUPLE,
244
16.1M
    };
245
16.1M
    #undef KWTUPLE
246
16.1M
    PyObject *argsbuf[2];
247
16.1M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
248
16.1M
    const char *encoding = NULL;
249
16.1M
    const char *errors = NULL;
250
251
16.1M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
252
16.1M
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
253
16.1M
    if (!args) {
254
0
        goto exit;
255
0
    }
256
16.1M
    if (!noptargs) {
257
10.9M
        goto skip_optional_pos;
258
10.9M
    }
259
5.17M
    if (args[0]) {
260
5.17M
        if (!PyUnicode_Check(args[0])) {
261
0
            _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]);
262
0
            goto exit;
263
0
        }
264
5.17M
        Py_ssize_t encoding_length;
265
5.17M
        encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
266
5.17M
        if (encoding == NULL) {
267
0
            goto exit;
268
0
        }
269
5.17M
        if (strlen(encoding) != (size_t)encoding_length) {
270
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
271
0
            goto exit;
272
0
        }
273
5.17M
        if (!--noptargs) {
274
4.31M
            goto skip_optional_pos;
275
4.31M
        }
276
5.17M
    }
277
856k
    if (!PyUnicode_Check(args[1])) {
278
0
        _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]);
279
0
        goto exit;
280
0
    }
281
856k
    Py_ssize_t errors_length;
282
856k
    errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
283
856k
    if (errors == NULL) {
284
0
        goto exit;
285
0
    }
286
856k
    if (strlen(errors) != (size_t)errors_length) {
287
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
288
0
        goto exit;
289
0
    }
290
16.1M
skip_optional_pos:
291
16.1M
    return_value = unicode_encode_impl(self, encoding, errors);
292
293
16.1M
exit:
294
16.1M
    return return_value;
295
16.1M
}
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
7.78M
{
314
7.78M
    PyObject *return_value = NULL;
315
7.78M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
316
317
7.78M
    #define NUM_KEYWORDS 1
318
7.78M
    static struct {
319
7.78M
        PyGC_Head _this_is_not_used;
320
7.78M
        PyObject_VAR_HEAD
321
7.78M
        Py_hash_t ob_hash;
322
7.78M
        PyObject *ob_item[NUM_KEYWORDS];
323
7.78M
    } _kwtuple = {
324
7.78M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
325
7.78M
        .ob_hash = -1,
326
7.78M
        .ob_item = { &_Py_ID(tabsize), },
327
7.78M
    };
328
7.78M
    #undef NUM_KEYWORDS
329
7.78M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
330
331
    #else  // !Py_BUILD_CORE
332
    #  define KWTUPLE NULL
333
    #endif  // !Py_BUILD_CORE
334
335
7.78M
    static const char * const _keywords[] = {"tabsize", NULL};
336
7.78M
    static _PyArg_Parser _parser = {
337
7.78M
        .keywords = _keywords,
338
7.78M
        .fname = "expandtabs",
339
7.78M
        .kwtuple = KWTUPLE,
340
7.78M
    };
341
7.78M
    #undef KWTUPLE
342
7.78M
    PyObject *argsbuf[1];
343
7.78M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
344
7.78M
    int tabsize = 8;
345
346
7.78M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
347
7.78M
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
348
7.78M
    if (!args) {
349
0
        goto exit;
350
0
    }
351
7.78M
    if (!noptargs) {
352
817
        goto skip_optional_pos;
353
817
    }
354
7.78M
    tabsize = PyLong_AsInt(args[0]);
355
7.78M
    if (tabsize == -1 && PyErr_Occurred()) {
356
0
        goto exit;
357
0
    }
358
7.78M
skip_optional_pos:
359
7.78M
    return_value = unicode_expandtabs_impl(self, tabsize);
360
361
7.78M
exit:
362
7.78M
    return return_value;
363
7.78M
}
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
24.2M
{
384
24.2M
    PyObject *return_value = NULL;
385
24.2M
    PyObject *substr;
386
24.2M
    Py_ssize_t start = 0;
387
24.2M
    Py_ssize_t end = PY_SSIZE_T_MAX;
388
24.2M
    Py_ssize_t _return_value;
389
390
24.2M
    if (!_PyArg_CheckPositional("find", nargs, 1, 3)) {
391
0
        goto exit;
392
0
    }
393
24.2M
    if (!PyUnicode_Check(args[0])) {
394
0
        _PyArg_BadArgument("find", "argument 1", "str", args[0]);
395
0
        goto exit;
396
0
    }
397
24.2M
    substr = args[0];
398
24.2M
    if (nargs < 2) {
399
1.87M
        goto skip_optional;
400
1.87M
    }
401
22.3M
    if (!_PyEval_SliceIndex(args[1], &start)) {
402
0
        goto exit;
403
0
    }
404
22.3M
    if (nargs < 3) {
405
17.5M
        goto skip_optional;
406
17.5M
    }
407
4.85M
    if (!_PyEval_SliceIndex(args[2], &end)) {
408
0
        goto exit;
409
0
    }
410
24.2M
skip_optional:
411
24.2M
    _return_value = unicode_find_impl(str, substr, start, end);
412
24.2M
    if ((_return_value == -1) && PyErr_Occurred()) {
413
0
        goto exit;
414
0
    }
415
24.2M
    return_value = PyLong_FromSsize_t(_return_value);
416
417
24.2M
exit:
418
24.2M
    return return_value;
419
24.2M
}
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
48.9k
{
440
48.9k
    PyObject *return_value = NULL;
441
48.9k
    PyObject *substr;
442
48.9k
    Py_ssize_t start = 0;
443
48.9k
    Py_ssize_t end = PY_SSIZE_T_MAX;
444
48.9k
    Py_ssize_t _return_value;
445
446
48.9k
    if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
447
0
        goto exit;
448
0
    }
449
48.9k
    if (!PyUnicode_Check(args[0])) {
450
0
        _PyArg_BadArgument("index", "argument 1", "str", args[0]);
451
0
        goto exit;
452
0
    }
453
48.9k
    substr = args[0];
454
48.9k
    if (nargs < 2) {
455
0
        goto skip_optional;
456
0
    }
457
48.9k
    if (!_PyEval_SliceIndex(args[1], &start)) {
458
0
        goto exit;
459
0
    }
460
48.9k
    if (nargs < 3) {
461
48.9k
        goto skip_optional;
462
48.9k
    }
463
0
    if (!_PyEval_SliceIndex(args[2], &end)) {
464
0
        goto exit;
465
0
    }
466
48.9k
skip_optional:
467
48.9k
    _return_value = unicode_index_impl(str, substr, start, end);
468
48.9k
    if ((_return_value == -1) && PyErr_Occurred()) {
469
750
        goto exit;
470
750
    }
471
48.2k
    return_value = PyLong_FromSsize_t(_return_value);
472
473
48.9k
exit:
474
48.9k
    return return_value;
475
48.2k
}
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
9.37k
{
495
9.37k
    return unicode_isascii_impl(self);
496
9.37k
}
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
10.6k
{
537
10.6k
    return unicode_isupper_impl(self);
538
10.6k
}
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
23.7M
{
579
23.7M
    return unicode_isspace_impl(self);
580
23.7M
}
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
14
{
600
14
    return unicode_isalpha_impl(self);
601
14
}
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
0
{
621
0
    return unicode_isalnum_impl(self);
622
0
}
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
1.32k
{
642
1.32k
    return unicode_isdecimal_impl(self);
643
1.32k
}
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.48M
{
663
1.48M
    return unicode_isdigit_impl(self);
664
1.48M
}
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
3.92k
{
705
3.92k
    return unicode_isidentifier_impl(self);
706
3.92k
}
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
890k
{
725
890k
    return unicode_isprintable_impl(self);
726
890k
}
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
111
{
759
111
    PyObject *return_value = NULL;
760
111
    Py_ssize_t width;
761
111
    Py_UCS4 fillchar = ' ';
762
763
111
    if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {
764
0
        goto exit;
765
0
    }
766
111
    {
767
111
        Py_ssize_t ival = -1;
768
111
        PyObject *iobj = _PyNumber_Index(args[0]);
769
111
        if (iobj != NULL) {
770
111
            ival = PyLong_AsSsize_t(iobj);
771
111
            Py_DECREF(iobj);
772
111
        }
773
111
        if (ival == -1 && PyErr_Occurred()) {
774
0
            goto exit;
775
0
        }
776
111
        width = ival;
777
111
    }
778
111
    if (nargs < 2) {
779
0
        goto skip_optional;
780
0
    }
781
111
    if (!convert_uc(args[1], &fillchar)) {
782
0
        goto exit;
783
0
    }
784
111
skip_optional:
785
111
    return_value = unicode_ljust_impl(self, width, fillchar);
786
787
111
exit:
788
111
    return return_value;
789
111
}
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
58.6M
{
806
58.6M
    return unicode_lower_impl(self);
807
58.6M
}
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
43.6M
{
826
43.6M
    PyObject *return_value = NULL;
827
43.6M
    PyObject *chars = Py_None;
828
829
43.6M
    if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
830
0
        goto exit;
831
0
    }
832
43.6M
    if (nargs < 1) {
833
43.6M
        goto skip_optional;
834
43.6M
    }
835
18
    chars = args[0];
836
43.6M
skip_optional:
837
43.6M
    return_value = unicode_strip_impl(self, chars);
838
839
43.6M
exit:
840
43.6M
    return return_value;
841
43.6M
}
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
2.10M
{
860
2.10M
    PyObject *return_value = NULL;
861
2.10M
    PyObject *chars = Py_None;
862
863
2.10M
    if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
864
0
        goto exit;
865
0
    }
866
2.10M
    if (nargs < 1) {
867
1.67M
        goto skip_optional;
868
1.67M
    }
869
425k
    chars = args[0];
870
2.10M
skip_optional:
871
2.10M
    return_value = unicode_lstrip_impl(self, chars);
872
873
2.10M
exit:
874
2.10M
    return return_value;
875
2.10M
}
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
33.3M
{
894
33.3M
    PyObject *return_value = NULL;
895
33.3M
    PyObject *chars = Py_None;
896
897
33.3M
    if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
898
0
        goto exit;
899
0
    }
900
33.3M
    if (nargs < 1) {
901
23.1M
        goto skip_optional;
902
23.1M
    }
903
10.2M
    chars = args[0];
904
33.3M
skip_optional:
905
33.3M
    return_value = unicode_rstrip_impl(self, chars);
906
907
33.3M
exit:
908
33.3M
    return return_value;
909
33.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
79.8M
{
934
79.8M
    PyObject *return_value = NULL;
935
79.8M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
936
937
79.8M
    #define NUM_KEYWORDS 1
938
79.8M
    static struct {
939
79.8M
        PyGC_Head _this_is_not_used;
940
79.8M
        PyObject_VAR_HEAD
941
79.8M
        Py_hash_t ob_hash;
942
79.8M
        PyObject *ob_item[NUM_KEYWORDS];
943
79.8M
    } _kwtuple = {
944
79.8M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
945
79.8M
        .ob_hash = -1,
946
79.8M
        .ob_item = { &_Py_ID(count), },
947
79.8M
    };
948
79.8M
    #undef NUM_KEYWORDS
949
79.8M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
950
951
    #else  // !Py_BUILD_CORE
952
    #  define KWTUPLE NULL
953
    #endif  // !Py_BUILD_CORE
954
955
79.8M
    static const char * const _keywords[] = {"", "", "count", NULL};
956
79.8M
    static _PyArg_Parser _parser = {
957
79.8M
        .keywords = _keywords,
958
79.8M
        .fname = "replace",
959
79.8M
        .kwtuple = KWTUPLE,
960
79.8M
    };
961
79.8M
    #undef KWTUPLE
962
79.8M
    PyObject *argsbuf[3];
963
79.8M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
964
79.8M
    PyObject *old;
965
79.8M
    PyObject *new;
966
79.8M
    Py_ssize_t count = -1;
967
968
79.8M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
969
79.8M
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
970
79.8M
    if (!args) {
971
0
        goto exit;
972
0
    }
973
79.8M
    if (!PyUnicode_Check(args[0])) {
974
0
        _PyArg_BadArgument("replace", "argument 1", "str", args[0]);
975
0
        goto exit;
976
0
    }
977
79.8M
    old = args[0];
978
79.8M
    if (!PyUnicode_Check(args[1])) {
979
0
        _PyArg_BadArgument("replace", "argument 2", "str", args[1]);
980
0
        goto exit;
981
0
    }
982
79.8M
    new = args[1];
983
79.8M
    if (!noptargs) {
984
79.8M
        goto skip_optional_pos;
985
79.8M
    }
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
79.8M
skip_optional_pos:
999
79.8M
    return_value = unicode_replace_impl(self, old, new, count);
1000
1001
79.8M
exit:
1002
79.8M
    return return_value;
1003
79.8M
}
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
154
{
1023
154
    PyObject *return_value = NULL;
1024
154
    PyObject *prefix;
1025
1026
154
    if (!PyUnicode_Check(arg)) {
1027
0
        _PyArg_BadArgument("removeprefix", "argument", "str", arg);
1028
0
        goto exit;
1029
0
    }
1030
154
    prefix = arg;
1031
154
    return_value = unicode_removeprefix_impl(self, prefix);
1032
1033
154
exit:
1034
154
    return return_value;
1035
154
}
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
315k
{
1089
315k
    PyObject *return_value = NULL;
1090
315k
    PyObject *substr;
1091
315k
    Py_ssize_t start = 0;
1092
315k
    Py_ssize_t end = PY_SSIZE_T_MAX;
1093
315k
    Py_ssize_t _return_value;
1094
1095
315k
    if (!_PyArg_CheckPositional("rfind", nargs, 1, 3)) {
1096
0
        goto exit;
1097
0
    }
1098
315k
    if (!PyUnicode_Check(args[0])) {
1099
0
        _PyArg_BadArgument("rfind", "argument 1", "str", args[0]);
1100
0
        goto exit;
1101
0
    }
1102
315k
    substr = args[0];
1103
315k
    if (nargs < 2) {
1104
304k
        goto skip_optional;
1105
304k
    }
1106
11.2k
    if (!_PyEval_SliceIndex(args[1], &start)) {
1107
0
        goto exit;
1108
0
    }
1109
11.2k
    if (nargs < 3) {
1110
3.68k
        goto skip_optional;
1111
3.68k
    }
1112
7.53k
    if (!_PyEval_SliceIndex(args[2], &end)) {
1113
0
        goto exit;
1114
0
    }
1115
315k
skip_optional:
1116
315k
    _return_value = unicode_rfind_impl(str, substr, start, end);
1117
315k
    if ((_return_value == -1) && PyErr_Occurred()) {
1118
0
        goto exit;
1119
0
    }
1120
315k
    return_value = PyLong_FromSsize_t(_return_value);
1121
1122
315k
exit:
1123
315k
    return return_value;
1124
315k
}
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
138k
{
1145
138k
    PyObject *return_value = NULL;
1146
138k
    PyObject *substr;
1147
138k
    Py_ssize_t start = 0;
1148
138k
    Py_ssize_t end = PY_SSIZE_T_MAX;
1149
138k
    Py_ssize_t _return_value;
1150
1151
138k
    if (!_PyArg_CheckPositional("rindex", nargs, 1, 3)) {
1152
0
        goto exit;
1153
0
    }
1154
138k
    if (!PyUnicode_Check(args[0])) {
1155
0
        _PyArg_BadArgument("rindex", "argument 1", "str", args[0]);
1156
0
        goto exit;
1157
0
    }
1158
138k
    substr = args[0];
1159
138k
    if (nargs < 2) {
1160
0
        goto skip_optional;
1161
0
    }
1162
138k
    if (!_PyEval_SliceIndex(args[1], &start)) {
1163
0
        goto exit;
1164
0
    }
1165
138k
    if (nargs < 3) {
1166
0
        goto skip_optional;
1167
0
    }
1168
138k
    if (!_PyEval_SliceIndex(args[2], &end)) {
1169
0
        goto exit;
1170
0
    }
1171
138k
skip_optional:
1172
138k
    _return_value = unicode_rindex_impl(str, substr, start, end);
1173
138k
    if ((_return_value == -1) && PyErr_Occurred()) {
1174
0
        goto exit;
1175
0
    }
1176
138k
    return_value = PyLong_FromSsize_t(_return_value);
1177
1178
138k
exit:
1179
138k
    return return_value;
1180
138k
}
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
17.9M
{
1262
17.9M
    PyObject *return_value = NULL;
1263
17.9M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1264
1265
17.9M
    #define NUM_KEYWORDS 2
1266
17.9M
    static struct {
1267
17.9M
        PyGC_Head _this_is_not_used;
1268
17.9M
        PyObject_VAR_HEAD
1269
17.9M
        Py_hash_t ob_hash;
1270
17.9M
        PyObject *ob_item[NUM_KEYWORDS];
1271
17.9M
    } _kwtuple = {
1272
17.9M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1273
17.9M
        .ob_hash = -1,
1274
17.9M
        .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
1275
17.9M
    };
1276
17.9M
    #undef NUM_KEYWORDS
1277
17.9M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1278
1279
    #else  // !Py_BUILD_CORE
1280
    #  define KWTUPLE NULL
1281
    #endif  // !Py_BUILD_CORE
1282
1283
17.9M
    static const char * const _keywords[] = {"sep", "maxsplit", NULL};
1284
17.9M
    static _PyArg_Parser _parser = {
1285
17.9M
        .keywords = _keywords,
1286
17.9M
        .fname = "split",
1287
17.9M
        .kwtuple = KWTUPLE,
1288
17.9M
    };
1289
17.9M
    #undef KWTUPLE
1290
17.9M
    PyObject *argsbuf[2];
1291
17.9M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1292
17.9M
    PyObject *sep = Py_None;
1293
17.9M
    Py_ssize_t maxsplit = -1;
1294
1295
17.9M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1296
17.9M
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1297
17.9M
    if (!args) {
1298
0
        goto exit;
1299
0
    }
1300
17.9M
    if (!noptargs) {
1301
144k
        goto skip_optional_pos;
1302
144k
    }
1303
17.8M
    if (args[0]) {
1304
17.8M
        sep = args[0];
1305
17.8M
        if (!--noptargs) {
1306
12.0M
            goto skip_optional_pos;
1307
12.0M
        }
1308
17.8M
    }
1309
5.75M
    {
1310
5.75M
        Py_ssize_t ival = -1;
1311
5.75M
        PyObject *iobj = _PyNumber_Index(args[1]);
1312
5.75M
        if (iobj != NULL) {
1313
5.75M
            ival = PyLong_AsSsize_t(iobj);
1314
5.75M
            Py_DECREF(iobj);
1315
5.75M
        }
1316
5.75M
        if (ival == -1 && PyErr_Occurred()) {
1317
0
            goto exit;
1318
0
        }
1319
5.75M
        maxsplit = ival;
1320
5.75M
    }
1321
17.9M
skip_optional_pos:
1322
17.9M
    return_value = unicode_split_impl(self, sep, maxsplit);
1323
1324
17.9M
exit:
1325
17.9M
    return return_value;
1326
17.9M
}
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
64
{
1387
64
    PyObject *return_value = NULL;
1388
64
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1389
1390
64
    #define NUM_KEYWORDS 2
1391
64
    static struct {
1392
64
        PyGC_Head _this_is_not_used;
1393
64
        PyObject_VAR_HEAD
1394
64
        Py_hash_t ob_hash;
1395
64
        PyObject *ob_item[NUM_KEYWORDS];
1396
64
    } _kwtuple = {
1397
64
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1398
64
        .ob_hash = -1,
1399
64
        .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
1400
64
    };
1401
64
    #undef NUM_KEYWORDS
1402
64
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1403
1404
    #else  // !Py_BUILD_CORE
1405
    #  define KWTUPLE NULL
1406
    #endif  // !Py_BUILD_CORE
1407
1408
64
    static const char * const _keywords[] = {"sep", "maxsplit", NULL};
1409
64
    static _PyArg_Parser _parser = {
1410
64
        .keywords = _keywords,
1411
64
        .fname = "rsplit",
1412
64
        .kwtuple = KWTUPLE,
1413
64
    };
1414
64
    #undef KWTUPLE
1415
64
    PyObject *argsbuf[2];
1416
64
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1417
64
    PyObject *sep = Py_None;
1418
64
    Py_ssize_t maxsplit = -1;
1419
1420
64
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1421
64
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1422
64
    if (!args) {
1423
0
        goto exit;
1424
0
    }
1425
64
    if (!noptargs) {
1426
0
        goto skip_optional_pos;
1427
0
    }
1428
64
    if (args[0]) {
1429
64
        sep = args[0];
1430
64
        if (!--noptargs) {
1431
0
            goto skip_optional_pos;
1432
0
        }
1433
64
    }
1434
64
    {
1435
64
        Py_ssize_t ival = -1;
1436
64
        PyObject *iobj = _PyNumber_Index(args[1]);
1437
64
        if (iobj != NULL) {
1438
64
            ival = PyLong_AsSsize_t(iobj);
1439
64
            Py_DECREF(iobj);
1440
64
        }
1441
64
        if (ival == -1 && PyErr_Occurred()) {
1442
0
            goto exit;
1443
0
        }
1444
64
        maxsplit = ival;
1445
64
    }
1446
64
skip_optional_pos:
1447
64
    return_value = unicode_rsplit_impl(self, sep, maxsplit);
1448
1449
64
exit:
1450
64
    return return_value;
1451
64
}
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.1k
{
1471
14.1k
    PyObject *return_value = NULL;
1472
14.1k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1473
1474
14.1k
    #define NUM_KEYWORDS 1
1475
14.1k
    static struct {
1476
14.1k
        PyGC_Head _this_is_not_used;
1477
14.1k
        PyObject_VAR_HEAD
1478
14.1k
        Py_hash_t ob_hash;
1479
14.1k
        PyObject *ob_item[NUM_KEYWORDS];
1480
14.1k
    } _kwtuple = {
1481
14.1k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1482
14.1k
        .ob_hash = -1,
1483
14.1k
        .ob_item = { &_Py_ID(keepends), },
1484
14.1k
    };
1485
14.1k
    #undef NUM_KEYWORDS
1486
14.1k
    #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.1k
    static const char * const _keywords[] = {"keepends", NULL};
1493
14.1k
    static _PyArg_Parser _parser = {
1494
14.1k
        .keywords = _keywords,
1495
14.1k
        .fname = "splitlines",
1496
14.1k
        .kwtuple = KWTUPLE,
1497
14.1k
    };
1498
14.1k
    #undef KWTUPLE
1499
14.1k
    PyObject *argsbuf[1];
1500
14.1k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1501
14.1k
    int keepends = 0;
1502
1503
14.1k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1504
14.1k
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1505
14.1k
    if (!args) {
1506
0
        goto exit;
1507
0
    }
1508
14.1k
    if (!noptargs) {
1509
14.1k
        goto skip_optional_pos;
1510
14.1k
    }
1511
0
    keepends = PyObject_IsTrue(args[0]);
1512
0
    if (keepends < 0) {
1513
0
        goto exit;
1514
0
    }
1515
14.1k
skip_optional_pos:
1516
14.1k
    return_value = unicode_splitlines_impl(self, keepends);
1517
1518
14.1k
exit:
1519
14.1k
    return return_value;
1520
14.1k
}
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
2
{
1563
2
    PyObject *return_value = NULL;
1564
2
    PyObject *x;
1565
2
    PyObject *y = NULL;
1566
2
    PyObject *z = NULL;
1567
1568
2
    if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) {
1569
0
        goto exit;
1570
0
    }
1571
2
    x = args[0];
1572
2
    if (nargs < 2) {
1573
0
        goto skip_optional;
1574
0
    }
1575
2
    if (!PyUnicode_Check(args[1])) {
1576
0
        _PyArg_BadArgument("maketrans", "argument 2", "str", args[1]);
1577
0
        goto exit;
1578
0
    }
1579
2
    y = args[1];
1580
2
    if (nargs < 3) {
1581
2
        goto skip_optional;
1582
2
    }
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
2
skip_optional:
1589
2
    return_value = unicode_maketrans_impl(x, y, z);
1590
1591
2
exit:
1592
2
    return return_value;
1593
2
}
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
306
{
1627
306
    return unicode_upper_impl(self);
1628
306
}
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
84.7M
{
1691
84.7M
    PyObject *return_value = NULL;
1692
84.7M
    PyObject *subobj;
1693
84.7M
    Py_ssize_t start = 0;
1694
84.7M
    Py_ssize_t end = PY_SSIZE_T_MAX;
1695
1696
84.7M
    if (!_PyArg_CheckPositional("startswith", nargs, 1, 3)) {
1697
0
        goto exit;
1698
0
    }
1699
84.7M
    subobj = args[0];
1700
84.7M
    if (nargs < 2) {
1701
65.6M
        goto skip_optional;
1702
65.6M
    }
1703
19.0M
    if (!_PyEval_SliceIndex(args[1], &start)) {
1704
0
        goto exit;
1705
0
    }
1706
19.0M
    if (nargs < 3) {
1707
19.0M
        goto skip_optional;
1708
19.0M
    }
1709
0
    if (!_PyEval_SliceIndex(args[2], &end)) {
1710
0
        goto exit;
1711
0
    }
1712
84.7M
skip_optional:
1713
84.7M
    return_value = unicode_startswith_impl(self, subobj, start, end);
1714
1715
84.7M
exit:
1716
84.7M
    return return_value;
1717
84.7M
}
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
10.8M
{
1742
10.8M
    PyObject *return_value = NULL;
1743
10.8M
    PyObject *subobj;
1744
10.8M
    Py_ssize_t start = 0;
1745
10.8M
    Py_ssize_t end = PY_SSIZE_T_MAX;
1746
1747
10.8M
    if (!_PyArg_CheckPositional("endswith", nargs, 1, 3)) {
1748
0
        goto exit;
1749
0
    }
1750
10.8M
    subobj = args[0];
1751
10.8M
    if (nargs < 2) {
1752
10.8M
        goto skip_optional;
1753
10.8M
    }
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
10.8M
skip_optional:
1764
10.8M
    return_value = unicode_endswith_impl(self, subobj, start, end);
1765
1766
10.8M
exit:
1767
10.8M
    return return_value;
1768
10.8M
}
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
16.4M
{
1824
16.4M
    PyObject *return_value = NULL;
1825
16.4M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1826
1827
16.4M
    #define NUM_KEYWORDS 3
1828
16.4M
    static struct {
1829
16.4M
        PyGC_Head _this_is_not_used;
1830
16.4M
        PyObject_VAR_HEAD
1831
16.4M
        Py_hash_t ob_hash;
1832
16.4M
        PyObject *ob_item[NUM_KEYWORDS];
1833
16.4M
    } _kwtuple = {
1834
16.4M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1835
16.4M
        .ob_hash = -1,
1836
16.4M
        .ob_item = { &_Py_ID(object), &_Py_ID(encoding), &_Py_ID(errors), },
1837
16.4M
    };
1838
16.4M
    #undef NUM_KEYWORDS
1839
16.4M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1840
1841
    #else  // !Py_BUILD_CORE
1842
    #  define KWTUPLE NULL
1843
    #endif  // !Py_BUILD_CORE
1844
1845
16.4M
    static const char * const _keywords[] = {"object", "encoding", "errors", NULL};
1846
16.4M
    static _PyArg_Parser _parser = {
1847
16.4M
        .keywords = _keywords,
1848
16.4M
        .fname = "str",
1849
16.4M
        .kwtuple = KWTUPLE,
1850
16.4M
    };
1851
16.4M
    #undef KWTUPLE
1852
16.4M
    PyObject *argsbuf[3];
1853
16.4M
    PyObject * const *fastargs;
1854
16.4M
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1855
16.4M
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
1856
16.4M
    PyObject *x = NULL;
1857
16.4M
    const char *encoding = NULL;
1858
16.4M
    const char *errors = NULL;
1859
1860
16.4M
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
1861
16.4M
            /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1862
16.4M
    if (!fastargs) {
1863
0
        goto exit;
1864
0
    }
1865
16.4M
    if (!noptargs) {
1866
0
        goto skip_optional_pos;
1867
0
    }
1868
16.4M
    if (fastargs[0]) {
1869
16.4M
        x = fastargs[0];
1870
16.4M
        if (!--noptargs) {
1871
16.4M
            goto skip_optional_pos;
1872
16.4M
        }
1873
16.4M
    }
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
16.4M
skip_optional_pos:
1906
16.4M
    return_value = unicode_new_impl(type, x, encoding, errors);
1907
1908
16.4M
exit:
1909
16.4M
    return return_value;
1910
16.4M
}
1911
/*[clinic end generated code: output=238917fe66120bde input=a9049054013a1b77]*/