1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586(*
* Copyright (C) 2006-2009 Citrix Systems Inc.
* Copyright (c) 2010 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)includeEzjsonmletreclist_iter_betweenfo=function|[]->()|[h]->fh|h::t->fh;o();list_iter_betweenfotletescape_strings=letbuf=Buffer.create80inBuffer.add_stringbuf"\"";fori=0toString.lengths-1doletx=matchs.[i]with|'\n'->"\\n"|'\t'->"\\t"|'\r'->"\\r"|'\b'->"\\b"|'\\'->"\\\\"|'/'->"\\/"|'"'->"\\\""|'\x0c'->"\\f"|c->String.make1cinBuffer.add_stringbufxdone;Buffer.add_stringbuf"\"";Buffer.contentsbufletrecto_fcttf=matchtwith|`Boolb->f(string_of_boolb)|`Floatr->f(Printf.sprintf"%g"r)|`Strings->f(escape_strings)|`Null->f"null"|`Aa->f"[";list_iter_between(funi->to_fctif)(fun()->f", ")a;f"]";|`Oa->f"{";list_iter_between(fun(k,v)->to_fct(`Stringk)f;f": ";to_fctvf)(fun()->f", ")a;f"}"letto_fct_humtf=matchtwith|`Boolb->f(string_of_boolb)|`Floatr->f(Printf.sprintf"%g"r)|`Strings->f(escape_strings)|`Null->f"null"|`Aa->f"[ ";list_iter_between(funi->to_fctif)(fun()->f", ")a;f" ]\n";|`Oa->f"{";list_iter_between(fun(k,v)->to_fct(`Stringk)f;f": ";to_fctvf)(fun()->f", ")a;f"}\n"letto_buffervbuf=to_fctv(funs->Buffer.add_stringbufs)letto_stringv=Ezjsonm.to_string~minify:true(wrapv)letto_buffer_humvbuf=to_fct_humv(funs->Buffer.add_stringbufs)letto_string_humv=Ezjsonm.to_string~minify:false(wrapv)letof_strings=unwrap(Ezjsonm.from_strings)exceptionRuntime_errorofstring*value