gh-110289: C API: Add PyUnicode_EqualToUTF8() and PyUnicode_EqualToUTF8AndSize() functions (GH-110297)

This commit is contained in:
Serhiy Storchaka 2023-10-11 16:41:58 +03:00 committed by GitHub
parent d1f7fae424
commit eb50cd37ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 280 additions and 0 deletions

View file

@ -1396,6 +1396,28 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
:c:func:`PyErr_Occurred` to check for errors.
.. c:function:: int PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *string, Py_ssize_t size)
Compare a Unicode object with a char buffer which is interpreted as
being UTF-8 or ASCII encoded and return true (``1``) if they are equal,
or false (``0``) otherwise.
If the Unicode object contains surrogate characters or
the C string is not valid UTF-8, false (``0``) is returned.
This function does not raise exceptions.
.. versionadded:: 3.13
.. c:function:: int PyUnicode_EqualToUTF8(PyObject *unicode, const char *string)
Similar to :c:func:`PyUnicode_EqualToUTF8AndSize`, but compute *string*
length using :c:func:`!strlen`.
If the Unicode object contains null characters, false (``0``) is returned.
.. versionadded:: 3.13
.. c:function:: int PyUnicode_CompareWithASCIIString(PyObject *uni, const char *string)
Compare a Unicode object, *uni*, with *string* and return ``-1``, ``0``, ``1`` for less