summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2007-11-16 18:04:14 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2007-11-16 18:04:14 (GMT)
commit57d5669f4be86fcaf21f95436fcd5142ffe5efae (patch)
tree332a4d0e4f0069b55af028ade293def34622954f /Objects/stringobject.c
parent5397fd1a51d2f5bbb9ca1f5a385538e6072ced26 (diff)
downloadcpython-57d5669f4be86fcaf21f95436fcd5142ffe5efae.zip
cpython-57d5669f4be86fcaf21f95436fcd5142ffe5efae.tar.gz
cpython-57d5669f4be86fcaf21f95436fcd5142ffe5efae.tar.bz2
Now in find, rfind, index, and rindex, you can use None as defaults,
as usual with slicing (both with str and unicode strings). This fixes issue 1259. For str only the stringobject.c file was modified. But for unicode, I needed to repeat in the four functions a lot of code, so created a new function that does part of the job for them (and placed it in find.h, following a suggestion of Barry). Also added tests for this behaviour.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index ce24154..a0e2837 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -1880,10 +1880,21 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
const char *sub;
Py_ssize_t sub_len;
Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
+ PyObject *obj_start=Py_None, *obj_end=Py_None;
- if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!PyArg_ParseTuple(args, "O|OO:find/rfind/index/rindex", &subobj,
+ &obj_start, &obj_end))
return -2;
+ /* To support None in "start" and "end" arguments, meaning
+ the same as if they were not passed.
+ */
+ if (obj_start != Py_None)
+ if (!_PyEval_SliceIndex(obj_start, &start))
+ return -2;
+ if (obj_end != Py_None)
+ if (!_PyEval_SliceIndex(obj_end, &end))
+ return -2;
+
if (PyString_Check(subobj)) {
sub = PyString_AS_STRING(subobj);
sub_len = PyString_GET_SIZE(subobj);