Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mateusz Pawlik
ted-datasets
Commits
69b520c1
Commit
69b520c1
authored
Jun 14, 2018
by
Mateusz Pawlik
Browse files
Added removal of the null character.
Weird stuff that caused errors in parsing bracket notation in C++.
parent
3a6c0e07
Changes
1
Show whitespace changes
Inline
Side-by-side
python_ast/parse_json.py
View file @
69b520c1
...
...
@@ -14,7 +14,9 @@ import json
def
print_tree
(
json_tree
,
index
):
print
(
'{'
+
json_tree
[
index
][
'type'
],
end
=
''
)
if
'value'
in
json_tree
[
index
]:
print
(
'{'
+
json_tree
[
index
][
'value'
].
replace
(
'
\r
'
,
''
).
replace
(
'
\n
'
,
''
).
replace
(
'
\t
'
,
''
).
strip
().
translate
(
str
.
maketrans
({
"{"
:
r
"\{"
,
# \x00 is a null character (https://en.wikipedia.org/wiki/Null_character)
# it caused endless loop / SEGFAULT while parsing a tree in bracket notation
print
(
'{'
+
json_tree
[
index
][
'value'
].
replace
(
'
\r
'
,
''
).
replace
(
'
\n
'
,
''
).
replace
(
'
\t
'
,
''
).
replace
(
'
\x00
'
,
''
).
strip
().
translate
(
str
.
maketrans
({
"{"
:
r
"\{"
,
"}"
:
r
"\}"
,
"
\\
"
:
r
"\\"
}))
+
'}'
,
end
=
''
)
...
...
Write
Preview
Supports
Markdown
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