3 from __future__ import print_function, division, absolute_import
6 from collections import OrderedDict
8 if len (sys.argv) != 2:
9 print("usage: ./gen-emoji-table.py emoji-data.txt", file=sys.stderr)
13 header = [f.readline () for _ in range(10)]
15 ranges = OrderedDict()
16 for line in f.readlines():
18 if not line or line[0] == '#':
20 rang, typ = [s.strip() for s in line.split('#')[0].split(';')[:2]]
22 rang = [int(s, 16) for s in rang.split('..')]
30 if ranges[typ] and ranges[typ][-1][1] == start - 1:
31 ranges[typ][-1] = (ranges[typ][-1][0], end)
33 ranges[typ].append((start, end))
37 print ("/* == Start of generated table == */")
39 print (" * The following tables are generated by running:")
41 print (" * ./gen-emoji-table.py emoji-data.txt")
43 print (" * on file with this header:")
46 print (" * %s" % (l.strip()))
49 print ("#ifndef HB_UNICODE_EMOJI_TABLE_HH")
50 print ("#define HB_UNICODE_EMOJI_TABLE_HH")
52 print ('#include "hb-unicode.hh"')
55 for typ,s in ranges.items():
56 if typ != "Extended_Pictographic": continue
58 print("static const struct hb_unicode_range_t _hb_unicode_emoji_%s_table[] =" % typ)
60 for pair in sorted(s):
61 print(" {0x%04X, 0x%04X}," % pair)
65 print ("#endif /* HB_UNICODE_EMOJI_TABLE_HH */")
67 print ("/* == End of generated table == */")