1
"""Script that generates the ctype.h-replacement in stringobject.c."""
3
NAMES = ("LOWER", "UPPER", "ALPHA", "DIGIT", "XDIGIT", "ALNUM", "SPACE")
6
#define FLAG_LOWER 0x01
7
#define FLAG_UPPER 0x02
8
#define FLAG_ALPHA (FLAG_LOWER|FLAG_UPPER)
9
#define FLAG_DIGIT 0x04
10
#define FLAG_ALNUM (FLAG_ALPHA|FLAG_DIGIT)
11
#define FLAG_SPACE 0x08
12
#define FLAG_XDIGIT 0x10
14
static unsigned int ctype_table[256] = {""")
20
if name in ("ALPHA", "ALNUM"):
23
method = lambda: c.isdigit() or c.upper() in "ABCDEF"
25
method = getattr(c, "is" + name.lower())
27
flags.append("FLAG_" + name)
34
print(" 0, /* 0x%x %s */" % (i, rc))
36
print(" %s, /* 0x%x %s */" % ("|".join(flags), i, rc))
38
for i in range(128, 256, 16):
39
print(" %s," % ", ".join(16*["0"]))
45
print("#define IS%s(c) (ctype_table[Py_CHARMASK(c)] & FLAG_%s)" %
51
name = "is" + name.lower()
52
print("#undef %s" % name)
53
print("#define %s(c) undefined_%s(c)" % (name, name))
56
static unsigned char ctype_tolower[256] = {""")
58
for i in range(0, 256, 8):
60
for i in range(i, i+8):
65
values.append("0x%02x" % i)
66
print(" %s," % ", ".join(values))
71
static unsigned char ctype_toupper[256] = {""")
73
for i in range(0, 256, 8):
75
for i in range(i, i+8):
80
values.append("0x%02x" % i)
81
print(" %s," % ", ".join(values))
86
#define TOLOWER(c) (ctype_tolower[Py_CHARMASK(c)])
87
#define TOUPPER(c) (ctype_toupper[Py_CHARMASK(c)])
90
#define tolower(c) undefined_tolower(c)
92
#define toupper(c) undefined_toupper(c)