summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 0fb7658..e98c658 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1148,6 +1148,30 @@ bytearray_count(PyByteArrayObject *self, PyObject *args)
return count_obj;
}
+PyDoc_STRVAR(clear__doc__,
+"B.clear() -> None\n\
+\n\
+Remove all items from B.");
+
+static PyObject *
+bytearray_clear(PyByteArrayObject *self)
+{
+ if (PyByteArray_Resize((PyObject *)self, 0) < 0)
+ return NULL;
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(copy__doc__,
+"B.copy() -> bytearray\n\
+\n\
+Return a copy of B.");
+
+static PyObject *
+bytearray_copy(PyByteArrayObject *self)
+{
+ return PyByteArray_FromStringAndSize(PyByteArray_AS_STRING((PyObject *)self),
+ PyByteArray_GET_SIZE(self));
+}
PyDoc_STRVAR(index__doc__,
"B.index(sub[, start[, end]]) -> int\n\
@@ -2439,7 +2463,7 @@ If the argument is omitted, strip trailing ASCII whitespace.");
static PyObject *
bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
{
- Py_ssize_t left, right, mysize, argsize;
+ Py_ssize_t right, mysize, argsize;
void *myptr, *argptr;
PyObject *arg = Py_None;
Py_buffer varg;
@@ -2457,11 +2481,10 @@ bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
}
myptr = self->ob_bytes;
mysize = Py_SIZE(self);
- left = 0;
right = rstrip_helper(myptr, mysize, argptr, argsize);
if (arg != Py_None)
PyBuffer_Release(&varg);
- return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left);
+ return PyByteArray_FromStringAndSize(self->ob_bytes, right);
}
PyDoc_STRVAR(decode_doc,
@@ -2731,6 +2754,8 @@ bytearray_methods[] = {
{"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
_Py_capitalize__doc__},
{"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__},
+ {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, clear__doc__},
+ {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, copy__doc__},
{"count", (PyCFunction)bytearray_count, METH_VARARGS, count__doc__},
{"decode", (PyCFunction)bytearray_decode, METH_VARARGS | METH_KEYWORDS, decode_doc},
{"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, endswith__doc__},