Merge branch 'master' of vapour:hop
This commit is contained in:
commit
7fbe8b9109
|
@ -38,24 +38,49 @@ let str_to_string s =
|
||||||
|
|
||||||
let rec to_string j =
|
let rec to_string j =
|
||||||
match j with
|
match j with
|
||||||
| Num f ->
|
| Num f ->
|
||||||
if float_of_int (int_of_float f) = f
|
if float_of_int (int_of_float f) = f
|
||||||
then string_of_int (int_of_float f)
|
then string_of_int (int_of_float f)
|
||||||
else string_of_float f
|
else string_of_float f
|
||||||
| Str s ->
|
| Str s ->
|
||||||
str_to_string s
|
str_to_string s
|
||||||
| Arr js ->
|
| Arr js ->
|
||||||
"[" ^ String.concat "," (List.map to_string js) ^ "]"
|
"[" ^ String.concat "," (List.map to_string js) ^ "]"
|
||||||
| Rec kvs ->
|
| Rec kvs ->
|
||||||
"{" ^ String.concat "," (List.map kv_to_string kvs) ^ "}"
|
"{" ^ String.concat "," (List.map kv_to_string kvs) ^ "}"
|
||||||
| Flg b ->
|
| Flg b ->
|
||||||
if b then "true" else "false"
|
if b then "true" else "false"
|
||||||
| Nil ->
|
| Nil ->
|
||||||
"null"
|
"null"
|
||||||
|
|
||||||
and kv_to_string (k, v) =
|
and kv_to_string (k, v) =
|
||||||
str_to_string k ^ ":" ^ to_string v
|
str_to_string k ^ ":" ^ to_string v
|
||||||
|
|
||||||
|
let rec pretty_string ?indent:(indent=2) j =
|
||||||
|
let rec walk current j =
|
||||||
|
match j with
|
||||||
|
| Num f ->
|
||||||
|
if float_of_int (int_of_float f) = f
|
||||||
|
then string_of_int (int_of_float f)
|
||||||
|
else string_of_float f
|
||||||
|
| Str s ->
|
||||||
|
str_to_string s
|
||||||
|
| Arr js ->
|
||||||
|
"[" ^ String.concat ", " (List.map (walk current) js) ^ "]"
|
||||||
|
| Rec [] ->
|
||||||
|
"{}"
|
||||||
|
| Rec [(k, v)] ->
|
||||||
|
"{" ^ str_to_string k ^ ": " ^ walk current v ^ "}"
|
||||||
|
| Rec kvs ->
|
||||||
|
"{" ^ String.concat "," (List.map (kv_walk (current + indent)) kvs) ^
|
||||||
|
"\n" ^ String.make current ' ' ^ "}"
|
||||||
|
| Flg b ->
|
||||||
|
if b then "true" else "false"
|
||||||
|
| Nil ->
|
||||||
|
"null"
|
||||||
|
and kv_walk current (k, v) =
|
||||||
|
"\n" ^ String.make current ' ' ^ str_to_string k ^ ": " ^ walk current v
|
||||||
|
in walk 0 j
|
||||||
|
|
||||||
let accumulate_utf8 codepoint (acc, len) =
|
let accumulate_utf8 codepoint (acc, len) =
|
||||||
(* Of course, at the moment, the codepoint is limited to 16 bits... *)
|
(* Of course, at the moment, the codepoint is limited to 16 bits... *)
|
||||||
if codepoint < 0x80 then
|
if codepoint < 0x80 then
|
||||||
|
|
Loading…
Reference in New Issue