@@ -9,8 +9,53 @@ extern "C" {
99 return 1 ;
1010 }
1111}
12- # elif PY_MINOR_VERSION >= 13
13- #define Py_BUILD_CORE
14- #include <internal/pycore_unicodeobject.h>
12+ #elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13
13+ typedef struct {
14+ /*
15+ These are either deltas to the character or offsets in
16+ _PyUnicode_ExtendedCase.
17+ */
18+ const int upper ;
19+ const int lower ;
20+ const int title ;
21+ /* Note if more flag space is needed, decimal and digit could be unified. */
22+ const unsigned char decimal ;
23+ const unsigned char digit ;
24+ const unsigned short flags ;
25+ } _PyUnicode_TypeRecord ;
26+
27+ #define EXTENDED_CASE_MASK 0x4000
28+ #include "./unicodetype_db.h"
29+ static const _PyUnicode_TypeRecord *
30+ gettyperecord (Py_UCS4 code )
31+ {
32+ int index ;
33+
34+ if (code >= 0x110000 )
35+ index = 0 ;
36+ else
37+ {
38+ index = index1 [(code >>SHIFT )];
39+ index = index2 [(index <<SHIFT )+ (code & ((1 <<SHIFT )- 1 ))];
40+ }
41+
42+ return & _PyUnicode_TypeRecords [index ];
43+ }
44+
45+ static int _PyUnicode_ToLowerFull (Py_UCS4 ch , Py_UCS4 * res )
46+ {
47+ const _PyUnicode_TypeRecord * ctype = gettyperecord (ch );
48+
49+ if (ctype -> flags & EXTENDED_CASE_MASK ) {
50+ int index = ctype -> lower & 0xFFFF ;
51+ int n = ctype -> lower >> 24 ;
52+ int i ;
53+ for (i = 0 ; i < n ; i ++ )
54+ res [i ] = _PyUnicode_ExtendedCase [index + i ];
55+ return n ;
56+ }
57+ res [0 ] = ch + ctype -> lower ;
58+ return 1 ;
59+ }
1560#endif
1661#endif
0 commit comments