Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
2e3cf3da
Commit
2e3cf3da
authored
Mar 07, 2013
by
Nikita Nemkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compatibility fix: no UTF-32 codec in Python 2.4/2.5.
parent
c0e70e4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
Cython/Compiler/StringEncoding.py
Cython/Compiler/StringEncoding.py
+21
-14
No files found.
Cython/Compiler/StringEncoding.py
View file @
2e3cf3da
...
...
@@ -4,7 +4,6 @@
import
re
import
sys
import
array
if
sys
.
version_info
[
0
]
>=
3
:
_unicode
,
_str
,
_bytes
=
str
,
str
,
bytes
...
...
@@ -267,18 +266,26 @@ def split_string_literal(s, limit=2000):
def
encode_pyunicode_string
(
s
):
"""Create Py_UNICODE[] representation of a given unicode string.
"""
utf32_array
=
array
.
array
(
'i'
,
s
.
encode
(
'UTF-32'
))
assert
utf32_array
.
itemsize
==
4
utf32_array
.
pop
(
0
)
# Remove BOM
utf32_array
.
append
(
0
)
# Add NULL terminator
for
c
in
utf32_array
:
if
c
>
65535
:
utf16_array
=
array
.
array
(
'H'
,
s
.
encode
(
'UTF-16'
)
)
utf16_array
.
pop
(
0
)
# Remove BOM
utf16_array
.
append
(
0
)
# Add NULL terminator
break
s
=
map
(
ord
,
s
)
+
[
0
]
if
sys
.
maxunicode
>=
0x10000
:
# Wide build or Py3.3
utf16
,
utf32
=
[],
s
for
code_point
in
s
:
if
code_point
>=
0x10000
:
# outside of BMP
high
,
low
=
divmod
(
code_point
-
0x10000
,
1024
)
utf16
.
append
(
high
+
0xD800
)
utf16
.
append
(
low
+
0xDC00
)
else
:
utf16
.
append
(
code_point
)
else
:
utf16_array
=
[]
utf16
,
utf32
=
s
,
[]
for
code_unit
in
s
:
if
0xDC00
<=
code_unit
<=
0xDFFF
:
# low surrogate
high
,
low
=
utf32
.
pop
(),
code_unit
utf32
.
append
(((
high
&
0x3FF
)
<<
10
)
+
(
low
&
0x3FF
)
+
0x10000
)
else
:
utf32
.
append
(
code_unit
)
return
","
.
join
(
map
(
unicode
,
utf16_array
)),
","
.
join
(
map
(
unicode
,
utf32_array
))
if
utf16
==
utf32
:
utf16
=
[]
return
","
.
join
(
map
(
unicode
,
utf16
)),
","
.
join
(
map
(
unicode
,
utf32
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment