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