MCPcopy Create free account
hub / github.com/TeamPiped/piped-proxy / escape_xml

Function escape_xml

src/utils.rs:77–96  ·  view source on GitHub ↗
(raw: &str)

Source from the content-addressed store, hash-verified

75}
76
77pub fn escape_xml(raw: &str) -> Cow<'_, str> {
78 if !raw.contains(&['<', '>', '&', '\'', '"'][..]) {
79 // If there are no characters to escape, return the original string.
80 Cow::Borrowed(raw)
81 } else {
82 // If there are characters to escape, build a new string with the replacements.
83 let mut escaped = String::with_capacity(raw.len());
84 for c in raw.chars() {
85 match c {
86 '<' => escaped.push_str("&lt;"),
87 '>' => escaped.push_str("&gt;"),
88 '&' => escaped.push_str("&amp;"),
89 '\'' => escaped.push_str("&apos;"),
90 '"' => escaped.push_str("&quot;"),
91 _ => escaped.push(c),
92 }
93 }
94 Cow::Owned(escaped)
95 }
96}
97
98pub fn get_env_bool(key: &str) -> bool {
99 match env::var(key) {

Callers 1

indexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected