1mod ini;2mod python;3mod toml;4mod xml;5mod yaml;67pub use ini::IniFormat;8use jrsonnet_evaluator::{9 IStr, ObjValue, Result, Val,10 function::builtin,11 manifest::{JsonFormat, YamlStreamFormat, escape_string_json},12};13pub use python::{PythonFormat, PythonVarsFormat};14pub use toml::TomlFormat;15pub use xml::XmlJsonmlFormat;16pub use yaml::YamlFormat;1718#[builtin]19pub fn builtin_escape_string_json(str_: IStr) -> Result<String> {20 Ok(escape_string_json(&str_))21}2223#[builtin]24pub fn builtin_escape_string_python(str: IStr) -> Result<String> {25 Ok(escape_string_json(&str))26}2728#[builtin]29pub fn builtin_manifest_json_ex(30 value: Val,31 indent: String,32 newline: Option<IStr>,33 key_val_sep: Option<IStr>,3435 #[default(false)]36 #[cfg(feature = "exp-preserve-order")]37 preserve_order: bool,38) -> Result<String> {39 let newline = newline.as_deref().unwrap_or("\n");40 let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");41 value.manifest(JsonFormat::std_to_json(42 indent,43 newline,44 key_val_sep,45 #[cfg(feature = "exp-preserve-order")]46 preserve_order,47 ))48}4950#[builtin]51pub fn builtin_manifest_json(52 value: Val,5354 #[default(false)]55 #[cfg(feature = "exp-preserve-order")]56 preserve_order: bool,57) -> Result<String> {58 builtin_manifest_json_ex(59 value,60 " ".to_owned(),61 None,62 None,63 #[cfg(feature = "exp-preserve-order")]64 preserve_order,65 )66}6768#[builtin]69pub fn builtin_manifest_json_minified(70 value: Val,7172 #[default(false)]73 #[cfg(feature = "exp-preserve-order")]74 preserve_order: bool,75) -> Result<String> {76 value.manifest(JsonFormat::minify(77 #[cfg(feature = "exp-preserve-order")]78 preserve_order,79 ))80}8182#[builtin]83pub fn builtin_manifest_yaml_doc(84 value: Val,85 #[default(false)] indent_array_in_object: bool,86 #[default(true)] quote_keys: bool,8788 #[default(false)]89 #[cfg(feature = "exp-preserve-order")]90 preserve_order: bool,91) -> Result<String> {92 value.manifest(YamlFormat::std_to_yaml(93 indent_array_in_object,94 quote_keys,95 #[cfg(feature = "exp-preserve-order")]96 preserve_order,97 ))98}99100#[builtin]101#[allow(clippy::fn_params_excessive_bools)]102pub fn builtin_manifest_yaml_stream(103 value: Val,104 #[default(false)] indent_array_in_object: bool,105 #[default(true)] c_document_end: bool,106 #[default(true)] quote_keys: bool,107108 #[default(false)]109 #[cfg(feature = "exp-preserve-order")]110 preserve_order: bool,111) -> Result<String> {112 value.manifest(YamlStreamFormat::std_yaml_stream(113 YamlFormat::std_to_yaml(114 indent_array_in_object,115 quote_keys,116 #[cfg(feature = "exp-preserve-order")]117 preserve_order,118 ),119 c_document_end,120 ))121}122123#[builtin]124pub fn builtin_manifest_toml_ex(125 value: ObjValue,126 indent: String,127128 #[default(false)]129 #[cfg(feature = "exp-preserve-order")]130 preserve_order: bool,131) -> Result<String> {132 Val::Obj(value).manifest(TomlFormat::std_to_toml(133 indent,134 #[cfg(feature = "exp-preserve-order")]135 preserve_order,136 ))137}138139#[builtin]140pub fn builtin_manifest_toml(141 value: ObjValue,142143 #[default(false)]144 #[cfg(feature = "exp-preserve-order")]145 preserve_order: bool,146) -> Result<String> {147 builtin_manifest_toml_ex(148 value,149 " ".to_owned(),150 #[cfg(feature = "exp-preserve-order")]151 preserve_order,152 )153}154155#[builtin]156pub fn builtin_to_string(a: Val) -> Result<IStr> {157 a.to_string()158}159160#[builtin]161pub fn builtin_manifest_python(162 v: Val,163164 #[default(false)]165 #[cfg(feature = "exp-preserve-order")]166 preserve_order: bool,167) -> Result<String> {168 v.manifest(PythonFormat::std(169 #[cfg(feature = "exp-preserve-order")]170 preserve_order,171 ))172}173#[builtin]174pub fn builtin_manifest_python_vars(175 conf: Val,176177 #[default(false)]178 #[cfg(feature = "exp-preserve-order")]179 preserve_order: bool,180) -> Result<String> {181 conf.manifest(PythonVarsFormat::std(182 #[cfg(feature = "exp-preserve-order")]183 preserve_order,184 ))185}186187#[builtin]188pub fn builtin_escape_string_xml(str_: String) -> String {189 xml::escape_string_xml(str_.as_str())190}191192#[builtin]193pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {194 value.manifest(XmlJsonmlFormat::std_to_xml())195}196197#[builtin]198pub fn builtin_manifest_ini(199 ini: Val,200201 #[default(false)]202 #[cfg(feature = "exp-preserve-order")]203 preserve_order: bool,204) -> Result<String> {205 ini.manifest(IniFormat::std(206 #[cfg(feature = "exp-preserve-order")]207 preserve_order,208 ))209}