gh-94808: Cover PyUnicode_Count in CAPI (#96929)

This commit is contained in:
Nikita Sobolev 2022-10-06 18:20:22 +03:00 committed by GitHub
parent e39ae6bef2
commit e63d7dae90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

View file

@ -223,6 +223,26 @@ unicode_asutf8andsize(PyObject *self, PyObject *args)
return Py_BuildValue("(Nn)", result, utf8_len);
}
static PyObject *
unicode_count(PyObject *self, PyObject *args)
{
PyObject *str;
PyObject *substr;
Py_ssize_t result;
Py_ssize_t start, end;
if (!PyArg_ParseTuple(args, "UUnn:unicode_count", &str, &substr,
&start, &end)) {
return NULL;
}
result = PyUnicode_Count(str, substr, start, end);
if (result == -1)
return NULL;
else
return PyLong_FromSsize_t(result);
}
static PyObject *
unicode_findchar(PyObject *self, PyObject *args)
{
@ -696,6 +716,7 @@ static PyMethodDef TestMethods[] = {
{"unicode_asucs4", unicode_asucs4, METH_VARARGS},
{"unicode_asutf8", unicode_asutf8, METH_VARARGS},
{"unicode_asutf8andsize", unicode_asutf8andsize, METH_VARARGS},
{"unicode_count", unicode_count, METH_VARARGS},
{"unicode_findchar", unicode_findchar, METH_VARARGS},
{"unicode_copycharacters", unicode_copycharacters, METH_VARARGS},
{NULL},