From d87033d32024845534e414f060a0d007ee85d3b5 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sun, 17 Mar 2024 00:49:53 +0100 Subject: [PATCH] svg-filters(codegen): add pretty and ugly printing --- crates/svg-filters/src/codegen.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/svg-filters/src/codegen.rs b/crates/svg-filters/src/codegen.rs index a8e7b23..cd93d25 100644 --- a/crates/svg-filters/src/codegen.rs +++ b/crates/svg-filters/src/codegen.rs @@ -43,10 +43,25 @@ impl SvgDocument { self.filters.get_mut(&id.to_string()).unwrap() } + pub fn generate_svg_pretty(&self) -> String { + let mut result = Vec::new(); + let doc_writer = quick_xml::Writer::new_with_indent(&mut result, b' ', 2); + + self.generate(doc_writer); + + String::from_utf8_lossy(&result).to_string() + } + pub fn generate_svg(&self) -> String { let mut result = Vec::new(); - let mut doc_writer = quick_xml::Writer::new_with_indent(&mut result, b' ', 2); + let doc_writer = quick_xml::Writer::new(&mut result); + self.generate(doc_writer); + + String::from_utf8_lossy(&result).to_string() + } + + fn generate(&self, mut doc_writer: quick_xml::Writer<&mut Vec>) { doc_writer .create_element("svg") .write_inner_content(|writer| { @@ -55,8 +70,6 @@ impl SvgDocument { .try_fold(writer, Self::gen_filter) .map(|_| {}) }); - - String::from_utf8_lossy(&result).to_string() } fn gen_filter<'w, 'r>(