glib/glib/gen-iswide-table.py
Behdad Esfahbod acda716d2d Bug 648966 - Update g_unichar_iswide and g_unichar_iswide_cjk
Update to Unicode 6.0.  Also attach Python script that generates
the tables.
2011-04-29 18:03:24 -04:00

59 lines
934 B
Python
Executable File

#!/usr/bin/python
import sys
W = {}
W['A'] = []
W['W'] = []
W['F'] = W['W']
for line in sys.stdin:
i = line.find ('#')
if i >= 0:
line = line[:i]
line = line.strip ()
if not len (line):
continue
fields = [x.strip () for x in line.split (';')]
chars = fields[0]
width = fields[1]
if width not in ['A', 'W', 'F']:
continue
if chars.find ('..') > 0:
(start,end) = chars.split ('..')
else:
start = chars
end = chars
start, end = int(start,16), int(end,16)
for i in range (start, end+1):
W[width].append (i)
def write_intervals (S):
S.sort ()
start = S[0];
end = start - 1
for c in S:
if c == end+1:
end += 1
continue
else:
print "{0x%04X, 0x%04X}, " % (start, end)
start = c
end = start
print "{0x%04X, 0x%04X} " % (start, end)
print "table for g_unichar_iswide():"
print
write_intervals (W['W'])
print
print "table for g_unichar_iswide_cjk():"
print
write_intervals (W['A'])