Skip to content

Commit

Permalink
json_to_dot: use String.escaped from stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols committed Sep 5, 2018
1 parent 3f161f7 commit 65c5404
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
14 changes: 0 additions & 14 deletions src/extPervasives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,3 @@ let lines s =

let string_last_line s =
lines s |> list_last

let escape ?(chars="\\\"") ?(esc='\\') s =
let buf = Bytes.create (2 * String.length s) in
let j = ref 0 in
for i = 0 to String.length s - 1 do
if String.contains chars s.[i] then
(
Bytes.set buf !j esc;
incr j
);
Bytes.set buf !j s.[i];
incr j
done;
Bytes.sub_string buf 0 !j
4 changes: 2 additions & 2 deletions src/jsonHelpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let json_to_dot cout json =
nodeid
| `String name ->
let nodeid = fresh () in
fprintf cout "%s [label=\"%s\"];\n" nodeid (ExtPervasives.escape name);
fprintf cout "%s [label=\"%s\"];\n" nodeid (String.escaped name);
nodeid
| `List [x] ->
traverse x
Expand All @@ -76,7 +76,7 @@ let json_to_dot cout json =
List.iter (fun c -> fprintf cout "%s -> %s;\n" nodeid c) childrenids;
nodeid
| _ ->
failwith "unsupported feature in json_to_dot"
assert false
in
fprintf cout "digraph {\n";
ignore (traverse json);
Expand Down

0 comments on commit 65c5404

Please sign in to comment.