Extract hexadecimal constants from enums

This commit is contained in:
Dietrich Epp 2022-04-01 12:17:43 -04:00
parent 4b20b30330
commit 39ebe32975
2 changed files with 82 additions and 5 deletions

View File

@ -39,3 +39,80 @@ kTextEncodingMacRomanian,38
kTextEncodingMacCeltic,39
kTextEncodingMacGaelic,40
kTextEncodingMacKeyboardGlyphs,41
kTextEncodingMacRSymbol,8
kTextEncodingMacUninterp,32
kTextEncodingMacUkrainian,152
kTextEncodingUnicodeDefault,256
kTextEncodingUnicodeV1_1,257
kTextEncodingISO10646_1993,257
kTextEncodingUnicodeV2_0,259
kTextEncodingUnicodeV2_1,259
kTextEncodingUnicodeV3_0,260
kTextEncodingUnicodeV3_1,261
kTextEncodingUnicodeV3_2,262
kTextEncodingISOLatin1,513
kTextEncodingISOLatin2,514
kTextEncodingISOLatin3,515
kTextEncodingISOLatin4,516
kTextEncodingISOLatinCyrillic,517
kTextEncodingISOLatinArabic,518
kTextEncodingISOLatinGreek,519
kTextEncodingISOLatinHebrew,520
kTextEncodingISOLatin5,521
kTextEncodingDOSLatinUS,1024
kTextEncodingDOSGreek,1029
kTextEncodingDOSBalticRim,1030
kTextEncodingDOSLatin1,1040
kTextEncodingDOSGreek1,1041
kTextEncodingDOSLatin2,1042
kTextEncodingDOSCyrillic,1043
kTextEncodingDOSTurkish,1044
kTextEncodingDOSPortuguese,1045
kTextEncodingDOSIcelandic,1046
kTextEncodingDOSHebrew,1047
kTextEncodingDOSCanadianFrench,1048
kTextEncodingDOSArabic,1049
kTextEncodingDOSJapanese,1056
kTextEncodingDOSChineseSimplif,1057
kTextEncodingDOSKorean,1058
kTextEncodingDOSChineseTrad,1059
kTextEncodingWindowsLatin1,1280
kTextEncodingWindowsANSI,1280
kTextEncodingWindowsLatin2,1281
kTextEncodingWindowsCyrillic,1282
kTextEncodingWindowsGreek,1283
kTextEncodingWindowsLatin5,1284
kTextEncodingWindowsHebrew,1285
kTextEncodingWindowsArabic,1286
kTextEncodingWindowsBalticRim,1287
kTextEncodingWindowsVietnamese,1288
kTextEncodingWindowsKoreanJohab,1296
kTextEncodingUS_ASCII,1536
kTextEncodingJIS_X0201_76,1568
kTextEncodingJIS_X0208_83,1569
kTextEncodingJIS_X0208_90,1570
kTextEncodingJIS_X0212_90,1571
kTextEncodingJIS_C6226_78,1572
kTextEncodingGB_2312_80,1584
kTextEncodingGBK_95,1585
kTextEncodingKSC_5601_87,1600
kTextEncodingKSC_5601_92_Johab,1601
kTextEncodingCNS_11643_92_P1,1617
kTextEncodingCNS_11643_92_P2,1618
kTextEncodingCNS_11643_92_P3,1619
kTextEncodingISO_2022_JP,2080
kTextEncodingISO_2022_JP_2,2081
kTextEncodingISO_2022_JP_1,2082
kTextEncodingISO_2022_CN,2096
kTextEncodingISO_2022_CN_EXT,2097
kTextEncodingISO_2022_KR,2112
kTextEncodingEUC_JP,2336
kTextEncodingEUC_CN,2352
kTextEncodingEUC_TW,2353
kTextEncodingEUC_KR,2368
kTextEncodingDefaultVariant,0
kTextEncodingDefaultFormat,0
kTextEncodingFullName,0
kTextEncodingBaseName,1
kTextEncodingVariantName,2
kTextEncodingFormatName,3

1 Name Value
39 kTextEncodingMacCeltic 39
40 kTextEncodingMacGaelic 40
41 kTextEncodingMacKeyboardGlyphs 41
42 kTextEncodingMacRSymbol 8
43 kTextEncodingMacUninterp 32
44 kTextEncodingMacUkrainian 152
45 kTextEncodingUnicodeDefault 256
46 kTextEncodingUnicodeV1_1 257
47 kTextEncodingISO10646_1993 257
48 kTextEncodingUnicodeV2_0 259
49 kTextEncodingUnicodeV2_1 259
50 kTextEncodingUnicodeV3_0 260
51 kTextEncodingUnicodeV3_1 261
52 kTextEncodingUnicodeV3_2 262
53 kTextEncodingISOLatin1 513
54 kTextEncodingISOLatin2 514
55 kTextEncodingISOLatin3 515
56 kTextEncodingISOLatin4 516
57 kTextEncodingISOLatinCyrillic 517
58 kTextEncodingISOLatinArabic 518
59 kTextEncodingISOLatinGreek 519
60 kTextEncodingISOLatinHebrew 520
61 kTextEncodingISOLatin5 521
62 kTextEncodingDOSLatinUS 1024
63 kTextEncodingDOSGreek 1029
64 kTextEncodingDOSBalticRim 1030
65 kTextEncodingDOSLatin1 1040
66 kTextEncodingDOSGreek1 1041
67 kTextEncodingDOSLatin2 1042
68 kTextEncodingDOSCyrillic 1043
69 kTextEncodingDOSTurkish 1044
70 kTextEncodingDOSPortuguese 1045
71 kTextEncodingDOSIcelandic 1046
72 kTextEncodingDOSHebrew 1047
73 kTextEncodingDOSCanadianFrench 1048
74 kTextEncodingDOSArabic 1049
75 kTextEncodingDOSJapanese 1056
76 kTextEncodingDOSChineseSimplif 1057
77 kTextEncodingDOSKorean 1058
78 kTextEncodingDOSChineseTrad 1059
79 kTextEncodingWindowsLatin1 1280
80 kTextEncodingWindowsANSI 1280
81 kTextEncodingWindowsLatin2 1281
82 kTextEncodingWindowsCyrillic 1282
83 kTextEncodingWindowsGreek 1283
84 kTextEncodingWindowsLatin5 1284
85 kTextEncodingWindowsHebrew 1285
86 kTextEncodingWindowsArabic 1286
87 kTextEncodingWindowsBalticRim 1287
88 kTextEncodingWindowsVietnamese 1288
89 kTextEncodingWindowsKoreanJohab 1296
90 kTextEncodingUS_ASCII 1536
91 kTextEncodingJIS_X0201_76 1568
92 kTextEncodingJIS_X0208_83 1569
93 kTextEncodingJIS_X0208_90 1570
94 kTextEncodingJIS_X0212_90 1571
95 kTextEncodingJIS_C6226_78 1572
96 kTextEncodingGB_2312_80 1584
97 kTextEncodingGBK_95 1585
98 kTextEncodingKSC_5601_87 1600
99 kTextEncodingKSC_5601_92_Johab 1601
100 kTextEncodingCNS_11643_92_P1 1617
101 kTextEncodingCNS_11643_92_P2 1618
102 kTextEncodingCNS_11643_92_P3 1619
103 kTextEncodingISO_2022_JP 2080
104 kTextEncodingISO_2022_JP_2 2081
105 kTextEncodingISO_2022_JP_1 2082
106 kTextEncodingISO_2022_CN 2096
107 kTextEncodingISO_2022_CN_EXT 2097
108 kTextEncodingISO_2022_KR 2112
109 kTextEncodingEUC_JP 2336
110 kTextEncodingEUC_CN 2352
111 kTextEncodingEUC_TW 2353
112 kTextEncodingEUC_KR 2368
113 kTextEncodingDefaultVariant 0
114 kTextEncodingDefaultFormat 0
115 kTextEncodingFullName 0
116 kTextEncodingBaseName 1
117 kTextEncodingVariantName 2
118 kTextEncodingFormatName 3

View File

@ -12,9 +12,11 @@ def list_enums(filename: str) -> Iterator[Item]:
"""List enum definitions in a file."""
with open(filename, 'rb') as fp:
data = fp.read()
for item in re.finditer(rb'^\s*(\w+)\s*=\s*(\d+)', data, re.MULTILINE):
for item in re.finditer(
rb'^\s*(\w+)\s*=\s*((?:0x)?\d+)u?l?\b',
data, re.MULTILINE | re.IGNORECASE):
name, value = item.groups()
yield name.decode('ASCII'), int(value)
yield name.decode('ASCII'), int(value, 0)
def index_of(data: List[Item], key: str) -> int:
for i, (name, _) in enumerate(data):
@ -49,9 +51,7 @@ def process_textcommon(filename: str) -> None:
for name, value in list_enums(filename):
if name.startswith('kTextEncoding'):
encodings.append((name, value))
write_csv('encoding.csv',
slice(encodings, 'kTextEncodingMacRoman',
'kTextEncodingMacKeyboardGlyphs'))
write_csv('encoding.csv', encodings)
def process(filename: str) -> None:
name = os.path.basename(filename).lower()