1#!/usr/bin/python 2 3from __future__ import print_function, division, absolute_import 4import sys 5import os.path 6from collections import OrderedDict 7 8if len (sys.argv) != 2: 9 print("usage: ./gen-emoji-table.py emoji-data.txt", file=sys.stderr) 10 sys.exit (1) 11 12f = open(sys.argv[1]) 13header = [f.readline () for _ in range(10)] 14 15ranges = OrderedDict() 16for line in f.readlines(): 17 line = line.strip() 18 if not line or line[0] == '#': 19 continue 20 rang, typ = [s.strip() for s in line.split('#')[0].split(';')[:2]] 21 22 rang = [int(s, 16) for s in rang.split('..')] 23 if len(rang) > 1: 24 start, end = rang 25 else: 26 start = end = rang[0] 27 28 if typ not in ranges: 29 ranges[typ] = [] 30 if ranges[typ] and ranges[typ][-1][1] == start - 1: 31 ranges[typ][-1] = (ranges[typ][-1][0], end) 32 else: 33 ranges[typ].append((start, end)) 34 35 36 37print ("/* == Start of generated table == */") 38print ("/*") 39print (" * The following tables are generated by running:") 40print (" *") 41print (" * ./gen-emoji-table.py emoji-data.txt") 42print (" *") 43print (" * on file with this header:") 44print (" *") 45for l in header: 46 print (" * %s" % (l.strip())) 47print (" */") 48print () 49print ("#ifndef HB_UNICODE_EMOJI_TABLE_HH") 50print ("#define HB_UNICODE_EMOJI_TABLE_HH") 51print () 52print ('#include "hb-unicode.hh"') 53print () 54 55for typ,s in ranges.items(): 56 if typ != "Extended_Pictographic": continue 57 print() 58 print("static const struct hb_unicode_range_t _hb_unicode_emoji_%s_table[] =" % typ) 59 print("{") 60 for pair in sorted(s): 61 print(" {0x%04X, 0x%04X}," % pair) 62 print("};") 63 64print () 65print ("#endif /* HB_UNICODE_EMOJI_TABLE_HH */") 66print () 67print ("/* == End of generated table == */") 68