Permalink
Browse files

license; expose string_of_json_float

  • Loading branch information...
1 parent b08c79d commit 9087e18520b3dd70988f4a42ccf8a768e1aafbbb barko committed Jan 25, 2011
Showing with 9 additions and 3 deletions.
  1. +1 −0 LICENSE
  2. +2 −2 json_io.ml
  3. +6 −1 json_io.mli
View
@@ -1,5 +1,6 @@
Copyright (c) 2006 Wink Technologies, Inc.
Copyright (c) 2006, 2009 Martin Jambon
+Copyright (c) 2011 barko 00336ea19fcb53de187740c490f764f4
All rights reserved.
Redistribution and use in source and binary forms, with or without
View
@@ -132,7 +132,7 @@ let rec bprint_json allow_nan buf = function
Buffer.add_string buf (string_of_int i)
| Float f ->
- Buffer.add_string buf (string_of_json_float allow_nan f)
+ Buffer.add_string buf (string_of_json_float ~allow_nan f)
| String s ->
bquote_json_string buf s
@@ -161,7 +161,7 @@ and bprint_pair allow_nan buf (key, x) =
(* json does not allow rendering floats with a trailing dot: that is,
1234. is not allowed, but 1234.0 is ok. here, we add a '0' if
string_of_int result in a trailing dot *)
-and string_of_json_float allow_nan f =
+and string_of_json_float ?(allow_nan=false) f =
match classify_float f with
| FP_nan ->
if allow_nan then "NaN"
View
@@ -42,9 +42,14 @@ val string_of_json :
Json_type.t -> string
-(** [escpae_json_string add_string add_char s] returns an escaped json string.
+(** [escape_json_string add_string add_char s] returns an escaped json string.
[add_string] and [add_char] are functions that write a string and char
to some destination
*)
val escape_json_string : (string -> unit) -> (char -> unit) -> string -> unit
+
+(** [string_of_json_float ~allow_nan f] stringifies [f] according to
+ the JSON specificationsince [Pervasives.string_of_float] does not
+ have the right properites. *)
+val string_of_json_float : ?allow_nan:bool -> float -> string

0 comments on commit 9087e18

Please sign in to comment.