diff options
author | Xiang Zhang <angwerzx@126.com> | 2016-12-20 14:52:33 (GMT) |
---|---|---|
committer | Xiang Zhang <angwerzx@126.com> | 2016-12-20 14:52:33 (GMT) |
commit | b211068f5c8e2535ab2dd7f4c43325bbf5b30fad (patch) | |
tree | d18683bf67a43286f7184b39a8e3b49f036cc466 /Modules/_testcapimodule.c | |
parent | 38f225dd486ab69779eab3cae4fa2375f6c2d8d6 (diff) | |
download | cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.zip cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.tar.gz cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.tar.bz2 |
Issue #28822: Adjust indices handling of PyUnicode_FindChar().
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 8d4346c..ef5f9d4 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1888,6 +1888,27 @@ unicode_asucs4(PyObject *self, PyObject *args) } static PyObject * +unicode_findchar(PyObject *self, PyObject *args) +{ + PyObject *str; + int direction; + unsigned int ch; + Py_ssize_t result; + Py_ssize_t start, end; + + if (!PyArg_ParseTuple(args, "UInni:unicode_findchar", &str, &ch, + &start, &end, &direction)) { + return NULL; + } + + result = PyUnicode_FindChar(str, (Py_UCS4)ch, start, end, direction); + if (result == -2) + return NULL; + else + return PyLong_FromSsize_t(result); +} + +static PyObject * unicode_copycharacters(PyObject *self, PyObject *args) { PyObject *from, *to, *to_copy; @@ -4121,6 +4142,7 @@ static PyMethodDef TestMethods[] = { {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS}, {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, + {"unicode_findchar", unicode_findchar, METH_VARARGS}, {"unicode_copycharacters", unicode_copycharacters, METH_VARARGS}, {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS}, {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VARARGS}, |