diff options
author | Guido van Rossum <guido@python.org> | 2000-03-07 15:53:43 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-03-07 15:53:43 +0000 |
commit | 1d5ec0dfc68c23ace2e29a8a3788cc17d80621d2 (patch) | |
tree | b6824997a991b6e94e74403a1dc1461bb9afebf8 /Objects/stringobject.c | |
parent | 61bfc6ac93db9bf11c88f549c9122ac5b498e3d6 (diff) | |
download | cpython-1d5ec0dfc68c23ace2e29a8a3788cc17d80621d2.tar.gz |
Patch by Moshe Zadka: move the string special case from abstract.c
here.
[Patch modified by GvR to keep the original exception.]
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index bc1bb41538..77c08dd749 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -381,6 +381,27 @@ string_slice(a, i, j) return PyString_FromStringAndSize(a->ob_sval + i, (int) (j-i)); } +static int +string_contains(a, el) +PyObject *a, *el; +{ + register char *s, *end; + register char c; + if (!PyString_Check(el) || PyString_Size(el) != 1) { + PyErr_SetString(PyExc_TypeError, + "string member test needs char left operand"); + return -1; + } + c = PyString_AsString(el)[0]; + s = PyString_AsString(a); + end = s + PyString_Size(a); + while (s < end) { + if (c == *s++) + return 1; + } + return 0; +} + static PyObject * string_item(a, i) PyStringObject *a; @@ -516,6 +537,7 @@ static PySequenceMethods string_as_sequence = { (intintargfunc)string_slice, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ + (objobjproc)string_contains /*sq_contains*/ }; static PyBufferProcs string_as_buffer = { |