diff -r 967f368b7f75 Objects/unicodeobject.c
--- a/Objects/unicodeobject.c Sun Jan 19 00:38:36 2014 +0200
+++ b/Objects/unicodeobject.c Tue Jan 21 00:57:18 2014 +0200
@@ -52,6 +52,14 @@
[clinic start generated code]*/
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
+/*[python input]
+class Py_UCS4_converter(CConverter):
+ type = 'Py_UCS4'
+ converter = 'convert_uc'
+
+[python start generated code]*/
+/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
+
/* --- Globals ------------------------------------------------------------
NOTE: In the interpreter's initialization phase, some globals are currently
@@ -10570,21 +10578,52 @@
return 1;
}
-PyDoc_STRVAR(center__doc__,
- "S.center(width[, fillchar]) -> str\n\
-\n\
-Return S centered in a string of length width. Padding is\n\
-done using the specified fill character (default is a space)");
+/*[clinic input]
+str.center as unicode_center
+
+ width: Py_ssize_t
+ fillchar: Py_UCS4(c_default="' '") = ' '
+ /
+
+Return a centered string of length width.
+
+Padding is done using the specified fill character (default is a space).
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_center__doc__,
+"center(width, fillchar=\' \')\n"
+"Return a centered string of length width.\n"
+"\n"
+"Padding is done using the specified fill character (default is a space).");
+
+#define UNICODE_CENTER_METHODDEF \
+ {"center", (PyCFunction)unicode_center, METH_VARARGS, unicode_center__doc__},
+
+static PyObject *
+unicode_center_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
static PyObject *
unicode_center(PyObject *self, PyObject *args)
{
- Py_ssize_t marg, left;
+ PyObject *return_value = NULL;
Py_ssize_t width;
Py_UCS4 fillchar = ' ';
- if (!PyArg_ParseTuple(args, "n|O&:center", &width, convert_uc, &fillchar))
- return NULL;
+ if (!PyArg_ParseTuple(args,
+ "n|O&:center",
+ &width, convert_uc, &fillchar))
+ goto exit;
+ return_value = unicode_center_impl(self, width, fillchar);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_center_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar)
+/*[clinic end generated code: checksum=cf06aa57d85fbf3ba5f797aab9c0db3f135210a1]*/
+{
+ Py_ssize_t marg, left;
if (PyUnicode_READY(self) == -1)
return NULL;
@@ -11168,51 +11207,115 @@
return result;
}
-PyDoc_STRVAR(encode__doc__,
- "S.encode(encoding='utf-8', errors='strict') -> bytes\n\
-\n\
-Encode S using the codec registered for encoding. Default encoding\n\
-is 'utf-8'. errors may be given to set a different error\n\
-handling scheme. Default is 'strict' meaning that encoding errors raise\n\
-a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\
-'xmlcharrefreplace' as well as any other name registered with\n\
-codecs.register_error that can handle UnicodeEncodeErrors.");
+/*[clinic input]
+str.encode as unicode_encode
+
+ encoding: str(c_default="NULL") = 'utf-8'
+ The encoding in which to encode the string.
+ errors: str(c_default="NULL") = 'strict'
+ The error handling scheme to use for the handling of encoding errors.
+ The default is 'strict' meaning that encoding errors raise a
+ UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
+ 'xmlcharrefreplace' as well as any other name registered with
+ codecs.register_error that can handle UnicodeEncodeErrors.
+
+Encode a string using the codec registered for encoding.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_encode__doc__,
+"encode(encoding=\'utf-8\', errors=\'strict\')\n"
+"Encode a string using the codec registered for encoding.\n"
+"\n"
+" encoding\n"
+" The encoding in which to encode the string.\n"
+" errors\n"
+" The error handling scheme to use for the handling of encoding errors.\n"
+" The default is \'strict\' meaning that encoding errors raise a\n"
+" UnicodeEncodeError. Other possible values are \'ignore\', \'replace\' and\n"
+" \'xmlcharrefreplace\' as well as any other name registered with\n"
+" codecs.register_error that can handle UnicodeEncodeErrors.");
+
+#define UNICODE_ENCODE_METHODDEF \
+ {"encode", (PyCFunction)unicode_encode, METH_VARARGS|METH_KEYWORDS, unicode_encode__doc__},
+
+static PyObject *
+unicode_encode_impl(PyObject *self, const char *encoding, const char *errors);
static PyObject *
unicode_encode(PyObject *self, PyObject *args, PyObject *kwargs)
{
- static char *kwlist[] = {"encoding", "errors", 0};
- char *encoding = NULL;
- char *errors = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:encode",
- kwlist, &encoding, &errors))
- return NULL;
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"encoding", "errors", NULL};
+ const char *encoding = NULL;
+ const char *errors = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "|ss:encode", _keywords,
+ &encoding, &errors))
+ goto exit;
+ return_value = unicode_encode_impl(self, encoding, errors);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_encode_impl(PyObject *self, const char *encoding, const char *errors)
+/*[clinic end generated code: checksum=01e318696c3032d320e3bc07ff0d54c1c4c609fa]*/
+{
return PyUnicode_AsEncodedString(self, encoding, errors);
}
-PyDoc_STRVAR(expandtabs__doc__,
- "S.expandtabs(tabsize=8) -> str\n\
-\n\
-Return a copy of S where all tab characters are expanded using spaces.\n\
-If tabsize is not given, a tab size of 8 characters is assumed.");
-
-static PyObject*
-unicode_expandtabs(PyObject *self, PyObject *args, PyObject *kwds)
+/*[clinic input]
+str.expandtabs as unicode_expandtabs
+
+ tabsize: int = 8
+
+Return a copy where all tab characters are expanded using spaces.
+
+If tabsize is not given, a tab size of 8 characters is assumed.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_expandtabs__doc__,
+"expandtabs(tabsize=8)\n"
+"Return a copy where all tab characters are expanded using spaces.\n"
+"\n"
+"If tabsize is not given, a tab size of 8 characters is assumed.");
+
+#define UNICODE_EXPANDTABS_METHODDEF \
+ {"expandtabs", (PyCFunction)unicode_expandtabs, METH_VARARGS|METH_KEYWORDS, unicode_expandtabs__doc__},
+
+static PyObject *
+unicode_expandtabs_impl(PyObject *self, int tabsize);
+
+static PyObject *
+unicode_expandtabs(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"tabsize", NULL};
+ int tabsize = 8;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "|i:expandtabs", _keywords,
+ &tabsize))
+ goto exit;
+ return_value = unicode_expandtabs_impl(self, tabsize);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_expandtabs_impl(PyObject *self, int tabsize)
+/*[clinic end generated code: checksum=ba3da0ecf16bd66b3131170836b47cbf2c484c22]*/
{
Py_ssize_t i, j, line_pos, src_len, incr;
Py_UCS4 ch;
PyObject *u;
void *src_data, *dest_data;
- static char *kwlist[] = {"tabsize", 0};
- int tabsize = 8;
int kind;
int found;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:expandtabs",
- kwlist, &tabsize))
- return NULL;
-
if (PyUnicode_READY(self) == -1)
return NULL;
@@ -11869,21 +11972,51 @@
return PyUnicode_GET_LENGTH(self);
}
-PyDoc_STRVAR(ljust__doc__,
- "S.ljust(width[, fillchar]) -> str\n\
-\n\
-Return S left-justified in a Unicode string of length width. Padding is\n\
-done using the specified fill character (default is a space).");
+/*[clinic input]
+str.ljust as unicode_ljust
+
+ width: Py_ssize_t
+ fillchar: Py_UCS4(c_default="' '") = ' '
+ /
+
+Return a left-justified string of length width.
+
+Padding is done using the specified fill character (default is a space).
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_ljust__doc__,
+"ljust(width, fillchar=\' \')\n"
+"Return a left-justified string of length width.\n"
+"\n"
+"Padding is done using the specified fill character (default is a space).");
+
+#define UNICODE_LJUST_METHODDEF \
+ {"ljust", (PyCFunction)unicode_ljust, METH_VARARGS, unicode_ljust__doc__},
+
+static PyObject *
+unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
static PyObject *
unicode_ljust(PyObject *self, PyObject *args)
{
+ PyObject *return_value = NULL;
Py_ssize_t width;
Py_UCS4 fillchar = ' ';
- if (!PyArg_ParseTuple(args, "n|O&:ljust", &width, convert_uc, &fillchar))
- return NULL;
-
+ if (!PyArg_ParseTuple(args,
+ "n|O&:ljust",
+ &width, convert_uc, &fillchar))
+ goto exit;
+ return_value = unicode_ljust_impl(self, width, fillchar);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_ljust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar)
+/*[clinic end generated code: checksum=b96e6170b02277edba34c053e69c87d6243c2305]*/
+{
if (PyUnicode_READY(self) == -1)
return NULL;
@@ -11913,9 +12046,9 @@
#define BOTHSTRIP 2
/* Arrays indexed by above */
-static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
-
-#define STRIPNAME(i) (stripformat[i]+3)
+static const char *stripfuncnames[] = {"lstrip", "rstrip", "strip"};
+
+#define STRIPNAME(i) (stripfuncnames[i])
/* externally visible for str.strip(unicode) */
PyObject *
@@ -12072,13 +12205,8 @@
static PyObject *
-do_argstrip(PyObject *self, int striptype, PyObject *args)
-{
- PyObject *sep = NULL;
-
- if (!PyArg_ParseTuple(args, stripformat[striptype], &sep))
- return NULL;
-
+do_argstrip(PyObject *self, int striptype, PyObject *sep)
+{
if (sep != NULL && sep != Py_None) {
if (PyUnicode_Check(sep))
return _PyUnicode_XStrip(self, striptype, sep);
@@ -12094,52 +12222,144 @@
}
-PyDoc_STRVAR(strip__doc__,
- "S.strip([chars]) -> str\n\
-\n\
-Return a copy of the string S with leading and trailing\n\
-whitespace removed.\n\
-If chars is given and not None, remove characters in chars instead.");
+/*[clinic input]
+str.strip as unicode_strip
+
+ chars: object = NULL
+ /
+
+Return a copy of the string with leading and trailing whitespace removed.
+
+If chars is given and not None, remove characters in chars instead.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_strip__doc__,
+"strip(chars=None)\n"
+"Return a copy of the string with leading and trailing whitespace removed.\n"
+"\n"
+"If chars is given and not None, remove characters in chars instead.");
+
+#define UNICODE_STRIP_METHODDEF \
+ {"strip", (PyCFunction)unicode_strip, METH_VARARGS, unicode_strip__doc__},
+
+static PyObject *
+unicode_strip_impl(PyObject *self, PyObject *chars);
static PyObject *
unicode_strip(PyObject *self, PyObject *args)
{
- if (PyTuple_GET_SIZE(args) == 0)
- return do_strip(self, BOTHSTRIP); /* Common case */
- else
- return do_argstrip(self, BOTHSTRIP, args);
-}
-
-
-PyDoc_STRVAR(lstrip__doc__,
- "S.lstrip([chars]) -> str\n\
-\n\
-Return a copy of the string S with leading whitespace removed.\n\
-If chars is given and not None, remove characters in chars instead.");
+ PyObject *return_value = NULL;
+ PyObject *chars = NULL;
+
+ if (!PyArg_UnpackTuple(args, "strip",
+ 0, 1,
+ &chars))
+ goto exit;
+ return_value = unicode_strip_impl(self, chars);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_strip_impl(PyObject *self, PyObject *chars)
+/*[clinic end generated code: checksum=80468df6115d55f328ff118d27d3b1880b42bb29]*/
+{
+ return do_argstrip(self, BOTHSTRIP, chars);
+}
+
+
+/*[clinic input]
+str.lstrip as unicode_lstrip
+
+ chars: object = NULL
+ /
+
+Return a copy of the string with leading whitespace removed.
+
+If chars is given and not None, remove characters in chars instead.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_lstrip__doc__,
+"lstrip(chars=None)\n"
+"Return a copy of the string with leading whitespace removed.\n"
+"\n"
+"If chars is given and not None, remove characters in chars instead.");
+
+#define UNICODE_LSTRIP_METHODDEF \
+ {"lstrip", (PyCFunction)unicode_lstrip, METH_VARARGS, unicode_lstrip__doc__},
+
+static PyObject *
+unicode_lstrip_impl(PyObject *self, PyObject *chars);
static PyObject *
unicode_lstrip(PyObject *self, PyObject *args)
{
- if (PyTuple_GET_SIZE(args) == 0)
- return do_strip(self, LEFTSTRIP); /* Common case */
- else
- return do_argstrip(self, LEFTSTRIP, args);
-}
-
-
-PyDoc_STRVAR(rstrip__doc__,
- "S.rstrip([chars]) -> str\n\
-\n\
-Return a copy of the string S with trailing whitespace removed.\n\
-If chars is given and not None, remove characters in chars instead.");
+ PyObject *return_value = NULL;
+ PyObject *chars = NULL;
+
+ if (!PyArg_UnpackTuple(args, "lstrip",
+ 0, 1,
+ &chars))
+ goto exit;
+ return_value = unicode_lstrip_impl(self, chars);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_lstrip_impl(PyObject *self, PyObject *chars)
+/*[clinic end generated code: checksum=e7fb853f69874119f2ad15c8b31ced35e0a1193c]*/
+{
+ return do_argstrip(self, LEFTSTRIP, chars);
+}
+
+
+/*[clinic input]
+str.rstrip as unicode_rstrip
+
+ chars: object = NULL
+ /
+
+Return a copy of the string with trailing whitespace removed.
+
+If chars is given and not None, remove characters in chars instead.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_rstrip__doc__,
+"rstrip(chars=None)\n"
+"Return a copy of the string with trailing whitespace removed.\n"
+"\n"
+"If chars is given and not None, remove characters in chars instead.");
+
+#define UNICODE_RSTRIP_METHODDEF \
+ {"rstrip", (PyCFunction)unicode_rstrip, METH_VARARGS, unicode_rstrip__doc__},
+
+static PyObject *
+unicode_rstrip_impl(PyObject *self, PyObject *chars);
static PyObject *
unicode_rstrip(PyObject *self, PyObject *args)
{
- if (PyTuple_GET_SIZE(args) == 0)
- return do_strip(self, RIGHTSTRIP); /* Common case */
- else
- return do_argstrip(self, RIGHTSTRIP, args);
+ PyObject *return_value = NULL;
+ PyObject *chars = NULL;
+
+ if (!PyArg_UnpackTuple(args, "rstrip",
+ 0, 1,
+ &chars))
+ goto exit;
+ return_value = unicode_rstrip_impl(self, chars);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_rstrip_impl(PyObject *self, PyObject *chars)
+/*[clinic end generated code: checksum=aeb870cf112bbcf2b06bfb19e9700feb015d422e]*/
+{
+ return do_argstrip(self, RIGHTSTRIP, chars);
}
@@ -12244,40 +12464,80 @@
return result;
}
-PyDoc_STRVAR(replace__doc__,
- "S.replace(old, new[, count]) -> str\n\
-\n\
-Return a copy of S with all occurrences of substring\n\
-old replaced by new. If the optional argument count is\n\
-given, only the first count occurrences are replaced.");
-
-static PyObject*
+/*[clinic input]
+str.replace as unicode_replace
+
+ old: object
+ new: object
+ count: Py_ssize_t = -1
+ Maximum number of occurrences to replace.
+ -1 (the default value) means replace all occurrences.
+ /
+
+Return a copy of S with all occurrences of substring old replaced by new.
+
+If the optional argument count is given, only the first count occurrences are
+replaced.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_replace__doc__,
+"replace(old, new, count=-1)\n"
+"Return a copy of S with all occurrences of substring old replaced by new.\n"
+"\n"
+" count\n"
+" Maximum number of occurrences to replace.\n"
+" -1 (the default value) means replace all occurrences.\n"
+"\n"
+"If the optional argument count is given, only the first count occurrences are\n"
+"replaced.");
+
+#define UNICODE_REPLACE_METHODDEF \
+ {"replace", (PyCFunction)unicode_replace, METH_VARARGS, unicode_replace__doc__},
+
+static PyObject *
+unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new, Py_ssize_t count);
+
+static PyObject *
unicode_replace(PyObject *self, PyObject *args)
{
- PyObject *str1;
- PyObject *str2;
- Py_ssize_t maxcount = -1;
+ PyObject *return_value = NULL;
+ PyObject *old;
+ PyObject *new;
+ Py_ssize_t count = -1;
+
+ if (!PyArg_ParseTuple(args,
+ "OO|n:replace",
+ &old, &new, &count))
+ goto exit;
+ return_value = unicode_replace_impl(self, old, new, count);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_replace_impl(PyObject *self, PyObject *old, PyObject *new, Py_ssize_t count)
+/*[clinic end generated code: checksum=e4cef72071de802cd458325bf40d45262d086cde]*/
+{
PyObject *result;
- if (!PyArg_ParseTuple(args, "OO|n:replace", &str1, &str2, &maxcount))
- return NULL;
if (PyUnicode_READY(self) == -1)
return NULL;
- str1 = PyUnicode_FromObject(str1);
- if (str1 == NULL)
- return NULL;
- str2 = PyUnicode_FromObject(str2);
- if (str2 == NULL) {
- Py_DECREF(str1);
- return NULL;
- }
- if (PyUnicode_READY(str1) == -1 || PyUnicode_READY(str2) == -1)
+ old = PyUnicode_FromObject(old);
+ if (old == NULL)
+ return NULL;
+ new = PyUnicode_FromObject(new);
+ if (new == NULL) {
+ Py_DECREF(old);
+ return NULL;
+ }
+ if (PyUnicode_READY(old) == -1 || PyUnicode_READY(new) == -1)
result = NULL;
else
- result = replace(self, str1, str2, maxcount);
-
- Py_DECREF(str1);
- Py_DECREF(str2);
+ result = replace(self, old, new, count);
+
+ Py_DECREF(old);
+ Py_DECREF(new);
return result;
}
@@ -12520,21 +12780,51 @@
return PyLong_FromSsize_t(result);
}
-PyDoc_STRVAR(rjust__doc__,
- "S.rjust(width[, fillchar]) -> str\n\
-\n\
-Return S right-justified in a string of length width. Padding is\n\
-done using the specified fill character (default is a space).");
+/*[clinic input]
+str.rjust as unicode_rjust
+
+ width: Py_ssize_t
+ fillchar: Py_UCS4(c_default="' '") = ' '
+ /
+
+Return a right-justified string of length width.
+
+Padding is done using the specified fill character (default is a space).
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_rjust__doc__,
+"rjust(width, fillchar=\' \')\n"
+"Return a right-justified string of length width.\n"
+"\n"
+"Padding is done using the specified fill character (default is a space).");
+
+#define UNICODE_RJUST_METHODDEF \
+ {"rjust", (PyCFunction)unicode_rjust, METH_VARARGS, unicode_rjust__doc__},
+
+static PyObject *
+unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar);
static PyObject *
unicode_rjust(PyObject *self, PyObject *args)
{
+ PyObject *return_value = NULL;
Py_ssize_t width;
Py_UCS4 fillchar = ' ';
- if (!PyArg_ParseTuple(args, "n|O&:rjust", &width, convert_uc, &fillchar))
- return NULL;
-
+ if (!PyArg_ParseTuple(args,
+ "n|O&:rjust",
+ &width, convert_uc, &fillchar))
+ goto exit;
+ return_value = unicode_rjust_impl(self, width, fillchar);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_rjust_impl(PyObject *self, Py_ssize_t width, Py_UCS4 fillchar)
+/*[clinic end generated code: checksum=b0ba9ae2034113c7b57503ca5b0261235af6ad1e]*/
+{
if (PyUnicode_READY(self) == -1)
return NULL;
@@ -12567,32 +12857,66 @@
return result;
}
-PyDoc_STRVAR(split__doc__,
- "S.split(sep=None, maxsplit=-1) -> list of strings\n\
-\n\
-Return a list of the words in S, using sep as the\n\
-delimiter string. If maxsplit is given, at most maxsplit\n\
-splits are done. If sep is not specified or is None, any\n\
-whitespace string is a separator and empty strings are\n\
-removed from the result.");
-
-static PyObject*
-unicode_split(PyObject *self, PyObject *args, PyObject *kwds)
-{
- static char *kwlist[] = {"sep", "maxsplit", 0};
- PyObject *substring = Py_None;
- Py_ssize_t maxcount = -1;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:split",
- kwlist, &substring, &maxcount))
- return NULL;
-
- if (substring == Py_None)
- return split(self, NULL, maxcount);
- else if (PyUnicode_Check(substring))
- return split(self, substring, maxcount);
+/*[clinic input]
+str.split as unicode_split
+
+ sep: object = None
+ The delimiter according which to split the string.
+ None (the default value) means split according to any whitespace,
+ and discard empty strings from the result.
+ maxsplit: Py_ssize_t = -1
+ Maximum number of splits to do.
+ -1 (the default value) means no limit.
+
+Return a list of the words in the string, using sep as the delimiter string.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_split__doc__,
+"split(sep=None, maxsplit=-1)\n"
+"Return a list of the words in the string, using sep as the delimiter string.\n"
+"\n"
+" sep\n"
+" The delimiter according which to split the string.\n"
+" None (the default value) means split according to any whitespace,\n"
+" and discard empty strings from the result.\n"
+" maxsplit\n"
+" Maximum number of splits to do.\n"
+" -1 (the default value) means no limit.");
+
+#define UNICODE_SPLIT_METHODDEF \
+ {"split", (PyCFunction)unicode_split, METH_VARARGS|METH_KEYWORDS, unicode_split__doc__},
+
+static PyObject *
+unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
+
+static PyObject *
+unicode_split(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"sep", "maxsplit", NULL};
+ PyObject *sep = Py_None;
+ Py_ssize_t maxsplit = -1;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "|On:split", _keywords,
+ &sep, &maxsplit))
+ goto exit;
+ return_value = unicode_split_impl(self, sep, maxsplit);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_split_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit)
+/*[clinic end generated code: checksum=c864bcbc05418a0952b6141c467ad087eb53546b]*/
+{
+ if (sep == Py_None)
+ return split(self, NULL, maxsplit);
+ else if (PyUnicode_Check(sep))
+ return split(self, sep, maxsplit);
else
- return PyUnicode_Split(self, substring, maxcount);
+ return PyUnicode_Split(self, sep, maxsplit);
}
PyObject *
@@ -12792,51 +13116,109 @@
return result;
}
-PyDoc_STRVAR(rsplit__doc__,
- "S.rsplit(sep=None, maxsplit=-1) -> list of strings\n\
-\n\
-Return a list of the words in S, using sep as the\n\
-delimiter string, starting at the end of the string and\n\
-working to the front. If maxsplit is given, at most maxsplit\n\
-splits are done. If sep is not specified, any whitespace string\n\
-is a separator.");
-
-static PyObject*
-unicode_rsplit(PyObject *self, PyObject *args, PyObject *kwds)
-{
- static char *kwlist[] = {"sep", "maxsplit", 0};
- PyObject *substring = Py_None;
- Py_ssize_t maxcount = -1;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:rsplit",
- kwlist, &substring, &maxcount))
- return NULL;
-
- if (substring == Py_None)
- return rsplit(self, NULL, maxcount);
- else if (PyUnicode_Check(substring))
- return rsplit(self, substring, maxcount);
+/*[clinic input]
+str.rsplit as unicode_rsplit = str.split
+
+Return a list of the words in the string, using sep as the delimiter string.
+
+Splits are done starting at the end of the string and working to the front.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_rsplit__doc__,
+"rsplit(sep=None, maxsplit=-1)\n"
+"Return a list of the words in the string, using sep as the delimiter string.\n"
+"\n"
+" sep\n"
+" The delimiter according which to split the string.\n"
+" None (the default value) means split according to any whitespace,\n"
+" and discard empty strings from the result.\n"
+" maxsplit\n"
+" Maximum number of splits to do.\n"
+" -1 (the default value) means no limit.\n"
+"\n"
+"Splits are done starting at the end of the string and working to the front.");
+
+#define UNICODE_RSPLIT_METHODDEF \
+ {"rsplit", (PyCFunction)unicode_rsplit, METH_VARARGS|METH_KEYWORDS, unicode_rsplit__doc__},
+
+static PyObject *
+unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit);
+
+static PyObject *
+unicode_rsplit(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"sep", "maxsplit", NULL};
+ PyObject *sep = Py_None;
+ Py_ssize_t maxsplit = -1;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "|On:rsplit", _keywords,
+ &sep, &maxsplit))
+ goto exit;
+ return_value = unicode_rsplit_impl(self, sep, maxsplit);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_rsplit_impl(PyObject *self, PyObject *sep, Py_ssize_t maxsplit)
+/*[clinic end generated code: checksum=0a69914059f7b82c7a31725b670f1ba1a6a8e06e]*/
+{
+ if (sep == Py_None)
+ return rsplit(self, NULL, maxsplit);
+ else if (PyUnicode_Check(sep))
+ return rsplit(self, sep, maxsplit);
else
- return PyUnicode_RSplit(self, substring, maxcount);
-}
-
-PyDoc_STRVAR(splitlines__doc__,
- "S.splitlines([keepends]) -> list of strings\n\
-\n\
-Return a list of the lines in S, breaking at line boundaries.\n\
-Line breaks are not included in the resulting list unless keepends\n\
-is given and true.");
-
-static PyObject*
-unicode_splitlines(PyObject *self, PyObject *args, PyObject *kwds)
-{
- static char *kwlist[] = {"keepends", 0};
+ return PyUnicode_RSplit(self, sep, maxsplit);
+}
+
+/*[clinic input]
+str.splitlines as unicode_splitlines
+
+ keepends: int(py_default="False") = 0
+
+Return a list of the lines in the string, breaking at line boundaries.
+
+Line breaks are not included in the resulting list unless keepends is given and
+true.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_splitlines__doc__,
+"splitlines(keepends=False)\n"
+"Return a list of the lines in the string, breaking at line boundaries.\n"
+"\n"
+"Line breaks are not included in the resulting list unless keepends is given and\n"
+"true.");
+
+#define UNICODE_SPLITLINES_METHODDEF \
+ {"splitlines", (PyCFunction)unicode_splitlines, METH_VARARGS|METH_KEYWORDS, unicode_splitlines__doc__},
+
+static PyObject *
+unicode_splitlines_impl(PyObject *self, int keepends);
+
+static PyObject *
+unicode_splitlines(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"keepends", NULL};
int keepends = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:splitlines",
- kwlist, &keepends))
- return NULL;
-
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "|i:splitlines", _keywords,
+ &keepends))
+ goto exit;
+ return_value = unicode_splitlines_impl(self, keepends);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_splitlines_impl(PyObject *self, int keepends)
+/*[clinic end generated code: checksum=137f0f0ce6909220248cfbbf5978b2fc11150b13]*/
+{
return PyUnicode_Splitlines(self, keepends);
}
@@ -13056,25 +13438,55 @@
return case_operation(self, do_upper);
}
-PyDoc_STRVAR(zfill__doc__,
- "S.zfill(width) -> str\n\
-\n\
-Pad a numeric string S with zeros on the left, to fill a field\n\
-of the specified width. The string S is never truncated.");
+/*[clinic input]
+str.zfill as unicode_zfill
+
+ width: Py_ssize_t
+ /
+
+Pad a numeric string with zeros on the left, to fill a field of the given width.
+
+The original string is never truncated.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode_zfill__doc__,
+"zfill(width)\n"
+"Pad a numeric string with zeros on the left, to fill a field of the given width.\n"
+"\n"
+"The original string is never truncated.");
+
+#define UNICODE_ZFILL_METHODDEF \
+ {"zfill", (PyCFunction)unicode_zfill, METH_VARARGS, unicode_zfill__doc__},
+
+static PyObject *
+unicode_zfill_impl(PyObject *self, Py_ssize_t width);
static PyObject *
unicode_zfill(PyObject *self, PyObject *args)
{
+ PyObject *return_value = NULL;
+ Py_ssize_t width;
+
+ if (!PyArg_ParseTuple(args,
+ "n:zfill",
+ &width))
+ goto exit;
+ return_value = unicode_zfill_impl(self, width);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode_zfill_impl(PyObject *self, Py_ssize_t width)
+/*[clinic end generated code: checksum=197208613420895672c88732acc58e1c8a7edc82]*/
+{
Py_ssize_t fill;
PyObject *u;
- Py_ssize_t width;
int kind;
void *data;
Py_UCS4 chr;
- if (!PyArg_ParseTuple(args, "n:zfill", &width))
- return NULL;
-
if (PyUnicode_READY(self) == -1)
return NULL;
@@ -13524,16 +13936,48 @@
Return a formatted version of S, using substitutions from mapping.\n\
The substitutions are identified by braces ('{' and '}').");
-static PyObject *
-unicode__format__(PyObject* self, PyObject* args)
-{
+/*[clinic input]
+str.__format__ as unicode__format__
+
+ format_spec: unicode
+ /
+
+Return a formatted version of S as described by format_spec.
+[clinic start generated code]*/
+
+PyDoc_STRVAR(unicode__format____doc__,
+"__format__(format_spec)\n"
+"Return a formatted version of S as described by format_spec.");
+
+#define UNICODE__FORMAT___METHODDEF \
+ {"__format__", (PyCFunction)unicode__format__, METH_VARARGS, unicode__format____doc__},
+
+static PyObject *
+unicode__format___impl(PyObject *self, PyObject *format_spec);
+
+static PyObject *
+unicode__format__(PyObject *self, PyObject *args)
+{
+ PyObject *return_value = NULL;
PyObject *format_spec;
+
+ if (!PyArg_ParseTuple(args,
+ "U:__format__",
+ &format_spec))
+ goto exit;
+ return_value = unicode__format___impl(self, format_spec);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+unicode__format___impl(PyObject *self, PyObject *format_spec)
+/*[clinic end generated code: checksum=58858973e9576869bcb320c2e53e88104dd44ef0]*/
+{
_PyUnicodeWriter writer;
int ret;
- if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
- return NULL;
-
if (PyUnicode_READY(self) == -1)
return NULL;
_PyUnicodeWriter_Init(&writer);
@@ -13547,11 +13991,6 @@
return _PyUnicodeWriter_Finish(&writer);
}
-PyDoc_STRVAR(p_format__doc__,
- "S.__format__(format_spec) -> str\n\
-\n\
-Return a formatted version of S as described by format_spec.");
-
static PyObject *
unicode__sizeof__(PyObject *v)
{
@@ -13595,32 +14034,30 @@
}
static PyMethodDef unicode_methods[] = {
- {"encode", (PyCFunction) unicode_encode, METH_VARARGS | METH_KEYWORDS, encode__doc__},
- {"replace", (PyCFunction) unicode_replace, METH_VARARGS, replace__doc__},
- {"split", (PyCFunction) unicode_split, METH_VARARGS | METH_KEYWORDS, split__doc__},
- {"rsplit", (PyCFunction) unicode_rsplit, METH_VARARGS | METH_KEYWORDS, rsplit__doc__},
+ UNICODE_ENCODE_METHODDEF
+ UNICODE_REPLACE_METHODDEF
+ UNICODE_SPLIT_METHODDEF
+ UNICODE_RSPLIT_METHODDEF
{"join", (PyCFunction) unicode_join, METH_O, join__doc__},
{"capitalize", (PyCFunction) unicode_capitalize, METH_NOARGS, capitalize__doc__},
{"casefold", (PyCFunction) unicode_casefold, METH_NOARGS, casefold__doc__},
{"title", (PyCFunction) unicode_title, METH_NOARGS, title__doc__},
- {"center", (PyCFunction) unicode_center, METH_VARARGS, center__doc__},
+ UNICODE_CENTER_METHODDEF
{"count", (PyCFunction) unicode_count, METH_VARARGS, count__doc__},
- {"expandtabs", (PyCFunction) unicode_expandtabs,
- METH_VARARGS | METH_KEYWORDS, expandtabs__doc__},
+ UNICODE_EXPANDTABS_METHODDEF
{"find", (PyCFunction) unicode_find, METH_VARARGS, find__doc__},
{"partition", (PyCFunction) unicode_partition, METH_O, partition__doc__},
{"index", (PyCFunction) unicode_index, METH_VARARGS, index__doc__},
- {"ljust", (PyCFunction) unicode_ljust, METH_VARARGS, ljust__doc__},
+ UNICODE_LJUST_METHODDEF
{"lower", (PyCFunction) unicode_lower, METH_NOARGS, lower__doc__},
- {"lstrip", (PyCFunction) unicode_lstrip, METH_VARARGS, lstrip__doc__},
+ UNICODE_LSTRIP_METHODDEF
{"rfind", (PyCFunction) unicode_rfind, METH_VARARGS, rfind__doc__},
{"rindex", (PyCFunction) unicode_rindex, METH_VARARGS, rindex__doc__},
- {"rjust", (PyCFunction) unicode_rjust, METH_VARARGS, rjust__doc__},
- {"rstrip", (PyCFunction) unicode_rstrip, METH_VARARGS, rstrip__doc__},
+ UNICODE_RJUST_METHODDEF
+ UNICODE_RSTRIP_METHODDEF
{"rpartition", (PyCFunction) unicode_rpartition, METH_O, rpartition__doc__},
- {"splitlines", (PyCFunction) unicode_splitlines,
- METH_VARARGS | METH_KEYWORDS, splitlines__doc__},
- {"strip", (PyCFunction) unicode_strip, METH_VARARGS, strip__doc__},
+ UNICODE_SPLITLINES_METHODDEF
+ UNICODE_STRIP_METHODDEF
{"swapcase", (PyCFunction) unicode_swapcase, METH_NOARGS, swapcase__doc__},
{"translate", (PyCFunction) unicode_translate, METH_O, translate__doc__},
{"upper", (PyCFunction) unicode_upper, METH_NOARGS, upper__doc__},
@@ -13637,10 +14074,10 @@
{"isalnum", (PyCFunction) unicode_isalnum, METH_NOARGS, isalnum__doc__},
{"isidentifier", (PyCFunction) unicode_isidentifier, METH_NOARGS, isidentifier__doc__},
{"isprintable", (PyCFunction) unicode_isprintable, METH_NOARGS, isprintable__doc__},
- {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__},
+ UNICODE_ZFILL_METHODDEF
{"format", (PyCFunction) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__},
{"format_map", (PyCFunction) do_string_format_map, METH_O, format_map__doc__},
- {"__format__", (PyCFunction) unicode__format__, METH_VARARGS, p_format__doc__},
+ UNICODE__FORMAT___METHODDEF
UNICODE_MAKETRANS_METHODDEF
{"__sizeof__", (PyCFunction) unicode__sizeof__, METH_NOARGS, sizeof__doc__},
#if 0