Imported Upstream version 0.27.1
[platform/upstream/pkg-config.git] / glib / glib / gen-iswide-table.py
1 #!/usr/bin/python
2
3 import sys
4
5 W = {}
6 W['A'] = []
7 W['W'] = []
8 W['F'] = W['W']
9
10 for line in sys.stdin:
11         i = line.find ('#')
12         if i >= 0:
13                 line = line[:i]
14         line = line.strip ()
15         if not len (line):
16                 continue
17
18         fields = [x.strip () for x in line.split (';')]
19         chars = fields[0]
20         width = fields[1]
21
22         if width not in ['A', 'W', 'F']:
23                 continue
24
25         if chars.find ('..') > 0:
26                 (start,end) = chars.split ('..')
27         else:
28                 start = chars
29                 end = chars
30         start, end = int(start,16), int(end,16)
31
32         for i in range (start, end+1):
33                 W[width].append (i)
34
35
36 def write_intervals (S):
37         S.sort ()
38         start = S[0];
39         end = start - 1
40         for c in S:
41                 if c == end+1:
42                         end += 1
43                         continue
44                 else:
45                         print "{0x%04X, 0x%04X}, " % (start, end)
46                         start = c
47                         end = start
48         print "{0x%04X, 0x%04X} " % (start, end)
49
50
51
52 print "table for g_unichar_iswide():"
53 print
54 write_intervals (W['W'])
55 print
56 print "table for g_unichar_iswide_cjk():"
57 print
58 write_intervals (W['A'])