diff options
author | Guido van Rossum <guido@python.org> | 2000-03-07 15:53:43 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-03-07 15:53:43 (GMT) |
commit | 9284a572bc22c31a965ebc03d428ec6145f70c73 (patch) | |
tree | dbeb759653d5b46ada514357c3124a88f30b8016 /Objects/stringobject.c | |
parent | da2361ac1df04934246c4e7d22cf0951b75836c4 (diff) | |
download | cpython-9284a572bc22c31a965ebc03d428ec6145f70c73.zip cpython-9284a572bc22c31a965ebc03d428ec6145f70c73.tar.gz cpython-9284a572bc22c31a965ebc03d428ec6145f70c73.tar.bz2 |
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 bc1bb41..77c08dd 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 = { |