Merge branch 'master' of vapour:hop
This commit is contained in:
commit
7fbe8b9109
|
@ -52,10 +52,35 @@ let rec to_string j =
|
|||
if b then "true" else "false"
|
||||
| Nil ->
|
||||
"null"
|
||||
|
||||
and kv_to_string (k, 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) =
|
||||
(* Of course, at the moment, the codepoint is limited to 16 bits... *)
|
||||
if codepoint < 0x80 then
|
||||
|
|
Loading…
Reference in New Issue