File: genpuncttable.py

package info (click to toggle)
ibus-pinyin 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,428 kB
  • sloc: cpp: 6,536; ansic: 791; python: 567; makefile: 392; sh: 24; awk: 13
file content (32 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# vim:set et sts=4:
# -*- coding: utf-8 -*-

from punct import *

def tocstr(s):
    s = s.replace('\\', '\\\\')
    s = s.replace('"', '\\"')
    return '"%s"' % s

def gen_table():
    array = []
    i = 0
    print 'static const gchar * const'
    print 'puncts[] = {'
    for k, vs in punct_map:
        k = tocstr(k)
        vs = map(tocstr, vs)
        array.append((i, k))
        line = '    %s, %s, NULL,' % (k, ", ".join(vs))
        print line.encode("utf8")
        i += len(vs) + 2
    print '};'
    print
    print 'static const gchar * const * const'
    print 'punct_table[] = {'
    for i, k in array:
        print '    &puncts[%d],    // %s' % (i, k)
    print '};'

if __name__ == "__main__":
    gen_table()