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
Kirill Smelkov
cython
Commits
efb4bde9
Commit
efb4bde9
authored
Aug 12, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use correct byte encoding for char values, some escaping on char literals
parent
c3d75bde
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
9 deletions
+15
-9
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-8
Cython/Utils.py
Cython/Utils.py
+12
-1
No files found.
Cython/Compiler/ExprNodes.py
View file @
efb4bde9
...
...
@@ -14,6 +14,7 @@ from Builtin import list_type, tuple_type, dict_type
import
Symtab
import
Options
from
Annotate
import
AnnotationItem
from
Cython
import
Utils
from
Cython.Debugging
import
print_call_chain
from
DebugFlags
import
debug_disposal_code
,
debug_temp_alloc
,
\
...
...
@@ -639,16 +640,10 @@ class CharNode(ConstNode):
type
=
PyrexTypes
.
c_char_type
def
compile_time_value
(
self
,
denv
):
return
ord
(
self
.
value
)
return
ord
(
self
.
value
.
byteencode
()
)
def
calculate_result_code
(
self
):
if
self
.
value
==
"'"
:
return
r"'\''"
char
=
ord
(
self
.
value
)
if
char
<
32
:
return
"'
\
\
x%02X'"
%
char
else
:
return
"'%s'"
%
self
.
value
return
"'%s'"
%
Utils
.
escape_character
(
self
.
value
.
byteencode
())
class
IntNode
(
ConstNode
):
...
...
Cython/Utils.py
View file @
efb4bde9
...
...
@@ -115,7 +115,7 @@ def _to_escape_sequence(s):
elif
s
==
'"'
:
return
r'\"'
else
:
# oct passes much better than hex
#
within a character sequence,
oct passes much better than hex
return
''
.
join
([
'
\
\
%03o'
%
ord
(
c
)
for
c
in
s
])
_c_special
=
(
'
\
0
'
,
'
\
n
'
,
'
\
r
'
,
'
\
t
'
,
'??'
,
'"'
)
...
...
@@ -130,6 +130,17 @@ def _build_specials_test():
_has_specials
=
_build_specials_test
()
def
escape_character
(
c
):
if
c
in
'
\
n
\
r
\
t
\
\
'
:
return
repr
(
c
)[
1
:
-
1
]
elif
c
==
"'"
:
return
"
\
\
'"
elif
ord
(
c
)
<
32
:
# hex works well for characters
return
"
\
\
x%02X"
%
ord
(
c
)
else
:
return
c
def
escape_byte_string
(
s
):
s
=
s
.
replace
(
'
\
\
'
,
'
\
\
\
\
'
)
if
_has_specials
(
s
):
...
...
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