diff options
author | 2024-11-20 16:43:34 +0000 | |
---|---|---|
committer | 2024-11-20 16:43:34 +0000 | |
commit | c1e6f7e918eacaad9c8b1a4b27fcd4d6245aaf68 (patch) | |
tree | 07640279a1d5a3a7f527f0def5ea7d3d1409f5ad /src/element.rs | |
parent | 49c8d52f0d4a41c340dd73c945119e69cf345a42 (diff) | |
download | peanuts-c1e6f7e918eacaad9c8b1a4b27fcd4d6245aaf68.tar.gz peanuts-c1e6f7e918eacaad9c8b1a4b27fcd4d6245aaf68.tar.bz2 peanuts-c1e6f7e918eacaad9c8b1a4b27fcd4d6245aaf68.zip |
implement element writing
Diffstat (limited to 'src/element.rs')
-rw-r--r-- | src/element.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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<Content>, } +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<xml::Element<'s>> for Element<'s> { // type Error = Error; |