1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#![recursion_limit="512"] #[macro_use] pub mod macros; extern crate regex; pub mod edn; use edn::{utils::{replace_keywords, replace_char}}; /// `emit_edn` receives a json string and parses its common key-values to a regular EDN format. /// tested examples are: /// 1. `"{\"hello world\": \"julia\"}"` becomes `"{:hello-world \"julia\"}"` /// 2. `"{\"hello\": null}"` becomes `"{:hello nil}"` /// 3. `{\"hello\": 'c'}` becomes `"{:hello \\c}"` /// 4. `"{\"multi_string with underscore\": 545643}"` becomes `"{:multi-string-with-underscore 545643}"` /// /// ``` /// use edn_rs::emit_edn; /// /// fn emits_helloworld_edn() { /// let json = String::from("{\"hello\": \"world\"}"); /// let edn = String::from("{:hello \"world\"}"); /// /// assert_eq!(edn, emit_edn(json)); /// } /// ``` pub fn emit_edn(json: String) -> String { let edn_aux = replace_keywords(json); let edn = replace_char(edn_aux); edn.replace("null","nil") }