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
Gwenaël Samain
cython
Commits
745d0091
Commit
745d0091
authored
Mar 07, 2013
by
scoder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #193 from nnemkin/pyunicode_string_fix
Compatibility fix for Py_UNICODE* support.
parents
d4546c4f
08342a2d
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 @
745d0091
...
...
@@ -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
and
utf32
and
0xD800
<=
utf32
[
-
1
]
<=
0xDBFF
:
high
,
low
=
utf32
[
-
1
],
code_unit
utf32
[
-
1
]
=
((
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