Skip to content

unicode: Properly parse ranges in UnicodeData.txt #23000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/etc/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def fetch(f):
sys.stderr.write("cannot load %s" % f)
exit(1)

def is_valid_unicode(n):
return 0 <= n <= 0xD7FF or 0xE000 <= n <= 0x10FFFF
def is_surrogate(n):
return 0xD800 <= n <= 0xDFFF

def load_unicode_data(f):
fetch(f)
Expand All @@ -96,19 +96,28 @@ def load_unicode_data(f):
canon_decomp = {}
compat_decomp = {}

udict = {};
range_start = -1;
for line in fileinput.input(f):
fields = line.split(";")
if len(fields) != 15:
data = line.split(';');
if len(data) != 15:
continue
[code, name, gencat, combine, bidi,
decomp, deci, digit, num, mirror,
old, iso, upcase, lowcase, titlecase ] = fields

code_org = code
code = int(code, 16)

if not is_valid_unicode(code):
cp = int(data[0], 16);
if is_surrogate(cp):
continue
if range_start >= 0:
for i in xrange(range_start, cp):
udict[i] = data;
range_start = -1;
if data[1].endswith(", First>"):
range_start = cp;
continue;
udict[cp] = data;

for code in udict:
[code_org, name, gencat, combine, bidi,
decomp, deci, digit, num, mirror,
old, iso, upcase, lowcase, titlecase ] = udict[code];

# generate char to char direct common and simple conversions
# uppercase to lowercase
Expand Down
Loading