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