Skip to content
Newer
Older
100644 63 lines (51 sloc) 1.73 KB
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (*
19 @author Rudy Sicard
20 @author Raja Boujbel
21 **)
22
23 (** Main Json module for serialize and unserialize Json. *)
24
25 module J = JsonTypes
26
27 (**
28 @deprecated use [JsPrint.escape_non_utf8_special]
29 *)
30 let escape_non_utf8_special = JsonPrint.escape_non_utf8_special
31
32 (*
33 extract from opa
34 let rpl_list = [
35 ( "\\" , "\\\\");
36 ( "\n" , "\\n" );
37 ( "\r" , "\\r" );
38 ( "\t" , "\\t" );
39 ( "\"" , "\\\"" )
40 ] in
41 Base.List.foldl ( fun (pat, rpl) str -> String.replace pat rpl str) rpl_list v
42 *)
43
44 (** Unserialize string to json. *)
45 let from_string str =
46 (*DEBUG - print_tokens str;*)
47 let buffer = Ulexing.from_utf8_string str in
48 let res =
49 (* Trick from Alain Frisch to use Ulex with OCamlyacc *)
50 (* http://caml.inria.fr/pub/ml-archives/caml-list/2005/01/52cbc2cd2be4fc7ea0f00c39a760bf59.en.html *)
51 JsonParse.json (fun _ -> JsonLex.get_token buffer) (Lexing.from_string "dummy")
52 in res
53
54 (**
55 @deprecated use [JsPrint.Buffer.json]
56 *)
57 let to_buffer = JsonPrint.Buffer.json
58
59 (**
60 @deprecated use [JsPrint.to_string]
61 *)
62 let to_string = JsonPrint.to_string
Something went wrong with that request. Please try again.