mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
Support using UCS-4 as the Py_UNICODE type:
Add configure option --enable-unicode. Add config.h macros Py_USING_UNICODE, PY_UNICODE_TYPE, Py_UNICODE_SIZE, SIZEOF_WCHAR_T. Define Py_UCS2. Encode and decode large UTF-8 characters into single Py_UNICODE values for wide Unicode types; likewise for UTF-16. Remove test whether sizeof Py_UNICODE is two.
This commit is contained in:
parent
ff1cc902fe
commit
0ba70cc3c8
7 changed files with 667 additions and 473 deletions
|
@ -324,12 +324,16 @@ builtin_unichr(PyObject *self, PyObject *args)
|
|||
s[0] = (Py_UNICODE) x;
|
||||
return PyUnicode_FromUnicode(s, 1);
|
||||
} else {
|
||||
#if Py_UNICODE_SIZE == 2
|
||||
/* UCS-4 character. store as two surrogate characters */
|
||||
x -= 0x10000L;
|
||||
s[0] = 0xD800 + (Py_UNICODE) (x >> 10);
|
||||
s[1] = 0xDC00 + (Py_UNICODE) (x & 0x03FF);
|
||||
return PyUnicode_FromUnicode(s, 2);
|
||||
#endif
|
||||
}
|
||||
s[0] = (Py_UNICODE)x;
|
||||
return PyUnicode_FromUnicode(s, 1);
|
||||
}
|
||||
|
||||
static char unichr_doc[] =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue