Commit 69b520c1 authored by Mateusz Pawlik's avatar Mateusz Pawlik
Browse files

Added removal of the null character.

Weird stuff that caused errors in parsing bracket notation in C++.
parent 3a6c0e07
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -14,7 +14,9 @@ import json
def print_tree(json_tree, index):
def print_tree(json_tree, index):
  print('{' + json_tree[index]['type'], end='')
  print('{' + json_tree[index]['type'], end='')
  if 'value' in json_tree[index]:
  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"\}",
                                                                                                            "\\": r"\\"}))
                                                                                                            "\\": r"\\"}))
              + '}', end='')
              + '}', end='')