@@ -59,14 +59,21 @@ int _PyUnicode_IsLinebreak(register const Py_UNICODE ch)
5959/* Returns the titlecase Unicode characters corresponding to ch or just
6060 ch if no titlecase mapping is known. */
6161
62- Py_UNICODE _PyUnicode_ToTitlecase (register const Py_UNICODE ch )
62+ Py_UNICODE _PyUnicode_ToTitlecase (register Py_UNICODE ch )
6363{
6464 const _PyUnicode_TypeRecord * ctype = gettyperecord (ch );
6565
6666 if (ctype -> title )
67- return ch + ctype -> title ;
68-
69- return ch + ctype -> upper ;
67+ ch += ctype -> title ;
68+ else
69+ ch += ctype -> upper ;
70+
71+ #ifdef USE_UCS4_STORAGE
72+ /* The database assumes that the values wrap around at 0x10000. */
73+ if (ch > 0x10000 )
74+ ch -= 0x10000 ;
75+ #endif
76+ return ch ;
7077}
7178
7279/* Returns 1 for Unicode characters having the category 'Lt', 0
@@ -348,21 +355,33 @@ int _PyUnicode_IsUppercase(register const Py_UNICODE ch)
348355/* Returns the uppercase Unicode characters corresponding to ch or just
349356 ch if no uppercase mapping is known. */
350357
351- Py_UNICODE _PyUnicode_ToUppercase (register const Py_UNICODE ch )
358+ Py_UNICODE _PyUnicode_ToUppercase (register Py_UNICODE ch )
352359{
353360 const _PyUnicode_TypeRecord * ctype = gettyperecord (ch );
354361
355- return ch + ctype -> upper ;
362+ ch += ctype -> upper ;
363+ #ifdef USE_UCS4_STORAGE
364+ /* The database assumes that the values wrap around at 0x10000. */
365+ if (ch > 0x10000 )
366+ ch -= 0x10000 ;
367+ #endif
368+ return ch ;
356369}
357370
358371/* Returns the lowercase Unicode characters corresponding to ch or just
359372 ch if no lowercase mapping is known. */
360373
361- Py_UNICODE _PyUnicode_ToLowercase (register const Py_UNICODE ch )
374+ Py_UNICODE _PyUnicode_ToLowercase (register Py_UNICODE ch )
362375{
363376 const _PyUnicode_TypeRecord * ctype = gettyperecord (ch );
364377
365- return ch + ctype -> lower ;
378+ ch += ctype -> lower ;
379+ #ifdef USE_UCS4_STORAGE
380+ /* The database assumes that the values wrap around at 0x10000. */
381+ if (ch > 0x10000 )
382+ ch -= 0x10000 ;
383+ #endif
384+ return ch ;
366385}
367386
368387/* Returns 1 for Unicode characters having the category 'Ll', 'Lu', 'Lt',
0 commit comments