| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import os |
| 21 |
import sys |
| 22 |
import ucd |
| 23 |
|
| 24 |
ucd_rootdir = sys.argv[1] |
| 25 |
emoji_rootdir = 'data/emoji' |
| 26 |
csur_rootdir = 'data/csur' |
| 27 |
|
| 28 |
null = ucd.CodePoint('0000') |
| 29 |
|
| 30 |
properties = [ |
| 31 |
(ucd_rootdir, 'PropList'), |
| 32 |
(ucd_rootdir, 'DerivedCoreProperties'), |
| 33 |
(emoji_rootdir, 'emoji-data'), |
| 34 |
('data/espeak-ng', 'PropList') |
| 35 |
] |
| 36 |
|
| 37 |
unicode_chars = {} |
| 38 |
for data in ucd.parse_ucd_data(ucd_rootdir, 'UnicodeData'): |
| 39 |
for codepoint in data['CodePoint']: |
| 40 |
unicode_chars[codepoint] = data |
| 41 |
for propdir, propfile in properties: |
| 42 |
for data in ucd.parse_ucd_data(propdir, propfile): |
| 43 |
for codepoint in data['Range']: |
| 44 |
try: |
| 45 |
unicode_chars[codepoint][data['Property']] = 1 |
| 46 |
except KeyError: |
| 47 |
unicode_chars[codepoint] = {'CodePoint': codepoint} |
| 48 |
unicode_chars[codepoint][data['Property']] = 1 |
| 49 |
for data in ucd.parse_ucd_data(ucd_rootdir, 'Scripts'): |
| 50 |
for codepoint in data['Range']: |
| 51 |
unicode_chars[codepoint]['Script'] = data['Script'] |
| 52 |
if '--with-csur' in sys.argv: |
| 53 |
for csur in ['Klingon']: |
| 54 |
for data in ucd.parse_ucd_data('data/csur', csur): |
| 55 |
for codepoint in data['CodePoint']: |
| 56 |
unicode_chars[codepoint] = data |
| 57 |
|
| 58 |
def iscntrl(data): |
| 59 |
return 1 if data.get('Name', '') == '<control>' else 0 |
| 60 |
|
| 61 |
def isdigit(data): |
| 62 |
return 1 if data['CodePoint'].char() in '0123456789' else 0 |
| 63 |
|
| 64 |
def isxdigit(data): |
| 65 |
return 1 if data['CodePoint'].char() in '0123456789ABCDEFabcdef' else 0 |
| 66 |
|
| 67 |
def isspace(data): |
| 68 |
if data.get('White_Space', 0): |
| 69 |
dt = data.get('DecompositionType', '') |
| 70 |
return 1 if dt == None or not dt.startswith('<noBreak>') else 0 |
| 71 |
else: |
| 72 |
return 0 |
| 73 |
|
| 74 |
def isblank(data): |
| 75 |
if data.get('GeneralCategory', 'Cn') == 'Zs' or data['CodePoint'].char() == '\t': |
| 76 |
dt = data.get('DecompositionType', '') |
| 77 |
return 1 if dt == None or not dt.startswith('<noBreak>') else 0 |
| 78 |
else: |
| 79 |
return 0 |
| 80 |
|
| 81 |
def ispunct(data): |
| 82 |
return 1 if isgraph(data) and not isalnum(data) else 0 |
| 83 |
|
| 84 |
def isprint(data): |
| 85 |
if data.get('GeneralCategory', 'Cn')[0] in 'LMNPSZ': |
| 86 |
return 1 |
| 87 |
else: |
| 88 |
return 0 |
| 89 |
|
| 90 |
def isgraph(data): |
| 91 |
if data.get('GeneralCategory', 'Cn')[0] in 'LMNPS': |
| 92 |
return 1 |
| 93 |
else: |
| 94 |
return 0 |
| 95 |
|
| 96 |
def isalnum(data): |
| 97 |
if data.get('GeneralCategory', 'Cn')[0] in 'N': |
| 98 |
return 1 |
| 99 |
else: |
| 100 |
return data.get('Alphabetic', 0) |
| 101 |
|
| 102 |
def isalpha(data): |
| 103 |
return data.get('Alphabetic', 0) |
| 104 |
|
| 105 |
def isupper(data): |
| 106 |
if data.get('Uppercase', 0): |
| 107 |
return 1 |
| 108 |
elif data.get('LowerCase', null) != null: |
| 109 |
return 1 |
| 110 |
else: |
| 111 |
return 0 |
| 112 |
|
| 113 |
def islower(data): |
| 114 |
if data.get('Lowercase', 0): |
| 115 |
return 1 |
| 116 |
elif data.get('UpperCase', null) != null: |
| 117 |
return 1 |
| 118 |
else: |
| 119 |
return 0 |
| 120 |
|
| 121 |
def decomposition_type(data, dtype): |
| 122 |
value = data.get('DecompositionType', None) |
| 123 |
if value and value.startswith(dtype): |
| 124 |
return value |
| 125 |
return None |
| 126 |
|
| 127 |
def properties(data): |
| 128 |
props = 0 |
| 129 |
props += (2 ** 0) * data.get('White_Space', 0) |
| 130 |
props += (2 ** 1) * data.get('Bidi_Control', 0) |
| 131 |
props += (2 ** 2) * data.get('Join_Control', 0) |
| 132 |
props += (2 ** 3) * data.get('Dash', 0) |
| 133 |
props += (2 ** 4) * data.get('Hyphen', 0) |
| 134 |
props += (2 ** 5) * data.get('Quotation_Mark', 0) |
| 135 |
props += (2 ** 6) * data.get('Terminal_Punctuation', 0) |
| 136 |
props += (2 ** 7) * data.get('Other_Math', 0) |
| 137 |
props += (2 ** 8) * data.get('Hex_Digit', 0) |
| 138 |
props += (2 ** 9) * data.get('ASCII_Hex_Digit', 0) |
| 139 |
props += (2 ** 10) * data.get('Other_Alphabetic', 0) |
| 140 |
props += (2 ** 11) * data.get('Ideographic', 0) |
| 141 |
props += (2 ** 12) * data.get('Diacritic', 0) |
| 142 |
props += (2 ** 13) * data.get('Extender', 0) |
| 143 |
props += (2 ** 14) * data.get('Other_Lowercase', 0) |
| 144 |
props += (2 ** 15) * data.get('Other_Uppercase', 0) |
| 145 |
props += (2 ** 16) * data.get('Noncharacter_Code_Point', 0) |
| 146 |
props += (2 ** 17) * data.get('Other_Grapheme_Extend', 0) |
| 147 |
props += (2 ** 18) * data.get('IDS_Binary_Operator', 0) |
| 148 |
props += (2 ** 19) * data.get('IDS_Trinary_Operator', 0) |
| 149 |
props += (2 ** 20) * data.get('Radical', 0) |
| 150 |
props += (2 ** 21) * data.get('Unified_Ideograph', 0) |
| 151 |
props += (2 ** 22) * data.get('Other_Default_Ignorable_Code_Point', 0) |
| 152 |
props += (2 ** 23) * data.get('Deprecated', 0) |
| 153 |
props += (2 ** 24) * data.get('Soft_Dotted', 0) |
| 154 |
props += (2 ** 25) * data.get('Logical_Order_Exception', 0) |
| 155 |
props += (2 ** 26) * data.get('Other_ID_Start', 0) |
| 156 |
props += (2 ** 27) * data.get('Other_ID_Continue', 0) |
| 157 |
props += (2 ** 28) * data.get('Sentence_Terminal', 0) |
| 158 |
props += (2 ** 29) * data.get('Variation_Selector', 0) |
| 159 |
props += (2 ** 30) * data.get('Pattern_White_Space', 0) |
| 160 |
props += (2 ** 31) * data.get('Pattern_Syntax', 0) |
| 161 |
props += (2 ** 32) * data.get('Prepended_Concatenation_Mark', 0) |
| 162 |
props += (2 ** 33) * data.get('Emoji', 0) |
| 163 |
props += (2 ** 34) * data.get('Emoji_Presentation', 0) |
| 164 |
props += (2 ** 35) * data.get('Emoji_Modifier', 0) |
| 165 |
props += (2 ** 36) * data.get('Emoji_Modifier_Base', 0) |
| 166 |
props += (2 ** 37) * data.get('Regional_Indicator', 0) |
| 167 |
props += (2 ** 38) * data.get('Emoji_Component', 0) |
| 168 |
props += (2 ** 39) * data.get('Extended_Pictographic', 0) |
| 169 |
|
| 170 |
props += (2 ** 52) * data.get('Inverted_Terminal_Punctuation', 0) |
| 171 |
props += (2 ** 53) * data.get('Punctuation_In_Word', 0) |
| 172 |
props += (2 ** 54) * data.get('Optional_Space_After', 0) |
| 173 |
props += (2 ** 55) * data.get('Extended_Dash', 0) |
| 174 |
props += (2 ** 56) * data.get('Paragraph_Separator', 0) |
| 175 |
props += (2 ** 57) * data.get('Ellipsis', 0) |
| 176 |
props += (2 ** 58) * data.get('Semi_Colon', 0) |
| 177 |
props += (2 ** 59) * data.get('Colon', 0) |
| 178 |
props += (2 ** 60) * data.get('Comma', 0) |
| 179 |
props += (2 ** 61) * data.get('Exclamation_Mark', 0) |
| 180 |
props += (2 ** 62) * data.get('Question_Mark', 0) |
| 181 |
props += (2 ** 63) * data.get('Full_Stop', 0) |
| 182 |
return props |
| 183 |
|
| 184 |
if __name__ == '__main__': |
| 185 |
for codepoint in ucd.CodeRange('000000..10FFFF'): |
| 186 |
try: |
| 187 |
data = unicode_chars[codepoint] |
| 188 |
except KeyError: |
| 189 |
data = {'CodePoint': codepoint} |
| 190 |
script = data.get('Script', 'Zzzz') |
| 191 |
title = data.get('TitleCase', codepoint) |
| 192 |
upper = data.get('UpperCase', codepoint) |
| 193 |
lower = data.get('LowerCase', codepoint) |
| 194 |
if title == null: title = codepoint |
| 195 |
if upper == null: upper = codepoint |
| 196 |
if lower == null: lower = codepoint |
| 197 |
print('%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %016x' % ( |
| 198 |
codepoint, script, |
| 199 |
data.get('GeneralCategory', 'Cn')[0], data.get('GeneralCategory', 'Cn'), |
| 200 |
upper, lower, title, |
| 201 |
isdigit(data), isxdigit(data), |
| 202 |
iscntrl(data), isspace(data), isblank(data), ispunct(data), |
| 203 |
isprint(data), isgraph(data), isalnum(data), isalpha(data), isupper(data), islower(data), |
| 204 |
properties(data))) |