Skip to content

Commit

Permalink
support 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkovsky committed Oct 16, 2024
1 parent 707713a commit 55f1ba7
Show file tree
Hide file tree
Showing 3 changed files with 6,782 additions and 4 deletions.
51 changes: 48 additions & 3 deletions lib/cyac/unicode_portability.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,53 @@ extern "C" {
return 1;
}
}
# elif PY_MINOR_VERSION >= 13
#define Py_BUILD_CORE
#include <internal/pycore_unicodeobject.h>
#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13
typedef struct {
/*
These are either deltas to the character or offsets in
_PyUnicode_ExtendedCase.
*/
const int upper;
const int lower;
const int title;
/* Note if more flag space is needed, decimal and digit could be unified. */
const unsigned char decimal;
const unsigned char digit;
const unsigned short flags;
} _PyUnicode_TypeRecord;

#define EXTENDED_CASE_MASK 0x4000
#include "./unicodetype_db.h"
static const _PyUnicode_TypeRecord *
gettyperecord(Py_UCS4 code)
{
int index;

if (code >= 0x110000)
index = 0;
else
{
index = index1[(code>>SHIFT)];
index = index2[(index<<SHIFT)+(code&((1<<SHIFT)-1))];
}

return &_PyUnicode_TypeRecords[index];
}

static int _PyUnicode_ToLowerFull(Py_UCS4 ch, Py_UCS4 *res)
{
const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);

if (ctype->flags & EXTENDED_CASE_MASK) {
int index = ctype->lower & 0xFFFF;
int n = ctype->lower >> 24;
int i;
for (i = 0; i < n; i++)
res[i] = _PyUnicode_ExtendedCase[index + i];
return n;
}
res[0] = ch + ctype->lower;
return 1;
}
#endif
#endif
Loading

0 comments on commit 55f1ba7

Please sign in to comment.