blob: 509405e5271ca6e7256cbac77343c124280071d7 [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"
Martin Panter91a88662017-01-24 00:30:06 +0000409"The string whose method is called is inserted in between each given string.\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"
Victor Stinner0c4a8282017-01-17 02:21:47 +0100474"Return a copy of the string with leading and trailing whitespace remove.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900475"\n"
476"If chars is given and not None, remove characters in chars instead.");
477
478#define UNICODE_STRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100479 {"strip", (PyCFunction)unicode_strip, METH_FASTCALL, unicode_strip__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900480
481static PyObject *
482unicode_strip_impl(PyObject *self, PyObject *chars);
483
484static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100485unicode_strip(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900486{
487 PyObject *return_value = NULL;
488 PyObject *chars = Py_None;
489
Victor Stinner0c4a8282017-01-17 02:21:47 +0100490 if (!_PyArg_UnpackStack(args, nargs, "strip",
INADA Naoki3ae20562017-01-16 20:41:20 +0900491 0, 1,
492 &chars)) {
493 goto exit;
494 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100495
496 if (!_PyArg_NoStackKeywords("strip", kwnames)) {
497 goto exit;
498 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900499 return_value = unicode_strip_impl(self, chars);
500
501exit:
502 return return_value;
503}
504
505PyDoc_STRVAR(unicode_lstrip__doc__,
506"lstrip($self, chars=None, /)\n"
507"--\n"
508"\n"
509"Return a copy of the string with leading whitespace removed.\n"
510"\n"
511"If chars is given and not None, remove characters in chars instead.");
512
513#define UNICODE_LSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100514 {"lstrip", (PyCFunction)unicode_lstrip, METH_FASTCALL, unicode_lstrip__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900515
516static PyObject *
517unicode_lstrip_impl(PyObject *self, PyObject *chars);
518
519static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100520unicode_lstrip(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900521{
522 PyObject *return_value = NULL;
523 PyObject *chars = NULL;
524
Victor Stinner0c4a8282017-01-17 02:21:47 +0100525 if (!_PyArg_UnpackStack(args, nargs, "lstrip",
INADA Naoki3ae20562017-01-16 20:41:20 +0900526 0, 1,
527 &chars)) {
528 goto exit;
529 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100530
531 if (!_PyArg_NoStackKeywords("lstrip", kwnames)) {
532 goto exit;
533 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900534 return_value = unicode_lstrip_impl(self, chars);
535
536exit:
537 return return_value;
538}
539
540PyDoc_STRVAR(unicode_rstrip__doc__,
541"rstrip($self, chars=None, /)\n"
542"--\n"
543"\n"
544"Return a copy of the string with trailing whitespace removed.\n"
545"\n"
546"If chars is given and not None, remove characters in chars instead.");
547
548#define UNICODE_RSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100549 {"rstrip", (PyCFunction)unicode_rstrip, METH_FASTCALL, unicode_rstrip__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900550
551static PyObject *
552unicode_rstrip_impl(PyObject *self, PyObject *chars);
553
554static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100555unicode_rstrip(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900556{
557 PyObject *return_value = NULL;
558 PyObject *chars = NULL;
559
Victor Stinner0c4a8282017-01-17 02:21:47 +0100560 if (!_PyArg_UnpackStack(args, nargs, "rstrip",
INADA Naoki3ae20562017-01-16 20:41:20 +0900561 0, 1,
562 &chars)) {
563 goto exit;
564 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100565
566 if (!_PyArg_NoStackKeywords("rstrip", kwnames)) {
567 goto exit;
568 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900569 return_value = unicode_rstrip_impl(self, chars);
570
571exit:
572 return return_value;
573}
574
575PyDoc_STRVAR(unicode_replace__doc__,
576"replace($self, old, new, count=-1, /)\n"
577"--\n"
578"\n"
579"Return a copy with all occurrences of substring old replaced by new.\n"
580"\n"
581" count\n"
582" Maximum number of occurrences to replace.\n"
583" -1 (the default value) means replace all occurrences.\n"
584"\n"
585"If the optional argument count is given, only the first count occurrences are\n"
586"replaced.");
587
588#define UNICODE_REPLACE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100589 {"replace", (PyCFunction)unicode_replace, METH_FASTCALL, unicode_replace__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900590
591static PyObject *
592unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new,
593 Py_ssize_t count);
594
595static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100596unicode_replace(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900597{
598 PyObject *return_value = NULL;
599 PyObject *old;
600 PyObject *new;
601 Py_ssize_t count = -1;
602
Victor Stinner259f0e42017-01-17 01:35:17 +0100603 if (!_PyArg_ParseStack(args, nargs, "UU|n:replace",
INADA Naoki3ae20562017-01-16 20:41:20 +0900604 &old, &new, &count)) {
605 goto exit;
606 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100607
608 if (!_PyArg_NoStackKeywords("replace", kwnames)) {
609 goto exit;
610 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900611 return_value = unicode_replace_impl(self, old, new, count);
612
613exit:
614 return return_value;
615}
616
617PyDoc_STRVAR(unicode_rjust__doc__,
618"rjust($self, width, fillchar=\' \', /)\n"
619"--\n"
620"\n"
621"Return a right-justified string of length width.\n"
622"\n"
623"Padding is done using the specified fill character (default is a space).");
624
625#define UNICODE_RJUST_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100626 {"rjust", (PyCFunction)unicode_rjust, METH_FASTCALL, unicode_rjust__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900627
628static PyObject *
629unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
630
631static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100632unicode_rjust(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900633{
634 PyObject *return_value = NULL;
635 Py_ssize_t width;
636 Py_UCS4 fillchar = ' ';
637
Victor Stinner259f0e42017-01-17 01:35:17 +0100638 if (!_PyArg_ParseStack(args, nargs, "n|O&:rjust",
INADA Naoki3ae20562017-01-16 20:41:20 +0900639 &width, convert_uc, &fillchar)) {
640 goto exit;
641 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100642
643 if (!_PyArg_NoStackKeywords("rjust", kwnames)) {
644 goto exit;
645 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900646 return_value = unicode_rjust_impl(self, width, fillchar);
647
648exit:
649 return return_value;
650}
651
652PyDoc_STRVAR(unicode_split__doc__,
653"split($self, /, sep=None, maxsplit=-1)\n"
654"--\n"
655"\n"
656"Return a list of the words in the string, using sep as the delimiter string.\n"
657"\n"
658" sep\n"
659" The delimiter according which to split the string.\n"
660" None (the default value) means split according to any whitespace,\n"
661" and discard empty strings from the result.\n"
662" maxsplit\n"
663" Maximum number of splits to do.\n"
664" -1 (the default value) means no limit.");
665
666#define UNICODE_SPLIT_METHODDEF \
667 {"split", (PyCFunction)unicode_split, METH_FASTCALL, unicode_split__doc__},
668
669static PyObject *
670unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
671
672static PyObject *
673unicode_split(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
674{
675 PyObject *return_value = NULL;
676 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
677 static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
678 PyObject *sep = Py_None;
679 Py_ssize_t maxsplit = -1;
680
Victor Stinner3e1fad62017-01-17 01:29:01 +0100681 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900682 &sep, &maxsplit)) {
683 goto exit;
684 }
685 return_value = unicode_split_impl(self, sep, maxsplit);
686
687exit:
688 return return_value;
689}
690
691PyDoc_STRVAR(unicode_partition__doc__,
692"partition($self, sep, /)\n"
693"--\n"
694"\n"
695"Partition the string into three parts using the given separator.\n"
696"\n"
697"This will search for the separator in the string. If the separator is found,\n"
698"returns a 3-tuple containing the part before the separator, the separator\n"
699"itself, and the part after it.\n"
700"\n"
701"If the separator is not found, returns a 3-tuple containing the original string\n"
702"and two empty strings.");
703
704#define UNICODE_PARTITION_METHODDEF \
705 {"partition", (PyCFunction)unicode_partition, METH_O, unicode_partition__doc__},
706
707PyDoc_STRVAR(unicode_rpartition__doc__,
708"rpartition($self, sep, /)\n"
709"--\n"
710"\n"
711"Partition the string into three parts using the given separator.\n"
712"\n"
713"This will search for the separator in the string, starting and the end. If\n"
714"the separator is found, returns a 3-tuple containing the part before the\n"
715"separator, the separator itself, and the part after it.\n"
716"\n"
717"If the separator is not found, returns a 3-tuple containing two empty strings\n"
718"and the original string.");
719
720#define UNICODE_RPARTITION_METHODDEF \
721 {"rpartition", (PyCFunction)unicode_rpartition, METH_O, unicode_rpartition__doc__},
722
723PyDoc_STRVAR(unicode_rsplit__doc__,
724"rsplit($self, /, sep=None, maxsplit=-1)\n"
725"--\n"
726"\n"
727"Return a list of the words in the string, using sep as the delimiter string.\n"
728"\n"
729" sep\n"
730" The delimiter according which to split the string.\n"
731" None (the default value) means split according to any whitespace,\n"
732" and discard empty strings from the result.\n"
733" maxsplit\n"
734" Maximum number of splits to do.\n"
735" -1 (the default value) means no limit.\n"
736"\n"
737"Splits are done starting at the end of the string and working to the front.");
738
739#define UNICODE_RSPLIT_METHODDEF \
740 {"rsplit", (PyCFunction)unicode_rsplit, METH_FASTCALL, unicode_rsplit__doc__},
741
742static PyObject *
743unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
744
745static PyObject *
746unicode_rsplit(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
747{
748 PyObject *return_value = NULL;
749 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
750 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
751 PyObject *sep = Py_None;
752 Py_ssize_t maxsplit = -1;
753
Victor Stinner3e1fad62017-01-17 01:29:01 +0100754 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900755 &sep, &maxsplit)) {
756 goto exit;
757 }
758 return_value = unicode_rsplit_impl(self, sep, maxsplit);
759
760exit:
761 return return_value;
762}
763
764PyDoc_STRVAR(unicode_splitlines__doc__,
765"splitlines($self, /, keepends=False)\n"
766"--\n"
767"\n"
768"Return a list of the lines in the string, breaking at line boundaries.\n"
769"\n"
770"Line breaks are not included in the resulting list unless keepends is given and\n"
771"true.");
772
773#define UNICODE_SPLITLINES_METHODDEF \
774 {"splitlines", (PyCFunction)unicode_splitlines, METH_FASTCALL, unicode_splitlines__doc__},
775
776static PyObject *
777unicode_splitlines_impl(PyObject *self, int keepends);
778
779static PyObject *
780unicode_splitlines(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
781{
782 PyObject *return_value = NULL;
783 static const char * const _keywords[] = {"keepends", NULL};
784 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
785 int keepends = 0;
786
Victor Stinner3e1fad62017-01-17 01:29:01 +0100787 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900788 &keepends)) {
789 goto exit;
790 }
791 return_value = unicode_splitlines_impl(self, keepends);
792
793exit:
794 return return_value;
795}
796
797PyDoc_STRVAR(unicode_swapcase__doc__,
798"swapcase($self, /)\n"
799"--\n"
800"\n"
801"Convert uppercase characters to lowercase and lowercase characters to uppercase.");
802
803#define UNICODE_SWAPCASE_METHODDEF \
804 {"swapcase", (PyCFunction)unicode_swapcase, METH_NOARGS, unicode_swapcase__doc__},
805
806static PyObject *
807unicode_swapcase_impl(PyObject *self);
808
809static PyObject *
810unicode_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
811{
812 return unicode_swapcase_impl(self);
813}
814
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300815PyDoc_STRVAR(unicode_maketrans__doc__,
816"maketrans(x, y=None, z=None, /)\n"
817"--\n"
818"\n"
819"Return a translation table usable for str.translate().\n"
820"\n"
821"If there is only one argument, it must be a dictionary mapping Unicode\n"
822"ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
823"Character keys will be then converted to ordinals.\n"
824"If there are two arguments, they must be strings of equal length, and\n"
825"in the resulting dictionary, each character in x will be mapped to the\n"
826"character at the same position in y. If there is a third argument, it\n"
827"must be a string, whose characters will be mapped to None in the result.");
828
829#define UNICODE_MAKETRANS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100830 {"maketrans", (PyCFunction)unicode_maketrans, METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300831
832static PyObject *
833unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
834
835static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100836unicode_maketrans(void *null, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300837{
838 PyObject *return_value = NULL;
839 PyObject *x;
840 PyObject *y = NULL;
841 PyObject *z = NULL;
842
Victor Stinner259f0e42017-01-17 01:35:17 +0100843 if (!_PyArg_ParseStack(args, nargs, "O|UU:maketrans",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300844 &x, &y, &z)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300845 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300846 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100847
848 if (!_PyArg_NoStackKeywords("maketrans", kwnames)) {
849 goto exit;
850 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300851 return_value = unicode_maketrans_impl(x, y, z);
852
853exit:
854 return return_value;
855}
INADA Naoki3ae20562017-01-16 20:41:20 +0900856
857PyDoc_STRVAR(unicode_translate__doc__,
858"translate($self, table, /)\n"
859"--\n"
860"\n"
861"Replace each character in the string using the given translation table.\n"
862"\n"
863" table\n"
864" Translation table, which must be a mapping of Unicode ordinals to\n"
865" Unicode ordinals, strings, or None.\n"
866"\n"
867"The table must implement lookup/indexing via __getitem__, for instance a\n"
868"dictionary or list. If this operation raises LookupError, the character is\n"
869"left untouched. Characters mapped to None are deleted.");
870
871#define UNICODE_TRANSLATE_METHODDEF \
872 {"translate", (PyCFunction)unicode_translate, METH_O, unicode_translate__doc__},
873
874PyDoc_STRVAR(unicode_upper__doc__,
875"upper($self, /)\n"
876"--\n"
877"\n"
878"Return a copy of the string converted to uppercase.");
879
880#define UNICODE_UPPER_METHODDEF \
881 {"upper", (PyCFunction)unicode_upper, METH_NOARGS, unicode_upper__doc__},
882
883static PyObject *
884unicode_upper_impl(PyObject *self);
885
886static PyObject *
887unicode_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
888{
889 return unicode_upper_impl(self);
890}
891
892PyDoc_STRVAR(unicode_zfill__doc__,
893"zfill($self, width, /)\n"
894"--\n"
895"\n"
896"Pad a numeric string with zeros on the left, to fill a field of the given width.\n"
897"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900898"The string is never truncated.");
INADA Naoki3ae20562017-01-16 20:41:20 +0900899
900#define UNICODE_ZFILL_METHODDEF \
901 {"zfill", (PyCFunction)unicode_zfill, METH_O, unicode_zfill__doc__},
902
903static PyObject *
904unicode_zfill_impl(PyObject *self, Py_ssize_t width);
905
906static PyObject *
907unicode_zfill(PyObject *self, PyObject *arg)
908{
909 PyObject *return_value = NULL;
910 Py_ssize_t width;
911
912 if (!PyArg_Parse(arg, "n:zfill", &width)) {
913 goto exit;
914 }
915 return_value = unicode_zfill_impl(self, width);
916
917exit:
918 return return_value;
919}
920
921PyDoc_STRVAR(unicode___format____doc__,
922"__format__($self, format_spec, /)\n"
923"--\n"
924"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900925"Return a formatted version of the string as described by format_spec.");
INADA Naoki3ae20562017-01-16 20:41:20 +0900926
927#define UNICODE___FORMAT___METHODDEF \
928 {"__format__", (PyCFunction)unicode___format__, METH_O, unicode___format____doc__},
929
930static PyObject *
931unicode___format___impl(PyObject *self, PyObject *format_spec);
932
933static PyObject *
934unicode___format__(PyObject *self, PyObject *arg)
935{
936 PyObject *return_value = NULL;
937 PyObject *format_spec;
938
939 if (!PyArg_Parse(arg, "U:__format__", &format_spec)) {
940 goto exit;
941 }
942 return_value = unicode___format___impl(self, format_spec);
943
944exit:
945 return return_value;
946}
947
948PyDoc_STRVAR(unicode_sizeof__doc__,
949"__sizeof__($self, /)\n"
950"--\n"
951"\n"
952"Return the size of the string in memory, in bytes.");
953
954#define UNICODE_SIZEOF_METHODDEF \
955 {"__sizeof__", (PyCFunction)unicode_sizeof, METH_NOARGS, unicode_sizeof__doc__},
956
957static PyObject *
958unicode_sizeof_impl(PyObject *self);
959
960static PyObject *
961unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
962{
963 return unicode_sizeof_impl(self);
964}
Martin Panter91a88662017-01-24 00:30:06 +0000965/*[clinic end generated code: output=88b06f61edd282f9 input=a9049054013a1b77]*/