Home | History | Annotate | Download | only in clinic
      1 /*[clinic input]
      2 preserve
      3 [clinic start generated code]*/
      4 
      5 PyDoc_STRVAR(unicode_title__doc__,
      6 "title($self, /)\n"
      7 "--\n"
      8 "\n"
      9 "Return a version of the string where each word is titlecased.\n"
     10 "\n"
     11 "More specifically, words start with uppercased characters and all remaining\n"
     12 "cased characters have lower case.");
     13 
     14 #define UNICODE_TITLE_METHODDEF    \
     15     {"title", (PyCFunction)unicode_title, METH_NOARGS, unicode_title__doc__},
     16 
     17 static PyObject *
     18 unicode_title_impl(PyObject *self);
     19 
     20 static PyObject *
     21 unicode_title(PyObject *self, PyObject *Py_UNUSED(ignored))
     22 {
     23     return unicode_title_impl(self);
     24 }
     25 
     26 PyDoc_STRVAR(unicode_capitalize__doc__,
     27 "capitalize($self, /)\n"
     28 "--\n"
     29 "\n"
     30 "Return a capitalized version of the string.\n"
     31 "\n"
     32 "More specifically, make the first character have upper case and the rest lower\n"
     33 "case.");
     34 
     35 #define UNICODE_CAPITALIZE_METHODDEF    \
     36     {"capitalize", (PyCFunction)unicode_capitalize, METH_NOARGS, unicode_capitalize__doc__},
     37 
     38 static PyObject *
     39 unicode_capitalize_impl(PyObject *self);
     40 
     41 static PyObject *
     42 unicode_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored))
     43 {
     44     return unicode_capitalize_impl(self);
     45 }
     46 
     47 PyDoc_STRVAR(unicode_casefold__doc__,
     48 "casefold($self, /)\n"
     49 "--\n"
     50 "\n"
     51 "Return a version of the string suitable for caseless comparisons.");
     52 
     53 #define UNICODE_CASEFOLD_METHODDEF    \
     54     {"casefold", (PyCFunction)unicode_casefold, METH_NOARGS, unicode_casefold__doc__},
     55 
     56 static PyObject *
     57 unicode_casefold_impl(PyObject *self);
     58 
     59 static PyObject *
     60 unicode_casefold(PyObject *self, PyObject *Py_UNUSED(ignored))
     61 {
     62     return unicode_casefold_impl(self);
     63 }
     64 
     65 PyDoc_STRVAR(unicode_center__doc__,
     66 "center($self, width, fillchar=\' \', /)\n"
     67 "--\n"
     68 "\n"
     69 "Return a centered string of length width.\n"
     70 "\n"
     71 "Padding is done using the specified fill character (default is a space).");
     72 
     73 #define UNICODE_CENTER_METHODDEF    \
     74     {"center", (PyCFunction)unicode_center, METH_FASTCALL, unicode_center__doc__},
     75 
     76 static PyObject *
     77 unicode_center_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
     78 
     79 static PyObject *
     80 unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
     81 {
     82     PyObject *return_value = NULL;
     83     Py_ssize_t width;
     84     Py_UCS4 fillchar = ' ';
     85 
     86     if (!_PyArg_ParseStack(args, nargs, "n|O&:center",
     87         &width, convert_uc, &fillchar)) {
     88         goto exit;
     89     }
     90     return_value = unicode_center_impl(self, width, fillchar);
     91 
     92 exit:
     93     return return_value;
     94 }
     95 
     96 PyDoc_STRVAR(unicode_encode__doc__,
     97 "encode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
     98 "--\n"
     99 "\n"
    100 "Encode the string using the codec registered for encoding.\n"
    101 "\n"
    102 "  encoding\n"
    103 "    The encoding in which to encode the string.\n"
    104 "  errors\n"
    105 "    The error handling scheme to use for encoding errors.\n"
    106 "    The default is \'strict\' meaning that encoding errors raise a\n"
    107 "    UnicodeEncodeError.  Other possible values are \'ignore\', \'replace\' and\n"
    108 "    \'xmlcharrefreplace\' as well as any other name registered with\n"
    109 "    codecs.register_error that can handle UnicodeEncodeErrors.");
    110 
    111 #define UNICODE_ENCODE_METHODDEF    \
    112     {"encode", (PyCFunction)unicode_encode, METH_FASTCALL|METH_KEYWORDS, unicode_encode__doc__},
    113 
    114 static PyObject *
    115 unicode_encode_impl(PyObject *self, const char *encoding, const char *errors);
    116 
    117 static PyObject *
    118 unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    119 {
    120     PyObject *return_value = NULL;
    121     static const char * const _keywords[] = {"encoding", "errors", NULL};
    122     static _PyArg_Parser _parser = {"|ss:encode", _keywords, 0};
    123     const char *encoding = NULL;
    124     const char *errors = NULL;
    125 
    126     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
    127         &encoding, &errors)) {
    128         goto exit;
    129     }
    130     return_value = unicode_encode_impl(self, encoding, errors);
    131 
    132 exit:
    133     return return_value;
    134 }
    135 
    136 PyDoc_STRVAR(unicode_expandtabs__doc__,
    137 "expandtabs($self, /, tabsize=8)\n"
    138 "--\n"
    139 "\n"
    140 "Return a copy where all tab characters are expanded using spaces.\n"
    141 "\n"
    142 "If tabsize is not given, a tab size of 8 characters is assumed.");
    143 
    144 #define UNICODE_EXPANDTABS_METHODDEF    \
    145     {"expandtabs", (PyCFunction)unicode_expandtabs, METH_FASTCALL|METH_KEYWORDS, unicode_expandtabs__doc__},
    146 
    147 static PyObject *
    148 unicode_expandtabs_impl(PyObject *self, int tabsize);
    149 
    150 static PyObject *
    151 unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    152 {
    153     PyObject *return_value = NULL;
    154     static const char * const _keywords[] = {"tabsize", NULL};
    155     static _PyArg_Parser _parser = {"|i:expandtabs", _keywords, 0};
    156     int tabsize = 8;
    157 
    158     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
    159         &tabsize)) {
    160         goto exit;
    161     }
    162     return_value = unicode_expandtabs_impl(self, tabsize);
    163 
    164 exit:
    165     return return_value;
    166 }
    167 
    168 PyDoc_STRVAR(unicode_isascii__doc__,
    169 "isascii($self, /)\n"
    170 "--\n"
    171 "\n"
    172 "Return True if all characters in the string are ASCII, False otherwise.\n"
    173 "\n"
    174 "ASCII characters have code points in the range U+0000-U+007F.\n"
    175 "Empty string is ASCII too.");
    176 
    177 #define UNICODE_ISASCII_METHODDEF    \
    178     {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__},
    179 
    180 static PyObject *
    181 unicode_isascii_impl(PyObject *self);
    182 
    183 static PyObject *
    184 unicode_isascii(PyObject *self, PyObject *Py_UNUSED(ignored))
    185 {
    186     return unicode_isascii_impl(self);
    187 }
    188 
    189 PyDoc_STRVAR(unicode_islower__doc__,
    190 "islower($self, /)\n"
    191 "--\n"
    192 "\n"
    193 "Return True if the string is a lowercase string, False otherwise.\n"
    194 "\n"
    195 "A string is lowercase if all cased characters in the string are lowercase and\n"
    196 "there is at least one cased character in the string.");
    197 
    198 #define UNICODE_ISLOWER_METHODDEF    \
    199     {"islower", (PyCFunction)unicode_islower, METH_NOARGS, unicode_islower__doc__},
    200 
    201 static PyObject *
    202 unicode_islower_impl(PyObject *self);
    203 
    204 static PyObject *
    205 unicode_islower(PyObject *self, PyObject *Py_UNUSED(ignored))
    206 {
    207     return unicode_islower_impl(self);
    208 }
    209 
    210 PyDoc_STRVAR(unicode_isupper__doc__,
    211 "isupper($self, /)\n"
    212 "--\n"
    213 "\n"
    214 "Return True if the string is an uppercase string, False otherwise.\n"
    215 "\n"
    216 "A string is uppercase if all cased characters in the string are uppercase and\n"
    217 "there is at least one cased character in the string.");
    218 
    219 #define UNICODE_ISUPPER_METHODDEF    \
    220     {"isupper", (PyCFunction)unicode_isupper, METH_NOARGS, unicode_isupper__doc__},
    221 
    222 static PyObject *
    223 unicode_isupper_impl(PyObject *self);
    224 
    225 static PyObject *
    226 unicode_isupper(PyObject *self, PyObject *Py_UNUSED(ignored))
    227 {
    228     return unicode_isupper_impl(self);
    229 }
    230 
    231 PyDoc_STRVAR(unicode_istitle__doc__,
    232 "istitle($self, /)\n"
    233 "--\n"
    234 "\n"
    235 "Return True if the string is a title-cased string, False otherwise.\n"
    236 "\n"
    237 "In a title-cased string, upper- and title-case characters may only\n"
    238 "follow uncased characters and lowercase characters only cased ones.");
    239 
    240 #define UNICODE_ISTITLE_METHODDEF    \
    241     {"istitle", (PyCFunction)unicode_istitle, METH_NOARGS, unicode_istitle__doc__},
    242 
    243 static PyObject *
    244 unicode_istitle_impl(PyObject *self);
    245 
    246 static PyObject *
    247 unicode_istitle(PyObject *self, PyObject *Py_UNUSED(ignored))
    248 {
    249     return unicode_istitle_impl(self);
    250 }
    251 
    252 PyDoc_STRVAR(unicode_isspace__doc__,
    253 "isspace($self, /)\n"
    254 "--\n"
    255 "\n"
    256 "Return True if the string is a whitespace string, False otherwise.\n"
    257 "\n"
    258 "A string is whitespace if all characters in the string are whitespace and there\n"
    259 "is at least one character in the string.");
    260 
    261 #define UNICODE_ISSPACE_METHODDEF    \
    262     {"isspace", (PyCFunction)unicode_isspace, METH_NOARGS, unicode_isspace__doc__},
    263 
    264 static PyObject *
    265 unicode_isspace_impl(PyObject *self);
    266 
    267 static PyObject *
    268 unicode_isspace(PyObject *self, PyObject *Py_UNUSED(ignored))
    269 {
    270     return unicode_isspace_impl(self);
    271 }
    272 
    273 PyDoc_STRVAR(unicode_isalpha__doc__,
    274 "isalpha($self, /)\n"
    275 "--\n"
    276 "\n"
    277 "Return True if the string is an alphabetic string, False otherwise.\n"
    278 "\n"
    279 "A string is alphabetic if all characters in the string are alphabetic and there\n"
    280 "is at least one character in the string.");
    281 
    282 #define UNICODE_ISALPHA_METHODDEF    \
    283     {"isalpha", (PyCFunction)unicode_isalpha, METH_NOARGS, unicode_isalpha__doc__},
    284 
    285 static PyObject *
    286 unicode_isalpha_impl(PyObject *self);
    287 
    288 static PyObject *
    289 unicode_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored))
    290 {
    291     return unicode_isalpha_impl(self);
    292 }
    293 
    294 PyDoc_STRVAR(unicode_isalnum__doc__,
    295 "isalnum($self, /)\n"
    296 "--\n"
    297 "\n"
    298 "Return True if the string is an alpha-numeric string, False otherwise.\n"
    299 "\n"
    300 "A string is alpha-numeric if all characters in the string are alpha-numeric and\n"
    301 "there is at least one character in the string.");
    302 
    303 #define UNICODE_ISALNUM_METHODDEF    \
    304     {"isalnum", (PyCFunction)unicode_isalnum, METH_NOARGS, unicode_isalnum__doc__},
    305 
    306 static PyObject *
    307 unicode_isalnum_impl(PyObject *self);
    308 
    309 static PyObject *
    310 unicode_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored))
    311 {
    312     return unicode_isalnum_impl(self);
    313 }
    314 
    315 PyDoc_STRVAR(unicode_isdecimal__doc__,
    316 "isdecimal($self, /)\n"
    317 "--\n"
    318 "\n"
    319 "Return True if the string is a decimal string, False otherwise.\n"
    320 "\n"
    321 "A string is a decimal string if all characters in the string are decimal and\n"
    322 "there is at least one character in the string.");
    323 
    324 #define UNICODE_ISDECIMAL_METHODDEF    \
    325     {"isdecimal", (PyCFunction)unicode_isdecimal, METH_NOARGS, unicode_isdecimal__doc__},
    326 
    327 static PyObject *
    328 unicode_isdecimal_impl(PyObject *self);
    329 
    330 static PyObject *
    331 unicode_isdecimal(PyObject *self, PyObject *Py_UNUSED(ignored))
    332 {
    333     return unicode_isdecimal_impl(self);
    334 }
    335 
    336 PyDoc_STRVAR(unicode_isdigit__doc__,
    337 "isdigit($self, /)\n"
    338 "--\n"
    339 "\n"
    340 "Return True if the string is a digit string, False otherwise.\n"
    341 "\n"
    342 "A string is a digit string if all characters in the string are digits and there\n"
    343 "is at least one character in the string.");
    344 
    345 #define UNICODE_ISDIGIT_METHODDEF    \
    346     {"isdigit", (PyCFunction)unicode_isdigit, METH_NOARGS, unicode_isdigit__doc__},
    347 
    348 static PyObject *
    349 unicode_isdigit_impl(PyObject *self);
    350 
    351 static PyObject *
    352 unicode_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored))
    353 {
    354     return unicode_isdigit_impl(self);
    355 }
    356 
    357 PyDoc_STRVAR(unicode_isnumeric__doc__,
    358 "isnumeric($self, /)\n"
    359 "--\n"
    360 "\n"
    361 "Return True if the string is a numeric string, False otherwise.\n"
    362 "\n"
    363 "A string is numeric if all characters in the string are numeric and there is at\n"
    364 "least one character in the string.");
    365 
    366 #define UNICODE_ISNUMERIC_METHODDEF    \
    367     {"isnumeric", (PyCFunction)unicode_isnumeric, METH_NOARGS, unicode_isnumeric__doc__},
    368 
    369 static PyObject *
    370 unicode_isnumeric_impl(PyObject *self);
    371 
    372 static PyObject *
    373 unicode_isnumeric(PyObject *self, PyObject *Py_UNUSED(ignored))
    374 {
    375     return unicode_isnumeric_impl(self);
    376 }
    377 
    378 PyDoc_STRVAR(unicode_isidentifier__doc__,
    379 "isidentifier($self, /)\n"
    380 "--\n"
    381 "\n"
    382 "Return True if the string is a valid Python identifier, False otherwise.\n"
    383 "\n"
    384 "Use keyword.iskeyword() to test for reserved identifiers such as \"def\" and\n"
    385 "\"class\".");
    386 
    387 #define UNICODE_ISIDENTIFIER_METHODDEF    \
    388     {"isidentifier", (PyCFunction)unicode_isidentifier, METH_NOARGS, unicode_isidentifier__doc__},
    389 
    390 static PyObject *
    391 unicode_isidentifier_impl(PyObject *self);
    392 
    393 static PyObject *
    394 unicode_isidentifier(PyObject *self, PyObject *Py_UNUSED(ignored))
    395 {
    396     return unicode_isidentifier_impl(self);
    397 }
    398 
    399 PyDoc_STRVAR(unicode_isprintable__doc__,
    400 "isprintable($self, /)\n"
    401 "--\n"
    402 "\n"
    403 "Return True if the string is printable, False otherwise.\n"
    404 "\n"
    405 "A string is printable if all of its characters are considered printable in\n"
    406 "repr() or if it is empty.");
    407 
    408 #define UNICODE_ISPRINTABLE_METHODDEF    \
    409     {"isprintable", (PyCFunction)unicode_isprintable, METH_NOARGS, unicode_isprintable__doc__},
    410 
    411 static PyObject *
    412 unicode_isprintable_impl(PyObject *self);
    413 
    414 static PyObject *
    415 unicode_isprintable(PyObject *self, PyObject *Py_UNUSED(ignored))
    416 {
    417     return unicode_isprintable_impl(self);
    418 }
    419 
    420 PyDoc_STRVAR(unicode_join__doc__,
    421 "join($self, iterable, /)\n"
    422 "--\n"
    423 "\n"
    424 "Concatenate any number of strings.\n"
    425 "\n"
    426 "The string whose method is called is inserted in between each given string.\n"
    427 "The result is returned as a new string.\n"
    428 "\n"
    429 "Example: \'.\'.join([\'ab\', \'pq\', \'rs\']) -> \'ab.pq.rs\'");
    430 
    431 #define UNICODE_JOIN_METHODDEF    \
    432     {"join", (PyCFunction)unicode_join, METH_O, unicode_join__doc__},
    433 
    434 PyDoc_STRVAR(unicode_ljust__doc__,
    435 "ljust($self, width, fillchar=\' \', /)\n"
    436 "--\n"
    437 "\n"
    438 "Return a left-justified string of length width.\n"
    439 "\n"
    440 "Padding is done using the specified fill character (default is a space).");
    441 
    442 #define UNICODE_LJUST_METHODDEF    \
    443     {"ljust", (PyCFunction)unicode_ljust, METH_FASTCALL, unicode_ljust__doc__},
    444 
    445 static PyObject *
    446 unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
    447 
    448 static PyObject *
    449 unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
    450 {
    451     PyObject *return_value = NULL;
    452     Py_ssize_t width;
    453     Py_UCS4 fillchar = ' ';
    454 
    455     if (!_PyArg_ParseStack(args, nargs, "n|O&:ljust",
    456         &width, convert_uc, &fillchar)) {
    457         goto exit;
    458     }
    459     return_value = unicode_ljust_impl(self, width, fillchar);
    460 
    461 exit:
    462     return return_value;
    463 }
    464 
    465 PyDoc_STRVAR(unicode_lower__doc__,
    466 "lower($self, /)\n"
    467 "--\n"
    468 "\n"
    469 "Return a copy of the string converted to lowercase.");
    470 
    471 #define UNICODE_LOWER_METHODDEF    \
    472     {"lower", (PyCFunction)unicode_lower, METH_NOARGS, unicode_lower__doc__},
    473 
    474 static PyObject *
    475 unicode_lower_impl(PyObject *self);
    476 
    477 static PyObject *
    478 unicode_lower(PyObject *self, PyObject *Py_UNUSED(ignored))
    479 {
    480     return unicode_lower_impl(self);
    481 }
    482 
    483 PyDoc_STRVAR(unicode_strip__doc__,
    484 "strip($self, chars=None, /)\n"
    485 "--\n"
    486 "\n"
    487 "Return a copy of the string with leading and trailing whitespace remove.\n"
    488 "\n"
    489 "If chars is given and not None, remove characters in chars instead.");
    490 
    491 #define UNICODE_STRIP_METHODDEF    \
    492     {"strip", (PyCFunction)unicode_strip, METH_FASTCALL, unicode_strip__doc__},
    493 
    494 static PyObject *
    495 unicode_strip_impl(PyObject *self, PyObject *chars);
    496 
    497 static PyObject *
    498 unicode_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
    499 {
    500     PyObject *return_value = NULL;
    501     PyObject *chars = Py_None;
    502 
    503     if (!_PyArg_UnpackStack(args, nargs, "strip",
    504         0, 1,
    505         &chars)) {
    506         goto exit;
    507     }
    508     return_value = unicode_strip_impl(self, chars);
    509 
    510 exit:
    511     return return_value;
    512 }
    513 
    514 PyDoc_STRVAR(unicode_lstrip__doc__,
    515 "lstrip($self, chars=None, /)\n"
    516 "--\n"
    517 "\n"
    518 "Return a copy of the string with leading whitespace removed.\n"
    519 "\n"
    520 "If chars is given and not None, remove characters in chars instead.");
    521 
    522 #define UNICODE_LSTRIP_METHODDEF    \
    523     {"lstrip", (PyCFunction)unicode_lstrip, METH_FASTCALL, unicode_lstrip__doc__},
    524 
    525 static PyObject *
    526 unicode_lstrip_impl(PyObject *self, PyObject *chars);
    527 
    528 static PyObject *
    529 unicode_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
    530 {
    531     PyObject *return_value = NULL;
    532     PyObject *chars = NULL;
    533 
    534     if (!_PyArg_UnpackStack(args, nargs, "lstrip",
    535         0, 1,
    536         &chars)) {
    537         goto exit;
    538     }
    539     return_value = unicode_lstrip_impl(self, chars);
    540 
    541 exit:
    542     return return_value;
    543 }
    544 
    545 PyDoc_STRVAR(unicode_rstrip__doc__,
    546 "rstrip($self, chars=None, /)\n"
    547 "--\n"
    548 "\n"
    549 "Return a copy of the string with trailing whitespace removed.\n"
    550 "\n"
    551 "If chars is given and not None, remove characters in chars instead.");
    552 
    553 #define UNICODE_RSTRIP_METHODDEF    \
    554     {"rstrip", (PyCFunction)unicode_rstrip, METH_FASTCALL, unicode_rstrip__doc__},
    555 
    556 static PyObject *
    557 unicode_rstrip_impl(PyObject *self, PyObject *chars);
    558 
    559 static PyObject *
    560 unicode_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
    561 {
    562     PyObject *return_value = NULL;
    563     PyObject *chars = NULL;
    564 
    565     if (!_PyArg_UnpackStack(args, nargs, "rstrip",
    566         0, 1,
    567         &chars)) {
    568         goto exit;
    569     }
    570     return_value = unicode_rstrip_impl(self, chars);
    571 
    572 exit:
    573     return return_value;
    574 }
    575 
    576 PyDoc_STRVAR(unicode_replace__doc__,
    577 "replace($self, old, new, count=-1, /)\n"
    578 "--\n"
    579 "\n"
    580 "Return a copy with all occurrences of substring old replaced by new.\n"
    581 "\n"
    582 "  count\n"
    583 "    Maximum number of occurrences to replace.\n"
    584 "    -1 (the default value) means replace all occurrences.\n"
    585 "\n"
    586 "If the optional argument count is given, only the first count occurrences are\n"
    587 "replaced.");
    588 
    589 #define UNICODE_REPLACE_METHODDEF    \
    590     {"replace", (PyCFunction)unicode_replace, METH_FASTCALL, unicode_replace__doc__},
    591 
    592 static PyObject *
    593 unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new,
    594                      Py_ssize_t count);
    595 
    596 static PyObject *
    597 unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
    598 {
    599     PyObject *return_value = NULL;
    600     PyObject *old;
    601     PyObject *new;
    602     Py_ssize_t count = -1;
    603 
    604     if (!_PyArg_ParseStack(args, nargs, "UU|n:replace",
    605         &old, &new, &count)) {
    606         goto exit;
    607     }
    608     return_value = unicode_replace_impl(self, old, new, count);
    609 
    610 exit:
    611     return return_value;
    612 }
    613 
    614 PyDoc_STRVAR(unicode_rjust__doc__,
    615 "rjust($self, width, fillchar=\' \', /)\n"
    616 "--\n"
    617 "\n"
    618 "Return a right-justified string of length width.\n"
    619 "\n"
    620 "Padding is done using the specified fill character (default is a space).");
    621 
    622 #define UNICODE_RJUST_METHODDEF    \
    623     {"rjust", (PyCFunction)unicode_rjust, METH_FASTCALL, unicode_rjust__doc__},
    624 
    625 static PyObject *
    626 unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
    627 
    628 static PyObject *
    629 unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
    630 {
    631     PyObject *return_value = NULL;
    632     Py_ssize_t width;
    633     Py_UCS4 fillchar = ' ';
    634 
    635     if (!_PyArg_ParseStack(args, nargs, "n|O&:rjust",
    636         &width, convert_uc, &fillchar)) {
    637         goto exit;
    638     }
    639     return_value = unicode_rjust_impl(self, width, fillchar);
    640 
    641 exit:
    642     return return_value;
    643 }
    644 
    645 PyDoc_STRVAR(unicode_split__doc__,
    646 "split($self, /, sep=None, maxsplit=-1)\n"
    647 "--\n"
    648 "\n"
    649 "Return a list of the words in the string, using sep as the delimiter string.\n"
    650 "\n"
    651 "  sep\n"
    652 "    The delimiter according which to split the string.\n"
    653 "    None (the default value) means split according to any whitespace,\n"
    654 "    and discard empty strings from the result.\n"
    655 "  maxsplit\n"
    656 "    Maximum number of splits to do.\n"
    657 "    -1 (the default value) means no limit.");
    658 
    659 #define UNICODE_SPLIT_METHODDEF    \
    660     {"split", (PyCFunction)unicode_split, METH_FASTCALL|METH_KEYWORDS, unicode_split__doc__},
    661 
    662 static PyObject *
    663 unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
    664 
    665 static PyObject *
    666 unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    667 {
    668     PyObject *return_value = NULL;
    669     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
    670     static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
    671     PyObject *sep = Py_None;
    672     Py_ssize_t maxsplit = -1;
    673 
    674     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
    675         &sep, &maxsplit)) {
    676         goto exit;
    677     }
    678     return_value = unicode_split_impl(self, sep, maxsplit);
    679 
    680 exit:
    681     return return_value;
    682 }
    683 
    684 PyDoc_STRVAR(unicode_partition__doc__,
    685 "partition($self, sep, /)\n"
    686 "--\n"
    687 "\n"
    688 "Partition the string into three parts using the given separator.\n"
    689 "\n"
    690 "This will search for the separator in the string.  If the separator is found,\n"
    691 "returns a 3-tuple containing the part before the separator, the separator\n"
    692 "itself, and the part after it.\n"
    693 "\n"
    694 "If the separator is not found, returns a 3-tuple containing the original string\n"
    695 "and two empty strings.");
    696 
    697 #define UNICODE_PARTITION_METHODDEF    \
    698     {"partition", (PyCFunction)unicode_partition, METH_O, unicode_partition__doc__},
    699 
    700 PyDoc_STRVAR(unicode_rpartition__doc__,
    701 "rpartition($self, sep, /)\n"
    702 "--\n"
    703 "\n"
    704 "Partition the string into three parts using the given separator.\n"
    705 "\n"
    706 "This will search for the separator in the string, starting at the end. If\n"
    707 "the separator is found, returns a 3-tuple containing the part before the\n"
    708 "separator, the separator itself, and the part after it.\n"
    709 "\n"
    710 "If the separator is not found, returns a 3-tuple containing two empty strings\n"
    711 "and the original string.");
    712 
    713 #define UNICODE_RPARTITION_METHODDEF    \
    714     {"rpartition", (PyCFunction)unicode_rpartition, METH_O, unicode_rpartition__doc__},
    715 
    716 PyDoc_STRVAR(unicode_rsplit__doc__,
    717 "rsplit($self, /, sep=None, maxsplit=-1)\n"
    718 "--\n"
    719 "\n"
    720 "Return a list of the words in the string, using sep as the delimiter string.\n"
    721 "\n"
    722 "  sep\n"
    723 "    The delimiter according which to split the string.\n"
    724 "    None (the default value) means split according to any whitespace,\n"
    725 "    and discard empty strings from the result.\n"
    726 "  maxsplit\n"
    727 "    Maximum number of splits to do.\n"
    728 "    -1 (the default value) means no limit.\n"
    729 "\n"
    730 "Splits are done starting at the end of the string and working to the front.");
    731 
    732 #define UNICODE_RSPLIT_METHODDEF    \
    733     {"rsplit", (PyCFunction)unicode_rsplit, METH_FASTCALL|METH_KEYWORDS, unicode_rsplit__doc__},
    734 
    735 static PyObject *
    736 unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
    737 
    738 static PyObject *
    739 unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    740 {
    741     PyObject *return_value = NULL;
    742     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
    743     static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
    744     PyObject *sep = Py_None;
    745     Py_ssize_t maxsplit = -1;
    746 
    747     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
    748         &sep, &maxsplit)) {
    749         goto exit;
    750     }
    751     return_value = unicode_rsplit_impl(self, sep, maxsplit);
    752 
    753 exit:
    754     return return_value;
    755 }
    756 
    757 PyDoc_STRVAR(unicode_splitlines__doc__,
    758 "splitlines($self, /, keepends=False)\n"
    759 "--\n"
    760 "\n"
    761 "Return a list of the lines in the string, breaking at line boundaries.\n"
    762 "\n"
    763 "Line breaks are not included in the resulting list unless keepends is given and\n"
    764 "true.");
    765 
    766 #define UNICODE_SPLITLINES_METHODDEF    \
    767     {"splitlines", (PyCFunction)unicode_splitlines, METH_FASTCALL|METH_KEYWORDS, unicode_splitlines__doc__},
    768 
    769 static PyObject *
    770 unicode_splitlines_impl(PyObject *self, int keepends);
    771 
    772 static PyObject *
    773 unicode_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    774 {
    775     PyObject *return_value = NULL;
    776     static const char * const _keywords[] = {"keepends", NULL};
    777     static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
    778     int keepends = 0;
    779 
    780     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
    781         &keepends)) {
    782         goto exit;
    783     }
    784     return_value = unicode_splitlines_impl(self, keepends);
    785 
    786 exit:
    787     return return_value;
    788 }
    789 
    790 PyDoc_STRVAR(unicode_swapcase__doc__,
    791 "swapcase($self, /)\n"
    792 "--\n"
    793 "\n"
    794 "Convert uppercase characters to lowercase and lowercase characters to uppercase.");
    795 
    796 #define UNICODE_SWAPCASE_METHODDEF    \
    797     {"swapcase", (PyCFunction)unicode_swapcase, METH_NOARGS, unicode_swapcase__doc__},
    798 
    799 static PyObject *
    800 unicode_swapcase_impl(PyObject *self);
    801 
    802 static PyObject *
    803 unicode_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
    804 {
    805     return unicode_swapcase_impl(self);
    806 }
    807 
    808 PyDoc_STRVAR(unicode_maketrans__doc__,
    809 "maketrans(x, y=None, z=None, /)\n"
    810 "--\n"
    811 "\n"
    812 "Return a translation table usable for str.translate().\n"
    813 "\n"
    814 "If there is only one argument, it must be a dictionary mapping Unicode\n"
    815 "ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
    816 "Character keys will be then converted to ordinals.\n"
    817 "If there are two arguments, they must be strings of equal length, and\n"
    818 "in the resulting dictionary, each character in x will be mapped to the\n"
    819 "character at the same position in y. If there is a third argument, it\n"
    820 "must be a string, whose characters will be mapped to None in the result.");
    821 
    822 #define UNICODE_MAKETRANS_METHODDEF    \
    823     {"maketrans", (PyCFunction)unicode_maketrans, METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__},
    824 
    825 static PyObject *
    826 unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
    827 
    828 static PyObject *
    829 unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
    830 {
    831     PyObject *return_value = NULL;
    832     PyObject *x;
    833     PyObject *y = NULL;
    834     PyObject *z = NULL;
    835 
    836     if (!_PyArg_ParseStack(args, nargs, "O|UU:maketrans",
    837         &x, &y, &z)) {
    838         goto exit;
    839     }
    840     return_value = unicode_maketrans_impl(x, y, z);
    841 
    842 exit:
    843     return return_value;
    844 }
    845 
    846 PyDoc_STRVAR(unicode_translate__doc__,
    847 "translate($self, table, /)\n"
    848 "--\n"
    849 "\n"
    850 "Replace each character in the string using the given translation table.\n"
    851 "\n"
    852 "  table\n"
    853 "    Translation table, which must be a mapping of Unicode ordinals to\n"
    854 "    Unicode ordinals, strings, or None.\n"
    855 "\n"
    856 "The table must implement lookup/indexing via __getitem__, for instance a\n"
    857 "dictionary or list.  If this operation raises LookupError, the character is\n"
    858 "left untouched.  Characters mapped to None are deleted.");
    859 
    860 #define UNICODE_TRANSLATE_METHODDEF    \
    861     {"translate", (PyCFunction)unicode_translate, METH_O, unicode_translate__doc__},
    862 
    863 PyDoc_STRVAR(unicode_upper__doc__,
    864 "upper($self, /)\n"
    865 "--\n"
    866 "\n"
    867 "Return a copy of the string converted to uppercase.");
    868 
    869 #define UNICODE_UPPER_METHODDEF    \
    870     {"upper", (PyCFunction)unicode_upper, METH_NOARGS, unicode_upper__doc__},
    871 
    872 static PyObject *
    873 unicode_upper_impl(PyObject *self);
    874 
    875 static PyObject *
    876 unicode_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
    877 {
    878     return unicode_upper_impl(self);
    879 }
    880 
    881 PyDoc_STRVAR(unicode_zfill__doc__,
    882 "zfill($self, width, /)\n"
    883 "--\n"
    884 "\n"
    885 "Pad a numeric string with zeros on the left, to fill a field of the given width.\n"
    886 "\n"
    887 "The string is never truncated.");
    888 
    889 #define UNICODE_ZFILL_METHODDEF    \
    890     {"zfill", (PyCFunction)unicode_zfill, METH_O, unicode_zfill__doc__},
    891 
    892 static PyObject *
    893 unicode_zfill_impl(PyObject *self, Py_ssize_t width);
    894 
    895 static PyObject *
    896 unicode_zfill(PyObject *self, PyObject *arg)
    897 {
    898     PyObject *return_value = NULL;
    899     Py_ssize_t width;
    900 
    901     if (!PyArg_Parse(arg, "n:zfill", &width)) {
    902         goto exit;
    903     }
    904     return_value = unicode_zfill_impl(self, width);
    905 
    906 exit:
    907     return return_value;
    908 }
    909 
    910 PyDoc_STRVAR(unicode___format____doc__,
    911 "__format__($self, format_spec, /)\n"
    912 "--\n"
    913 "\n"
    914 "Return a formatted version of the string as described by format_spec.");
    915 
    916 #define UNICODE___FORMAT___METHODDEF    \
    917     {"__format__", (PyCFunction)unicode___format__, METH_O, unicode___format____doc__},
    918 
    919 static PyObject *
    920 unicode___format___impl(PyObject *self, PyObject *format_spec);
    921 
    922 static PyObject *
    923 unicode___format__(PyObject *self, PyObject *arg)
    924 {
    925     PyObject *return_value = NULL;
    926     PyObject *format_spec;
    927 
    928     if (!PyArg_Parse(arg, "U:__format__", &format_spec)) {
    929         goto exit;
    930     }
    931     return_value = unicode___format___impl(self, format_spec);
    932 
    933 exit:
    934     return return_value;
    935 }
    936 
    937 PyDoc_STRVAR(unicode_sizeof__doc__,
    938 "__sizeof__($self, /)\n"
    939 "--\n"
    940 "\n"
    941 "Return the size of the string in memory, in bytes.");
    942 
    943 #define UNICODE_SIZEOF_METHODDEF    \
    944     {"__sizeof__", (PyCFunction)unicode_sizeof, METH_NOARGS, unicode_sizeof__doc__},
    945 
    946 static PyObject *
    947 unicode_sizeof_impl(PyObject *self);
    948 
    949 static PyObject *
    950 unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
    951 {
    952     return unicode_sizeof_impl(self);
    953 }
    954 /*[clinic end generated code: output=561c88c912b8fe3b input=a9049054013a1b77]*/
    955