summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-10-11 13:41:58 (GMT)
committerGitHub <noreply@github.com>2023-10-11 13:41:58 (GMT)
commiteb50cd37eac47dd4dc71ab42d0582dfb6eac4515 (patch)
tree410d6c0c88cb2c223cace999b490a6adce642e8f /Modules
parentd1f7fae424d51b0374c8204599583c4a26c1a992 (diff)
downloadcpython-eb50cd37eac47dd4dc71ab42d0582dfb6eac4515.zip
cpython-eb50cd37eac47dd4dc71ab42d0582dfb6eac4515.tar.gz
cpython-eb50cd37eac47dd4dc71ab42d0582dfb6eac4515.tar.bz2
gh-110289: C API: Add PyUnicode_EqualToUTF8() and PyUnicode_EqualToUTF8AndSize() functions (GH-110297)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapi/unicode.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/Modules/_testcapi/unicode.c b/Modules/_testcapi/unicode.c
index 232b2ad..d52d88a 100644
--- a/Modules/_testcapi/unicode.c
+++ b/Modules/_testcapi/unicode.c
@@ -1429,6 +1429,48 @@ unicode_comparewithasciistring(PyObject *self, PyObject *args)
return PyLong_FromLong(result);
}
+/* Test PyUnicode_EqualToUTF8() */
+static PyObject *
+unicode_equaltoutf8(PyObject *self, PyObject *args)
+{
+ PyObject *left;
+ const char *right = NULL;
+ Py_ssize_t right_len;
+ int result;
+
+ if (!PyArg_ParseTuple(args, "Oz#", &left, &right, &right_len)) {
+ return NULL;
+ }
+
+ NULLABLE(left);
+ result = PyUnicode_EqualToUTF8(left, right);
+ assert(!PyErr_Occurred());
+ return PyLong_FromLong(result);
+}
+
+/* Test PyUnicode_EqualToUTF8AndSize() */
+static PyObject *
+unicode_equaltoutf8andsize(PyObject *self, PyObject *args)
+{
+ PyObject *left;
+ const char *right = NULL;
+ Py_ssize_t right_len;
+ Py_ssize_t size = -100;
+ int result;
+
+ if (!PyArg_ParseTuple(args, "Oz#|n", &left, &right, &right_len, &size)) {
+ return NULL;
+ }
+
+ NULLABLE(left);
+ if (size == -100) {
+ size = right_len;
+ }
+ result = PyUnicode_EqualToUTF8AndSize(left, right, size);
+ assert(!PyErr_Occurred());
+ return PyLong_FromLong(result);
+}
+
/* Test PyUnicode_RichCompare() */
static PyObject *
unicode_richcompare(PyObject *self, PyObject *args)
@@ -2044,6 +2086,8 @@ static PyMethodDef TestMethods[] = {
{"unicode_replace", unicode_replace, METH_VARARGS},
{"unicode_compare", unicode_compare, METH_VARARGS},
{"unicode_comparewithasciistring",unicode_comparewithasciistring,METH_VARARGS},
+ {"unicode_equaltoutf8", unicode_equaltoutf8, METH_VARARGS},
+ {"unicode_equaltoutf8andsize",unicode_equaltoutf8andsize, METH_VARARGS},
{"unicode_richcompare", unicode_richcompare, METH_VARARGS},
{"unicode_format", unicode_format, METH_VARARGS},
{"unicode_contains", unicode_contains, METH_VARARGS},