Commit 015b5ef0 authored by Stefan Behnel's avatar Stefan Behnel

fix parsing of wide unicode escapes on narrow Unicode platforms

parent 846d1859
...@@ -30,6 +30,17 @@ class UnicodeLiteralBuilder(object): ...@@ -30,6 +30,17 @@ class UnicodeLiteralBuilder(object):
assert isinstance(characters, _unicode), str(type(characters)) assert isinstance(characters, _unicode), str(type(characters))
self.chars.append(characters) self.chars.append(characters)
if sys.maxunicode == 65535:
def append_charval(self, char_number):
if char_number > 65535:
# wide Unicode character on narrow platform => replace
# by surrogate pair
char_number -= 0x10000
self.chars.append( unichr((char_number % 1024) + 0xDC00) )
self.chars.append( unichr((char_number // 1024) + 0xD800) )
else:
self.chars.append( unichr(char_number) )
else:
def append_charval(self, char_number): def append_charval(self, char_number):
self.chars.append( unichr(char_number) ) self.chars.append( unichr(char_number) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment