summaryrefslogtreecommitdiffstats
path: root/Objects/clinic/unicodeobject.c.h
diff options
context:
space:
mode:
authorsweeneyde <36520290+sweeneyde@users.noreply.github.com>2020-04-22 21:05:48 (GMT)
committerGitHub <noreply@github.com>2020-04-22 21:05:48 (GMT)
commita81849b0315277bb3937271174aaaa5059c0b445 (patch)
tree8184e6ab012aa217b5cc1bb242efc6aed531db7d /Objects/clinic/unicodeobject.c.h
parent39652cd8bdf7c82b7c6055089a4ed90ee546a448 (diff)
downloadcpython-a81849b0315277bb3937271174aaaa5059c0b445.zip
cpython-a81849b0315277bb3937271174aaaa5059c0b445.tar.gz
cpython-a81849b0315277bb3937271174aaaa5059c0b445.tar.bz2
bpo-39939: Add str.removeprefix and str.removesuffix (GH-18939)
Added str.removeprefix and str.removesuffix methods and corresponding bytes, bytearray, and collections.UserString methods to remove affixes from a string if present. See PEP 616 for a full description.
Diffstat (limited to 'Objects/clinic/unicodeobject.c.h')
-rw-r--r--Objects/clinic/unicodeobject.c.h73
1 files changed, 72 insertions, 1 deletions
diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h
index 0d13406..cf81df4 100644
--- a/Objects/clinic/unicodeobject.c.h
+++ b/Objects/clinic/unicodeobject.c.h
@@ -754,6 +754,77 @@ exit:
return return_value;
}
+PyDoc_STRVAR(unicode_removeprefix__doc__,
+"removeprefix($self, prefix, /)\n"
+"--\n"
+"\n"
+"Return a str with the given prefix string removed if present.\n"
+"\n"
+"If the string starts with the prefix string, return string[len(prefix):].\n"
+"Otherwise, return a copy of the original string.");
+
+#define UNICODE_REMOVEPREFIX_METHODDEF \
+ {"removeprefix", (PyCFunction)unicode_removeprefix, METH_O, unicode_removeprefix__doc__},
+
+static PyObject *
+unicode_removeprefix_impl(PyObject *self, PyObject *prefix);
+
+static PyObject *
+unicode_removeprefix(PyObject *self, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ PyObject *prefix;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("removeprefix", "argument", "str", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg) == -1) {
+ goto exit;
+ }
+ prefix = arg;
+ return_value = unicode_removeprefix_impl(self, prefix);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(unicode_removesuffix__doc__,
+"removesuffix($self, suffix, /)\n"
+"--\n"
+"\n"
+"Return a str with the given suffix string removed if present.\n"
+"\n"
+"If the string ends with the suffix string and that suffix is not empty,\n"
+"return string[:-len(suffix)]. Otherwise, return a copy of the original\n"
+"string.");
+
+#define UNICODE_REMOVESUFFIX_METHODDEF \
+ {"removesuffix", (PyCFunction)unicode_removesuffix, METH_O, unicode_removesuffix__doc__},
+
+static PyObject *
+unicode_removesuffix_impl(PyObject *self, PyObject *suffix);
+
+static PyObject *
+unicode_removesuffix(PyObject *self, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ PyObject *suffix;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("removesuffix", "argument", "str", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg) == -1) {
+ goto exit;
+ }
+ suffix = arg;
+ return_value = unicode_removesuffix_impl(self, suffix);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(unicode_rjust__doc__,
"rjust($self, width, fillchar=\' \', /)\n"
"--\n"
@@ -1232,4 +1303,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return unicode_sizeof_impl(self);
}
-/*[clinic end generated code: output=e4ed33400979c7e8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b91233f3722643be input=a9049054013a1b77]*/