mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
gh-94808: Cover PyUnicode_Count
in CAPI (#96929)
This commit is contained in:
parent
e39ae6bef2
commit
e63d7dae90
2 changed files with 59 additions and 0 deletions
|
@ -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},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue