test('capitalize', ' hello ', ' hello ')
test('capitalize', 'hello ', 'Hello ')
+
+ test('count', 'aaa', 3, 'a')
+ test('count', 'aaa', 0, 'b')
+
test('find', 'abcdefghiabc', 0, 'abc')
test('find', 'abcdefghiabc', 9, 'abc', 1)
test('find', 'abcdefghiabc', -1, 'def', 4)
test('capitalize', u' hello ', u' hello ')
test('capitalize', u'hello ', u'Hello ')
+test('count', u'aaa', 3, u'a')
+test('count', u'aaa', 0, u'b')
+test('count', 'aaa', 3, u'a')
+test('count', 'aaa', 0, u'b')
+test('count', u'aaa', 3, 'a')
+test('count', u'aaa', 0, 'b')
+
test('title', u' hello ', u' Hello ')
test('title', u'hello ', u'Hello ')
test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')
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;
x = Py_None;
Py_INCREF(x);
} else
- goto onError;
+ goto onError;
}
/* Apply mapping */
(targetsize << 2);
extrachars += needed;
if (_PyUnicode_Resize(v, PyUnicode_GET_SIZE(v) + needed)) {
- Py_DECREF(x);
- goto onError;
- }
+ Py_DECREF(x);
+ goto onError;
+ }
p = PyUnicode_AS_UNICODE(v) + oldpos;
}
Py_UNICODE_COPY(p,
x = Py_None;
Py_INCREF(x);
} else
- goto onError;
+ goto onError;
}
/* Apply mapping */
(targetsize << 2);
extrachars += needed;
if (_PyString_Resize(&v, PyString_GET_SIZE(v) + needed)) {
- Py_DECREF(x);
- goto onError;
- }
+ Py_DECREF(x);
+ goto onError;
+ }
s = PyString_AS_STRING(v) + oldpos;
}
memcpy(s,
{
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);