Commit 4603013c authored by Stefan Behnel's avatar Stefan Behnel

fix order of surrogate pair in wide unicode strings

parent f180a00f
...@@ -36,8 +36,8 @@ class UnicodeLiteralBuilder(object): ...@@ -36,8 +36,8 @@ class UnicodeLiteralBuilder(object):
# wide Unicode character on narrow platform => replace # wide Unicode character on narrow platform => replace
# by surrogate pair # by surrogate pair
char_number -= 0x10000 char_number -= 0x10000
self.chars.append( unichr((char_number % 1024) + 0xDC00) )
self.chars.append( unichr((char_number // 1024) + 0xD800) ) self.chars.append( unichr((char_number // 1024) + 0xD800) )
self.chars.append( unichr((char_number % 1024) + 0xDC00) )
else: else:
self.chars.append( unichr(char_number) ) self.chars.append( unichr(char_number) )
else: else:
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys
__doc__ = br""" __doc__ = br"""
>>> sa >>> sa
'abc' 'abc'
...@@ -38,6 +40,12 @@ __doc__ = br""" ...@@ -38,6 +40,12 @@ __doc__ = br"""
12 12
>>> len(null) >>> len(null)
1 1
>>> sys.maxunicode >= 65535
True
>>> sys.maxunicode == 65535 and 1 or len(wide_literal) # test for wide build
1
>>> sys.maxunicode > 65535 and 2 or len(wide_literal) # test for narrow build
2
""".decode("ASCII") + u""" """.decode("ASCII") + u"""
>>> ua == u'abc' >>> ua == u'abc'
True True
...@@ -59,9 +67,12 @@ __doc__ = br""" ...@@ -59,9 +67,12 @@ __doc__ = br"""
True True
>>> null == u'\\x00' # unescaped by Python (required by doctest) >>> null == u'\\x00' # unescaped by Python (required by doctest)
True True
>>> wide_literal == u'\U00101234' # unescaped by Cython
True
>>> wide_literal == u'\\U00101234' # unescaped by Python
True
""" """
import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '") __doc__ = __doc__.replace(u" u'", u" '")
else: else:
...@@ -78,3 +89,5 @@ f = u'\xf8' ...@@ -78,3 +89,5 @@ f = u'\xf8'
add = u'Søk ik' + u'üÖä' + u'abc' add = u'Søk ik' + u'üÖä' + u'abc'
null = u'\x00' null = u'\x00'
wide_literal = u'\U00101234'
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