mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
574e079f17
Character classification is no longer affected by quirks of standard library implementation Lookup table for own function was generated with Python thanks to Unicode Database module from its standard library Explicitly set locale for POSIX targets was reverted to C https://forum.zdoom.org/viewtopic.php?t=65641&start=18#p1115930
53 lines
1.3 KiB
Python
Executable file
53 lines
1.3 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import os
|
|
import sys
|
|
import unicodedata
|
|
|
|
|
|
if sys.hexversion >= 0x3000000:
|
|
# noinspection PyShadowingBuiltins
|
|
unichr = chr
|
|
|
|
CHARACTER_COUNT = 65536
|
|
CHARACTER_PER_LINE = 128
|
|
CHARACTER_PER_BYTE = 8
|
|
|
|
self_path = os.path.dirname(os.path.abspath(__file__)) + os.sep
|
|
output_path = self_path + os.pardir + os.sep + os.pardir + os.sep + 'src/gamedata/fonts/myiswalpha.h'
|
|
|
|
with open(output_path, 'w') as f:
|
|
version = '%i.%i.%i' % (sys.version_info.major, sys.version_info.minor, sys.version_info.micro)
|
|
f.write('''// Generated by Python %s
|
|
|
|
#pragma once
|
|
|
|
static const uint8_t MYISWALPHA_DATA[] =
|
|
{
|
|
''' % version)
|
|
|
|
for i in range(0, CHARACTER_COUNT, CHARACTER_PER_LINE):
|
|
s = ''
|
|
|
|
for j in range(0, CHARACTER_PER_LINE, CHARACTER_PER_BYTE):
|
|
b = 0
|
|
|
|
for k in range(CHARACTER_PER_BYTE):
|
|
# noinspection PyUnboundLocalVariable
|
|
category = unicodedata.category(unichr(i + j + k))
|
|
|
|
if category[0] == 'L':
|
|
b |= 1 << k
|
|
|
|
s += '0x%02X, ' % b
|
|
|
|
s += '// %04X..%04X\n' % (i, i + CHARACTER_PER_LINE - 1)
|
|
f.write(s)
|
|
|
|
f.write('''};
|
|
|
|
inline int myiswalpha(wint_t ch)
|
|
{
|
|
return MYISWALPHA_DATA[ch / 8] & (1 << (ch & 7));
|
|
}
|
|
''')
|