[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.210,2.211
Fredrik Lundh
effbot@users.sourceforge.net
Tue, 26 Jun 2001 13:01:58 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv30924/python
Modified Files:
bltinmodule.c
Log Message:
more unicode tweaks: make unichr(0xdddddddd) behave like u"\Udddddddd"
wrt surrogates. (this extends the valid range from 65535 to 1114111)
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.210
retrieving revision 2.211
diff -C2 -r2.210 -r2.211
*** bltinmodule.c 2001/06/26 17:46:10 2.210
--- bltinmodule.c 2001/06/26 20:01:56 2.211
***************
*** 309,323 ****
{
long x;
! Py_UNICODE s[1];
if (!PyArg_ParseTuple(args, "l:unichr", &x))
return NULL;
! if (x < 0 || x >= 65536) {
PyErr_SetString(PyExc_ValueError,
! "unichr() arg not in range(65536)");
return NULL;
}
- s[0] = (Py_UNICODE)x;
- return PyUnicode_FromUnicode(s, 1);
}
--- 309,334 ----
{
long x;
! Py_UNICODE s[2];
if (!PyArg_ParseTuple(args, "l:unichr", &x))
return NULL;
!
! if (x < 0 || x > 0x10ffff) {
PyErr_SetString(PyExc_ValueError,
! "unichr() arg not in range(0x10ffff)");
return NULL;
+ }
+
+ if (x <= 0xffff) {
+ /* UCS-2 character */
+ s[0] = (Py_UNICODE) x;
+ return PyUnicode_FromUnicode(s, 1);
+ } else {
+ /* 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);
}
}
***************
*** 325,329 ****
"unichr(i) -> Unicode character\n\
\n\
! Return a Unicode string of one character with ordinal i; 0 <= i < 65536.";
--- 336,340 ----
"unichr(i) -> Unicode character\n\
\n\
! Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.";