From c1e6f7e918eacaad9c8b1a4b27fcd4d6245aaf68 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 20 Nov 2024 16:43:34 +0000 Subject: implement element writing --- src/element.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/element.rs') diff --git a/src/element.rs b/src/element.rs index 5b5f048..04f2e5e 100644 --- a/src/element.rs +++ b/src/element.rs @@ -54,6 +54,33 @@ pub struct Element { pub content: Vec, } +pub fn escape_str(s: &str) -> String { + let mut string = String::new(); + for str in s.split_inclusive(|c| c == '<' || c == '&' || c == '>') { + if let Some(str) = str.strip_suffix('<') { + if !str.is_empty() { + string.push_str(str) + } + string.push_str("<"); + } else if let Some(str) = str.strip_suffix('&') { + if !str.is_empty() { + string.push_str(str) + } + string.push_str("&"); + } else if let Some(str) = str.strip_suffix('>') { + if !str.is_empty() { + string.push_str(str) + } + string.push_str(">"); + } else { + if !str.is_empty() { + string.push_str(str) + } + } + } + string +} + // impl<'s> TryFrom> for Element<'s> { // type Error = Error; -- cgit