Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
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
pyodide
Commits
1761a222
Commit
1761a222
authored
Jan 28, 2019
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify handling of non-BMP characters
parent
46f64b5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
src/js2python.c
src/js2python.c
+16
-12
No files found.
src/js2python.c
View file @
1761a222
...
...
@@ -79,20 +79,20 @@ EM_JS(int, __js2python, (int id), {
// to determine if is needs to be a 1-, 2- or 4-byte string, since
// Python handles all 3.
var
max_code_point
=
0
;
var
length
=
value
.
length
;
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
code_point
=
value
.
codePointAt
(
i
);
max_code_point
=
Math
.
max
(
max_code_point
,
code_point
);
if
(
max_code_point
>
0xffff
)
{
// If we're dealing with UTF-16 surrogate pairs, convert the string
// to an array of each of its characters, so we correctly count the
// number of characters.
value
=
Array
.
from
(
value
[
Symbol
.
iterator
]());
// We can short circuit here -- we already know we need a 4-byte output.
break
;
if
(
code_point
>
0xffff
)
{
// If we have a code point requiring UTF-16 surrogate pairs, the
// number of characters (codePoints) is less than value.length,
// so skip the next charCode and subtract 1 from the length.
i
++
;
length
--
;
}
}
var
result
=
__js2python_allocate_string
(
value
.
length
,
max_code_point
);
var
result
=
__js2python_allocate_string
(
length
,
max_code_point
);
if
(
result
==
0
)
{
return
0
;
}
...
...
@@ -100,16 +100,20 @@ EM_JS(int, __js2python, (int id), {
var
ptr
=
__js2python_get_ptr
(
result
);
if
(
max_code_point
>
0xffff
)
{
ptr
=
ptr
/
4
;
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
Module
.
HEAPU32
[
ptr
+
i
]
=
value
[
i
].
codePointAt
(
0
);
for
(
var
i
=
0
,
j
=
0
;
j
<
length
;
i
++
,
j
++
)
{
var
code_point
=
value
.
codePointAt
(
i
);
Module
.
HEAPU32
[
ptr
+
j
]
=
code_point
;
if
(
code_point
>
0xffff
)
{
i
++
;
}
}
}
else
if
(
max_code_point
>
0xff
)
{
ptr
=
ptr
/
2
;
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
Module
.
HEAPU16
[
ptr
+
i
]
=
value
.
codePointAt
(
i
);
}
}
else
{
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
Module
.
HEAPU8
[
ptr
+
i
]
=
value
.
codePointAt
(
i
);
}
}
...
...
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