sub = PyString_AS_STRING(subobj);
n = PyString_GET_SIZE(subobj);
}
- else if (PyUnicode_Check(subobj))
- return PyInt_FromLong(
- PyUnicode_Count((PyObject *)self, subobj, i, last));
+ else if (PyUnicode_Check(subobj)) {
+ int count;
+ count = PyUnicode_Count((PyObject *)self, subobj, i, last);
+ if (count == -1)
+ return NULL;
+ else
+ return PyInt_FromLong((long) count);
+ }
else if (PyObject_AsCharBuffer(subobj, &sub, &n))
return NULL;
prefix = PyString_AS_STRING(subobj);
plen = PyString_GET_SIZE(subobj);
}
- else if (PyUnicode_Check(subobj))
- return PyInt_FromLong(
- PyUnicode_Tailmatch((PyObject *)self,
- subobj, start, end, -1));
+ else if (PyUnicode_Check(subobj)) {
+ int rc;
+ rc = PyUnicode_Tailmatch((PyObject *)self,
+ subobj, start, end, -1);
+ if (rc == -1)
+ return NULL;
+ else
+ return PyInt_FromLong((long) rc);
+ }
else if (PyObject_AsCharBuffer(subobj, &prefix, &plen))
return NULL;
suffix = PyString_AS_STRING(subobj);
slen = PyString_GET_SIZE(subobj);
}
- else if (PyUnicode_Check(subobj))
- return PyInt_FromLong(
- PyUnicode_Tailmatch((PyObject *)self,
- subobj, start, end, +1));
+ else if (PyUnicode_Check(subobj)) {
+ int rc;
+ rc = PyUnicode_Tailmatch((PyObject *)self,
+ subobj, start, end, +1);
+ if (rc == -1)
+ return NULL;
+ else
+ return PyInt_FromLong((long) rc);
+ }
else if (PyObject_AsCharBuffer(subobj, &suffix, &slen))
return NULL;
{
int count = 0;
+ if (start < 0)
+ start += self->length;
+ if (start < 0)
+ start = 0;
+ if (end > self->length)
+ end = self->length;
+ if (end < 0)
+ end += self->length;
+ if (end < 0)
+ end = 0;
+
if (substring->length == 0)
return (end - start + 1);
int sublen = substring->length;
PyObject *str;
- for (i = j = 0; i < len - sublen; ) {
+ for (i = j = 0; i <= len - sublen; ) {
if (Py_UNICODE_MATCH(self, i, substring)) {
if (maxcount-- <= 0)
break;