Modernize fc-blanks.py
fc-blanks.py now works on both python2 and 3
This commit is contained in:
parent
13087e38ac
commit
0e837ae6ec
|
@ -1,8 +1,11 @@
|
||||||
#! /usr/bin/python
|
#! /usr/bin/python
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import print_function
|
||||||
import urllib2
|
import urllib2
|
||||||
import sys
|
import sys
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
fp = urllib2.urlopen('http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[%3AGC%3DZs%3A][%3ADI%3A]&abb=on&ucd=on&esc=on&g')
|
fp = urllib2.urlopen('http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[%3AGC%3DZs%3A][%3ADI%3A]&abb=on&ucd=on&esc=on&g')
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
|
@ -47,12 +50,12 @@ for i in p:
|
||||||
fescape = False
|
fescape = False
|
||||||
elif i >= '0' and i <= '9' or i.lower() >= 'a' and i.lower() <= 'f':
|
elif i >= '0' and i <= '9' or i.lower() >= 'a' and i.lower() <= 'f':
|
||||||
if fescape == True:
|
if fescape == True:
|
||||||
raise RuntimeError, "Unexpected escape code"
|
raise RuntimeError("Unexpected escape code")
|
||||||
if funicode == True:
|
if funicode == True:
|
||||||
v <<= 4
|
v <<= 4
|
||||||
v += int(i, 16)
|
v += int(i, 16)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError, "Unable to parse Unicode"
|
raise RuntimeError("Unable to parse Unicode")
|
||||||
elif i == ' ':
|
elif i == ' ':
|
||||||
if fescape == True:
|
if fescape == True:
|
||||||
funicode = True
|
funicode = True
|
||||||
|
@ -71,13 +74,13 @@ for i in p:
|
||||||
frange = False
|
frange = False
|
||||||
elif i == '-':
|
elif i == '-':
|
||||||
if fescape == True:
|
if fescape == True:
|
||||||
raise RuntimeError, "Unexpected escape code"
|
raise RuntimeError("Unexpected escape code")
|
||||||
vbegin = v
|
vbegin = v
|
||||||
v = 0
|
v = 0
|
||||||
funicode = False
|
funicode = False
|
||||||
frange = True
|
frange = True
|
||||||
else:
|
else:
|
||||||
raise RuntimeError, "Unable to parse Unicode: %s" % i
|
raise RuntimeError("Unable to parse Unicode: %s" % i)
|
||||||
|
|
||||||
if fprocess == True:
|
if fprocess == True:
|
||||||
vbegin = 0
|
vbegin = 0
|
||||||
|
@ -111,22 +114,22 @@ while True:
|
||||||
s = sys.stdin.readline().rstrip()
|
s = sys.stdin.readline().rstrip()
|
||||||
if s == "@@@":
|
if s == "@@@":
|
||||||
break
|
break
|
||||||
print s
|
print(s)
|
||||||
|
|
||||||
print "static FcChar32 _fcBlanks[%s] = {" % (ncode + 1)
|
print("static FcChar32 _fcBlanks[%s] = {" % (ncode + 1))
|
||||||
k = 0
|
k = 0
|
||||||
for i in sorted(l, key=lambda(a): a[0]):
|
for i in sorted(l, key=lambda a: a[0]):
|
||||||
for j in range(i[0], i[1] + 1):
|
for j in range(i[0], i[1] + 1):
|
||||||
if k != 0:
|
if k != 0:
|
||||||
print ","
|
print(",")
|
||||||
print " 0x%04x" % j,
|
print(" 0x%04x" % j, end=' ')
|
||||||
k += 1
|
k += 1
|
||||||
|
|
||||||
print "};"
|
print("};")
|
||||||
print '''
|
print('''
|
||||||
static FcBlanks fcBlanks = {
|
static FcBlanks fcBlanks = {
|
||||||
%s,
|
%s,
|
||||||
-1,
|
-1,
|
||||||
_fcBlanks
|
_fcBlanks
|
||||||
};
|
};
|
||||||
''' % (ncode + 1)
|
''' % (ncode + 1))
|
||||||
|
|
Loading…
Reference in New Issue