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