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