1mod ini;2mod python;3mod toml;4mod xml;5mod yaml;67pub use ini::IniFormat;8use jrsonnet_evaluator::{9 function::builtin,10 manifest::{escape_string_json, JsonFormat, YamlStreamFormat},11 IStr, ObjValue, Result, Val,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]101pub fn builtin_manifest_yaml_stream(102 value: Val,103 #[default(false)] indent_array_in_object: bool,104 #[default(true)] c_document_end: bool,105 #[default(true)] quote_keys: bool,106107 #[default(false)]108 #[cfg(feature = "exp-preserve-order")]109 preserve_order: bool,110) -> Result<String> {111 value.manifest(YamlStreamFormat::std_yaml_stream(112 YamlFormat::std_to_yaml(113 indent_array_in_object,114 quote_keys,115 #[cfg(feature = "exp-preserve-order")]116 preserve_order,117 ),118 c_document_end,119 ))120}121122#[builtin]123pub fn builtin_manifest_toml_ex(124 value: ObjValue,125 indent: String,126127 #[default(false)]128 #[cfg(feature = "exp-preserve-order")]129 preserve_order: bool,130) -> Result<String> {131 Val::Obj(value).manifest(TomlFormat::std_to_toml(132 indent,133 #[cfg(feature = "exp-preserve-order")]134 preserve_order,135 ))136}137138#[builtin]139pub fn builtin_manifest_toml(140 value: ObjValue,141142 #[default(false)]143 #[cfg(feature = "exp-preserve-order")]144 preserve_order: bool,145) -> Result<String> {146 builtin_manifest_toml_ex(147 value,148 " ".to_owned(),149 #[cfg(feature = "exp-preserve-order")]150 preserve_order,151 )152}153154#[builtin]155pub fn builtin_to_string(a: Val) -> Result<IStr> {156 a.to_string()157}158159#[builtin]160pub fn builtin_manifest_python(161 v: Val,162163 #[default(false)]164 #[cfg(feature = "exp-preserve-order")]165 preserve_order: bool,166) -> Result<String> {167 v.manifest(PythonFormat::std(168 #[cfg(feature = "exp-preserve-order")]169 preserve_order,170 ))171}172#[builtin]173pub fn builtin_manifest_python_vars(174 conf: Val,175176 #[default(false)]177 #[cfg(feature = "exp-preserve-order")]178 preserve_order: bool,179) -> Result<String> {180 conf.manifest(PythonVarsFormat::std(181 #[cfg(feature = "exp-preserve-order")]182 preserve_order,183 ))184}185186#[builtin]187pub fn builtin_escape_string_xml(str_: String) -> String {188 xml::escape_string_xml(str_.as_str())189}190191#[builtin]192pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {193 value.manifest(XmlJsonmlFormat::std_to_xml())194}195196#[builtin]197pub fn builtin_manifest_ini(198 ini: Val,199200 #[default(false)]201 #[cfg(feature = "exp-preserve-order")]202 preserve_order: bool,203) -> Result<String> {204 ini.manifest(IniFormat::std(205 #[cfg(feature = "exp-preserve-order")]206 preserve_order,207 ))208}