mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
gh-129569: The function unicodedata.normalize() always returns built-in str (#129570)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
9bf73c032f
commit
c359fcd2f5
3 changed files with 29 additions and 5 deletions
|
|
@ -933,34 +933,34 @@ unicodedata_UCD_normalize_impl(PyObject *self, PyObject *form,
|
|||
if (PyUnicode_GET_LENGTH(input) == 0) {
|
||||
/* Special case empty input strings, since resizing
|
||||
them later would cause internal errors. */
|
||||
return Py_NewRef(input);
|
||||
return PyUnicode_FromObject(input);
|
||||
}
|
||||
|
||||
if (PyUnicode_CompareWithASCIIString(form, "NFC") == 0) {
|
||||
if (is_normalized_quickcheck(self, input,
|
||||
true, false, true) == YES) {
|
||||
return Py_NewRef(input);
|
||||
return PyUnicode_FromObject(input);
|
||||
}
|
||||
return nfc_nfkc(self, input, 0);
|
||||
}
|
||||
if (PyUnicode_CompareWithASCIIString(form, "NFKC") == 0) {
|
||||
if (is_normalized_quickcheck(self, input,
|
||||
true, true, true) == YES) {
|
||||
return Py_NewRef(input);
|
||||
return PyUnicode_FromObject(input);
|
||||
}
|
||||
return nfc_nfkc(self, input, 1);
|
||||
}
|
||||
if (PyUnicode_CompareWithASCIIString(form, "NFD") == 0) {
|
||||
if (is_normalized_quickcheck(self, input,
|
||||
false, false, true) == YES) {
|
||||
return Py_NewRef(input);
|
||||
return PyUnicode_FromObject(input);
|
||||
}
|
||||
return nfd_nfkd(self, input, 0);
|
||||
}
|
||||
if (PyUnicode_CompareWithASCIIString(form, "NFKD") == 0) {
|
||||
if (is_normalized_quickcheck(self, input,
|
||||
false, true, true) == YES) {
|
||||
return Py_NewRef(input);
|
||||
return PyUnicode_FromObject(input);
|
||||
}
|
||||
return nfd_nfkd(self, input, 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue