blob: 8072516a8a36d142f1408e065cc626006460e4e2 [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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020080unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
INADA Naoki3ae20562017-01-16 20:41:20 +090081{
82 PyObject *return_value = NULL;
83 Py_ssize_t width;
84 Py_UCS4 fillchar = ' ';
85
Sylvain74453812017-06-10 06:51:48 +020086 if (!_PyArg_ParseStack(args, nargs, "n|O&:center",
87 &width, convert_uc, &fillchar)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010088 goto exit;
89 }
INADA Naoki3ae20562017-01-16 20:41:20 +090090 return_value = unicode_center_impl(self, width, fillchar);
91
92exit:
93 return return_value;
94}
95
96PyDoc_STRVAR(unicode_encode__doc__,
97"encode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
98"--\n"
99"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900100"Encode the string using the codec registered for encoding.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900101"\n"
102" encoding\n"
103" The encoding in which to encode the string.\n"
104" errors\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900105" The error handling scheme to use for encoding errors.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900106" The default is \'strict\' meaning that encoding errors raise a\n"
107" UnicodeEncodeError. Other possible values are \'ignore\', \'replace\' and\n"
108" \'xmlcharrefreplace\' as well as any other name registered with\n"
109" codecs.register_error that can handle UnicodeEncodeErrors.");
110
111#define UNICODE_ENCODE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300112 {"encode", (PyCFunction)unicode_encode, METH_FASTCALL|METH_KEYWORDS, unicode_encode__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900113
114static PyObject *
115unicode_encode_impl(PyObject *self, const char *encoding, const char *errors);
116
117static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200118unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900119{
120 PyObject *return_value = NULL;
121 static const char * const _keywords[] = {"encoding", "errors", NULL};
122 static _PyArg_Parser _parser = {"|ss:encode", _keywords, 0};
123 const char *encoding = NULL;
124 const char *errors = NULL;
125
Victor Stinner3e1fad62017-01-17 01:29:01 +0100126 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900127 &encoding, &errors)) {
128 goto exit;
129 }
130 return_value = unicode_encode_impl(self, encoding, errors);
131
132exit:
133 return return_value;
134}
135
136PyDoc_STRVAR(unicode_expandtabs__doc__,
137"expandtabs($self, /, tabsize=8)\n"
138"--\n"
139"\n"
140"Return a copy where all tab characters are expanded using spaces.\n"
141"\n"
142"If tabsize is not given, a tab size of 8 characters is assumed.");
143
144#define UNICODE_EXPANDTABS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300145 {"expandtabs", (PyCFunction)unicode_expandtabs, METH_FASTCALL|METH_KEYWORDS, unicode_expandtabs__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900146
147static PyObject *
148unicode_expandtabs_impl(PyObject *self, int tabsize);
149
150static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200151unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900152{
153 PyObject *return_value = NULL;
154 static const char * const _keywords[] = {"tabsize", NULL};
155 static _PyArg_Parser _parser = {"|i:expandtabs", _keywords, 0};
156 int tabsize = 8;
157
Victor Stinner3e1fad62017-01-17 01:29:01 +0100158 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900159 &tabsize)) {
160 goto exit;
161 }
162 return_value = unicode_expandtabs_impl(self, tabsize);
163
164exit:
165 return return_value;
166}
167
INADA Naokia49ac992018-01-27 14:06:21 +0900168PyDoc_STRVAR(unicode_isascii__doc__,
169"isascii($self, /)\n"
170"--\n"
171"\n"
172"Return True if all characters in the string are ASCII, False otherwise.\n"
173"\n"
174"ASCII characters have code points in the range U+0000-U+007F.\n"
175"Empty string is ASCII too.");
176
177#define UNICODE_ISASCII_METHODDEF \
178 {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__},
179
180static PyObject *
181unicode_isascii_impl(PyObject *self);
182
183static PyObject *
184unicode_isascii(PyObject *self, PyObject *Py_UNUSED(ignored))
185{
186 return unicode_isascii_impl(self);
187}
188
INADA Naoki3ae20562017-01-16 20:41:20 +0900189PyDoc_STRVAR(unicode_islower__doc__,
190"islower($self, /)\n"
191"--\n"
192"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900193"Return True if the string is a lowercase string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900194"\n"
195"A string is lowercase if all cased characters in the string are lowercase and\n"
196"there is at least one cased character in the string.");
197
198#define UNICODE_ISLOWER_METHODDEF \
199 {"islower", (PyCFunction)unicode_islower, METH_NOARGS, unicode_islower__doc__},
200
201static PyObject *
202unicode_islower_impl(PyObject *self);
203
204static PyObject *
205unicode_islower(PyObject *self, PyObject *Py_UNUSED(ignored))
206{
207 return unicode_islower_impl(self);
208}
209
210PyDoc_STRVAR(unicode_isupper__doc__,
211"isupper($self, /)\n"
212"--\n"
213"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900214"Return True if the string is an uppercase string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900215"\n"
216"A string is uppercase if all cased characters in the string are uppercase and\n"
217"there is at least one cased character in the string.");
218
219#define UNICODE_ISUPPER_METHODDEF \
220 {"isupper", (PyCFunction)unicode_isupper, METH_NOARGS, unicode_isupper__doc__},
221
222static PyObject *
223unicode_isupper_impl(PyObject *self);
224
225static PyObject *
226unicode_isupper(PyObject *self, PyObject *Py_UNUSED(ignored))
227{
228 return unicode_isupper_impl(self);
229}
230
231PyDoc_STRVAR(unicode_istitle__doc__,
232"istitle($self, /)\n"
233"--\n"
234"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900235"Return True if the string is a title-cased string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900236"\n"
237"In a title-cased string, upper- and title-case characters may only\n"
238"follow uncased characters and lowercase characters only cased ones.");
239
240#define UNICODE_ISTITLE_METHODDEF \
241 {"istitle", (PyCFunction)unicode_istitle, METH_NOARGS, unicode_istitle__doc__},
242
243static PyObject *
244unicode_istitle_impl(PyObject *self);
245
246static PyObject *
247unicode_istitle(PyObject *self, PyObject *Py_UNUSED(ignored))
248{
249 return unicode_istitle_impl(self);
250}
251
252PyDoc_STRVAR(unicode_isspace__doc__,
253"isspace($self, /)\n"
254"--\n"
255"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900256"Return True if the string is a whitespace string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900257"\n"
258"A string is whitespace if all characters in the string are whitespace and there\n"
259"is at least one character in the string.");
260
261#define UNICODE_ISSPACE_METHODDEF \
262 {"isspace", (PyCFunction)unicode_isspace, METH_NOARGS, unicode_isspace__doc__},
263
264static PyObject *
265unicode_isspace_impl(PyObject *self);
266
267static PyObject *
268unicode_isspace(PyObject *self, PyObject *Py_UNUSED(ignored))
269{
270 return unicode_isspace_impl(self);
271}
272
273PyDoc_STRVAR(unicode_isalpha__doc__,
274"isalpha($self, /)\n"
275"--\n"
276"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900277"Return True if the string is an alphabetic string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900278"\n"
279"A string is alphabetic if all characters in the string are alphabetic and there\n"
280"is at least one character in the string.");
281
282#define UNICODE_ISALPHA_METHODDEF \
283 {"isalpha", (PyCFunction)unicode_isalpha, METH_NOARGS, unicode_isalpha__doc__},
284
285static PyObject *
286unicode_isalpha_impl(PyObject *self);
287
288static PyObject *
289unicode_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored))
290{
291 return unicode_isalpha_impl(self);
292}
293
294PyDoc_STRVAR(unicode_isalnum__doc__,
295"isalnum($self, /)\n"
296"--\n"
297"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900298"Return True if the string is an alpha-numeric string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900299"\n"
300"A string is alpha-numeric if all characters in the string are alpha-numeric and\n"
301"there is at least one character in the string.");
302
303#define UNICODE_ISALNUM_METHODDEF \
304 {"isalnum", (PyCFunction)unicode_isalnum, METH_NOARGS, unicode_isalnum__doc__},
305
306static PyObject *
307unicode_isalnum_impl(PyObject *self);
308
309static PyObject *
310unicode_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored))
311{
312 return unicode_isalnum_impl(self);
313}
314
315PyDoc_STRVAR(unicode_isdecimal__doc__,
316"isdecimal($self, /)\n"
317"--\n"
318"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900319"Return True if the string is a decimal string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900320"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900321"A string is a decimal string if all characters in the string are decimal and\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900322"there is at least one character in the string.");
323
324#define UNICODE_ISDECIMAL_METHODDEF \
325 {"isdecimal", (PyCFunction)unicode_isdecimal, METH_NOARGS, unicode_isdecimal__doc__},
326
327static PyObject *
328unicode_isdecimal_impl(PyObject *self);
329
330static PyObject *
331unicode_isdecimal(PyObject *self, PyObject *Py_UNUSED(ignored))
332{
333 return unicode_isdecimal_impl(self);
334}
335
336PyDoc_STRVAR(unicode_isdigit__doc__,
337"isdigit($self, /)\n"
338"--\n"
339"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900340"Return True if the string is a digit string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900341"\n"
342"A string is a digit string if all characters in the string are digits and there\n"
343"is at least one character in the string.");
344
345#define UNICODE_ISDIGIT_METHODDEF \
346 {"isdigit", (PyCFunction)unicode_isdigit, METH_NOARGS, unicode_isdigit__doc__},
347
348static PyObject *
349unicode_isdigit_impl(PyObject *self);
350
351static PyObject *
352unicode_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored))
353{
354 return unicode_isdigit_impl(self);
355}
356
357PyDoc_STRVAR(unicode_isnumeric__doc__,
358"isnumeric($self, /)\n"
359"--\n"
360"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900361"Return True if the string is a numeric string, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900362"\n"
363"A string is numeric if all characters in the string are numeric and there is at\n"
364"least one character in the string.");
365
366#define UNICODE_ISNUMERIC_METHODDEF \
367 {"isnumeric", (PyCFunction)unicode_isnumeric, METH_NOARGS, unicode_isnumeric__doc__},
368
369static PyObject *
370unicode_isnumeric_impl(PyObject *self);
371
372static PyObject *
373unicode_isnumeric(PyObject *self, PyObject *Py_UNUSED(ignored))
374{
375 return unicode_isnumeric_impl(self);
376}
377
378PyDoc_STRVAR(unicode_isidentifier__doc__,
379"isidentifier($self, /)\n"
380"--\n"
381"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900382"Return True if the string is a valid Python identifier, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900383"\n"
384"Use keyword.iskeyword() to test for reserved identifiers such as \"def\" and\n"
385"\"class\".");
386
387#define UNICODE_ISIDENTIFIER_METHODDEF \
388 {"isidentifier", (PyCFunction)unicode_isidentifier, METH_NOARGS, unicode_isidentifier__doc__},
389
390static PyObject *
391unicode_isidentifier_impl(PyObject *self);
392
393static PyObject *
394unicode_isidentifier(PyObject *self, PyObject *Py_UNUSED(ignored))
395{
396 return unicode_isidentifier_impl(self);
397}
398
399PyDoc_STRVAR(unicode_isprintable__doc__,
400"isprintable($self, /)\n"
401"--\n"
402"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900403"Return True if the string is printable, False otherwise.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900404"\n"
405"A string is printable if all of its characters are considered printable in\n"
406"repr() or if it is empty.");
407
408#define UNICODE_ISPRINTABLE_METHODDEF \
409 {"isprintable", (PyCFunction)unicode_isprintable, METH_NOARGS, unicode_isprintable__doc__},
410
411static PyObject *
412unicode_isprintable_impl(PyObject *self);
413
414static PyObject *
415unicode_isprintable(PyObject *self, PyObject *Py_UNUSED(ignored))
416{
417 return unicode_isprintable_impl(self);
418}
419
420PyDoc_STRVAR(unicode_join__doc__,
421"join($self, iterable, /)\n"
422"--\n"
423"\n"
424"Concatenate any number of strings.\n"
425"\n"
Martin Panter91a88662017-01-24 00:30:06 +0000426"The string whose method is called is inserted in between each given string.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900427"The result is returned as a new string.\n"
428"\n"
429"Example: \'.\'.join([\'ab\', \'pq\', \'rs\']) -> \'ab.pq.rs\'");
430
431#define UNICODE_JOIN_METHODDEF \
432 {"join", (PyCFunction)unicode_join, METH_O, unicode_join__doc__},
433
434PyDoc_STRVAR(unicode_ljust__doc__,
435"ljust($self, width, fillchar=\' \', /)\n"
436"--\n"
437"\n"
438"Return a left-justified string of length width.\n"
439"\n"
440"Padding is done using the specified fill character (default is a space).");
441
442#define UNICODE_LJUST_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100443 {"ljust", (PyCFunction)unicode_ljust, METH_FASTCALL, unicode_ljust__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900444
445static PyObject *
446unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
447
448static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200449unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
INADA Naoki3ae20562017-01-16 20:41:20 +0900450{
451 PyObject *return_value = NULL;
452 Py_ssize_t width;
453 Py_UCS4 fillchar = ' ';
454
Sylvain74453812017-06-10 06:51:48 +0200455 if (!_PyArg_ParseStack(args, nargs, "n|O&:ljust",
456 &width, convert_uc, &fillchar)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100457 goto exit;
458 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900459 return_value = unicode_ljust_impl(self, width, fillchar);
460
461exit:
462 return return_value;
463}
464
465PyDoc_STRVAR(unicode_lower__doc__,
466"lower($self, /)\n"
467"--\n"
468"\n"
469"Return a copy of the string converted to lowercase.");
470
471#define UNICODE_LOWER_METHODDEF \
472 {"lower", (PyCFunction)unicode_lower, METH_NOARGS, unicode_lower__doc__},
473
474static PyObject *
475unicode_lower_impl(PyObject *self);
476
477static PyObject *
478unicode_lower(PyObject *self, PyObject *Py_UNUSED(ignored))
479{
480 return unicode_lower_impl(self);
481}
482
483PyDoc_STRVAR(unicode_strip__doc__,
484"strip($self, chars=None, /)\n"
485"--\n"
486"\n"
Victor Stinner0c4a8282017-01-17 02:21:47 +0100487"Return a copy of the string with leading and trailing whitespace remove.\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900488"\n"
489"If chars is given and not None, remove characters in chars instead.");
490
491#define UNICODE_STRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100492 {"strip", (PyCFunction)unicode_strip, METH_FASTCALL, unicode_strip__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900493
494static PyObject *
495unicode_strip_impl(PyObject *self, PyObject *chars);
496
497static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200498unicode_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
INADA Naoki3ae20562017-01-16 20:41:20 +0900499{
500 PyObject *return_value = NULL;
501 PyObject *chars = Py_None;
502
Sylvain74453812017-06-10 06:51:48 +0200503 if (!_PyArg_UnpackStack(args, nargs, "strip",
504 0, 1,
505 &chars)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100506 goto exit;
507 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900508 return_value = unicode_strip_impl(self, chars);
509
510exit:
511 return return_value;
512}
513
514PyDoc_STRVAR(unicode_lstrip__doc__,
515"lstrip($self, chars=None, /)\n"
516"--\n"
517"\n"
518"Return a copy of the string with leading whitespace removed.\n"
519"\n"
520"If chars is given and not None, remove characters in chars instead.");
521
522#define UNICODE_LSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100523 {"lstrip", (PyCFunction)unicode_lstrip, METH_FASTCALL, unicode_lstrip__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900524
525static PyObject *
526unicode_lstrip_impl(PyObject *self, PyObject *chars);
527
528static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200529unicode_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
INADA Naoki3ae20562017-01-16 20:41:20 +0900530{
531 PyObject *return_value = NULL;
532 PyObject *chars = NULL;
533
Sylvain74453812017-06-10 06:51:48 +0200534 if (!_PyArg_UnpackStack(args, nargs, "lstrip",
535 0, 1,
536 &chars)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100537 goto exit;
538 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900539 return_value = unicode_lstrip_impl(self, chars);
540
541exit:
542 return return_value;
543}
544
545PyDoc_STRVAR(unicode_rstrip__doc__,
546"rstrip($self, chars=None, /)\n"
547"--\n"
548"\n"
549"Return a copy of the string with trailing whitespace removed.\n"
550"\n"
551"If chars is given and not None, remove characters in chars instead.");
552
553#define UNICODE_RSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100554 {"rstrip", (PyCFunction)unicode_rstrip, METH_FASTCALL, unicode_rstrip__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900555
556static PyObject *
557unicode_rstrip_impl(PyObject *self, PyObject *chars);
558
559static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200560unicode_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
INADA Naoki3ae20562017-01-16 20:41:20 +0900561{
562 PyObject *return_value = NULL;
563 PyObject *chars = NULL;
564
Sylvain74453812017-06-10 06:51:48 +0200565 if (!_PyArg_UnpackStack(args, nargs, "rstrip",
566 0, 1,
567 &chars)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100568 goto exit;
569 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900570 return_value = unicode_rstrip_impl(self, chars);
571
572exit:
573 return return_value;
574}
575
576PyDoc_STRVAR(unicode_replace__doc__,
577"replace($self, old, new, count=-1, /)\n"
578"--\n"
579"\n"
580"Return a copy with all occurrences of substring old replaced by new.\n"
581"\n"
582" count\n"
583" Maximum number of occurrences to replace.\n"
584" -1 (the default value) means replace all occurrences.\n"
585"\n"
586"If the optional argument count is given, only the first count occurrences are\n"
587"replaced.");
588
589#define UNICODE_REPLACE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100590 {"replace", (PyCFunction)unicode_replace, METH_FASTCALL, unicode_replace__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900591
592static PyObject *
593unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new,
594 Py_ssize_t count);
595
596static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200597unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
INADA Naoki3ae20562017-01-16 20:41:20 +0900598{
599 PyObject *return_value = NULL;
600 PyObject *old;
601 PyObject *new;
602 Py_ssize_t count = -1;
603
Sylvain74453812017-06-10 06:51:48 +0200604 if (!_PyArg_ParseStack(args, nargs, "UU|n:replace",
605 &old, &new, &count)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100606 goto exit;
607 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900608 return_value = unicode_replace_impl(self, old, new, count);
609
610exit:
611 return return_value;
612}
613
614PyDoc_STRVAR(unicode_rjust__doc__,
615"rjust($self, width, fillchar=\' \', /)\n"
616"--\n"
617"\n"
618"Return a right-justified string of length width.\n"
619"\n"
620"Padding is done using the specified fill character (default is a space).");
621
622#define UNICODE_RJUST_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100623 {"rjust", (PyCFunction)unicode_rjust, METH_FASTCALL, unicode_rjust__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900624
625static PyObject *
626unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
627
628static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200629unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
INADA Naoki3ae20562017-01-16 20:41:20 +0900630{
631 PyObject *return_value = NULL;
632 Py_ssize_t width;
633 Py_UCS4 fillchar = ' ';
634
Sylvain74453812017-06-10 06:51:48 +0200635 if (!_PyArg_ParseStack(args, nargs, "n|O&:rjust",
636 &width, convert_uc, &fillchar)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100637 goto exit;
638 }
INADA Naoki3ae20562017-01-16 20:41:20 +0900639 return_value = unicode_rjust_impl(self, width, fillchar);
640
641exit:
642 return return_value;
643}
644
645PyDoc_STRVAR(unicode_split__doc__,
646"split($self, /, sep=None, maxsplit=-1)\n"
647"--\n"
648"\n"
649"Return a list of the words in the string, using sep as the delimiter string.\n"
650"\n"
651" sep\n"
652" The delimiter according which to split the string.\n"
653" None (the default value) means split according to any whitespace,\n"
654" and discard empty strings from the result.\n"
655" maxsplit\n"
656" Maximum number of splits to do.\n"
657" -1 (the default value) means no limit.");
658
659#define UNICODE_SPLIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300660 {"split", (PyCFunction)unicode_split, METH_FASTCALL|METH_KEYWORDS, unicode_split__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900661
662static PyObject *
663unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
664
665static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200666unicode_split(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900667{
668 PyObject *return_value = NULL;
669 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
670 static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
671 PyObject *sep = Py_None;
672 Py_ssize_t maxsplit = -1;
673
Victor Stinner3e1fad62017-01-17 01:29:01 +0100674 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900675 &sep, &maxsplit)) {
676 goto exit;
677 }
678 return_value = unicode_split_impl(self, sep, maxsplit);
679
680exit:
681 return return_value;
682}
683
684PyDoc_STRVAR(unicode_partition__doc__,
685"partition($self, sep, /)\n"
686"--\n"
687"\n"
688"Partition the string into three parts using the given separator.\n"
689"\n"
690"This will search for the separator in the string. If the separator is found,\n"
691"returns a 3-tuple containing the part before the separator, the separator\n"
692"itself, and the part after it.\n"
693"\n"
694"If the separator is not found, returns a 3-tuple containing the original string\n"
695"and two empty strings.");
696
697#define UNICODE_PARTITION_METHODDEF \
698 {"partition", (PyCFunction)unicode_partition, METH_O, unicode_partition__doc__},
699
700PyDoc_STRVAR(unicode_rpartition__doc__,
701"rpartition($self, sep, /)\n"
702"--\n"
703"\n"
704"Partition the string into three parts using the given separator.\n"
705"\n"
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300706"This will search for the separator in the string, starting at the end. If\n"
INADA Naoki3ae20562017-01-16 20:41:20 +0900707"the separator is found, returns a 3-tuple containing the part before the\n"
708"separator, the separator itself, and the part after it.\n"
709"\n"
710"If the separator is not found, returns a 3-tuple containing two empty strings\n"
711"and the original string.");
712
713#define UNICODE_RPARTITION_METHODDEF \
714 {"rpartition", (PyCFunction)unicode_rpartition, METH_O, unicode_rpartition__doc__},
715
716PyDoc_STRVAR(unicode_rsplit__doc__,
717"rsplit($self, /, sep=None, maxsplit=-1)\n"
718"--\n"
719"\n"
720"Return a list of the words in the string, using sep as the delimiter string.\n"
721"\n"
722" sep\n"
723" The delimiter according which to split the string.\n"
724" None (the default value) means split according to any whitespace,\n"
725" and discard empty strings from the result.\n"
726" maxsplit\n"
727" Maximum number of splits to do.\n"
728" -1 (the default value) means no limit.\n"
729"\n"
730"Splits are done starting at the end of the string and working to the front.");
731
732#define UNICODE_RSPLIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300733 {"rsplit", (PyCFunction)unicode_rsplit, METH_FASTCALL|METH_KEYWORDS, unicode_rsplit__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900734
735static PyObject *
736unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
737
738static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200739unicode_rsplit(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900740{
741 PyObject *return_value = NULL;
742 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
743 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
744 PyObject *sep = Py_None;
745 Py_ssize_t maxsplit = -1;
746
Victor Stinner3e1fad62017-01-17 01:29:01 +0100747 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900748 &sep, &maxsplit)) {
749 goto exit;
750 }
751 return_value = unicode_rsplit_impl(self, sep, maxsplit);
752
753exit:
754 return return_value;
755}
756
757PyDoc_STRVAR(unicode_splitlines__doc__,
758"splitlines($self, /, keepends=False)\n"
759"--\n"
760"\n"
761"Return a list of the lines in the string, breaking at line boundaries.\n"
762"\n"
763"Line breaks are not included in the resulting list unless keepends is given and\n"
764"true.");
765
766#define UNICODE_SPLITLINES_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300767 {"splitlines", (PyCFunction)unicode_splitlines, METH_FASTCALL|METH_KEYWORDS, unicode_splitlines__doc__},
INADA Naoki3ae20562017-01-16 20:41:20 +0900768
769static PyObject *
770unicode_splitlines_impl(PyObject *self, int keepends);
771
772static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200773unicode_splitlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
INADA Naoki3ae20562017-01-16 20:41:20 +0900774{
775 PyObject *return_value = NULL;
776 static const char * const _keywords[] = {"keepends", NULL};
777 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
778 int keepends = 0;
779
Victor Stinner3e1fad62017-01-17 01:29:01 +0100780 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
INADA Naoki3ae20562017-01-16 20:41:20 +0900781 &keepends)) {
782 goto exit;
783 }
784 return_value = unicode_splitlines_impl(self, keepends);
785
786exit:
787 return return_value;
788}
789
790PyDoc_STRVAR(unicode_swapcase__doc__,
791"swapcase($self, /)\n"
792"--\n"
793"\n"
794"Convert uppercase characters to lowercase and lowercase characters to uppercase.");
795
796#define UNICODE_SWAPCASE_METHODDEF \
797 {"swapcase", (PyCFunction)unicode_swapcase, METH_NOARGS, unicode_swapcase__doc__},
798
799static PyObject *
800unicode_swapcase_impl(PyObject *self);
801
802static PyObject *
803unicode_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
804{
805 return unicode_swapcase_impl(self);
806}
807
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300808PyDoc_STRVAR(unicode_maketrans__doc__,
809"maketrans(x, y=None, z=None, /)\n"
810"--\n"
811"\n"
812"Return a translation table usable for str.translate().\n"
813"\n"
814"If there is only one argument, it must be a dictionary mapping Unicode\n"
815"ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
816"Character keys will be then converted to ordinals.\n"
817"If there are two arguments, they must be strings of equal length, and\n"
818"in the resulting dictionary, each character in x will be mapped to the\n"
819"character at the same position in y. If there is a third argument, it\n"
820"must be a string, whose characters will be mapped to None in the result.");
821
822#define UNICODE_MAKETRANS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100823 {"maketrans", (PyCFunction)unicode_maketrans, METH_FASTCALL|METH_STATIC, unicode_maketrans__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300824
825static PyObject *
826unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
827
828static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200829unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300830{
831 PyObject *return_value = NULL;
832 PyObject *x;
833 PyObject *y = NULL;
834 PyObject *z = NULL;
835
Sylvain74453812017-06-10 06:51:48 +0200836 if (!_PyArg_ParseStack(args, nargs, "O|UU:maketrans",
837 &x, &y, &z)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100838 goto exit;
839 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300840 return_value = unicode_maketrans_impl(x, y, z);
841
842exit:
843 return return_value;
844}
INADA Naoki3ae20562017-01-16 20:41:20 +0900845
846PyDoc_STRVAR(unicode_translate__doc__,
847"translate($self, table, /)\n"
848"--\n"
849"\n"
850"Replace each character in the string using the given translation table.\n"
851"\n"
852" table\n"
853" Translation table, which must be a mapping of Unicode ordinals to\n"
854" Unicode ordinals, strings, or None.\n"
855"\n"
856"The table must implement lookup/indexing via __getitem__, for instance a\n"
857"dictionary or list. If this operation raises LookupError, the character is\n"
858"left untouched. Characters mapped to None are deleted.");
859
860#define UNICODE_TRANSLATE_METHODDEF \
861 {"translate", (PyCFunction)unicode_translate, METH_O, unicode_translate__doc__},
862
863PyDoc_STRVAR(unicode_upper__doc__,
864"upper($self, /)\n"
865"--\n"
866"\n"
867"Return a copy of the string converted to uppercase.");
868
869#define UNICODE_UPPER_METHODDEF \
870 {"upper", (PyCFunction)unicode_upper, METH_NOARGS, unicode_upper__doc__},
871
872static PyObject *
873unicode_upper_impl(PyObject *self);
874
875static PyObject *
876unicode_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
877{
878 return unicode_upper_impl(self);
879}
880
881PyDoc_STRVAR(unicode_zfill__doc__,
882"zfill($self, width, /)\n"
883"--\n"
884"\n"
885"Pad a numeric string with zeros on the left, to fill a field of the given width.\n"
886"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900887"The string is never truncated.");
INADA Naoki3ae20562017-01-16 20:41:20 +0900888
889#define UNICODE_ZFILL_METHODDEF \
890 {"zfill", (PyCFunction)unicode_zfill, METH_O, unicode_zfill__doc__},
891
892static PyObject *
893unicode_zfill_impl(PyObject *self, Py_ssize_t width);
894
895static PyObject *
896unicode_zfill(PyObject *self, PyObject *arg)
897{
898 PyObject *return_value = NULL;
899 Py_ssize_t width;
900
901 if (!PyArg_Parse(arg, "n:zfill", &width)) {
902 goto exit;
903 }
904 return_value = unicode_zfill_impl(self, width);
905
906exit:
907 return return_value;
908}
909
910PyDoc_STRVAR(unicode___format____doc__,
911"__format__($self, format_spec, /)\n"
912"--\n"
913"\n"
INADA Naoki15f94592017-01-16 21:49:13 +0900914"Return a formatted version of the string as described by format_spec.");
INADA Naoki3ae20562017-01-16 20:41:20 +0900915
916#define UNICODE___FORMAT___METHODDEF \
917 {"__format__", (PyCFunction)unicode___format__, METH_O, unicode___format____doc__},
918
919static PyObject *
920unicode___format___impl(PyObject *self, PyObject *format_spec);
921
922static PyObject *
923unicode___format__(PyObject *self, PyObject *arg)
924{
925 PyObject *return_value = NULL;
926 PyObject *format_spec;
927
928 if (!PyArg_Parse(arg, "U:__format__", &format_spec)) {
929 goto exit;
930 }
931 return_value = unicode___format___impl(self, format_spec);
932
933exit:
934 return return_value;
935}
936
937PyDoc_STRVAR(unicode_sizeof__doc__,
938"__sizeof__($self, /)\n"
939"--\n"
940"\n"
941"Return the size of the string in memory, in bytes.");
942
943#define UNICODE_SIZEOF_METHODDEF \
944 {"__sizeof__", (PyCFunction)unicode_sizeof, METH_NOARGS, unicode_sizeof__doc__},
945
946static PyObject *
947unicode_sizeof_impl(PyObject *self);
948
949static PyObject *
950unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
951{
952 return unicode_sizeof_impl(self);
953}
INADA Naokia49ac992018-01-27 14:06:21 +0900954/*[clinic end generated code: output=561c88c912b8fe3b input=a9049054013a1b77]*/