| 75 | } |
| 76 | |
| 77 | pub 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("<"), |
| 87 | '>' => escaped.push_str(">"), |
| 88 | '&' => escaped.push_str("&"), |
| 89 | '\'' => escaped.push_str("'"), |
| 90 | '"' => escaped.push_str("""), |
| 91 | _ => escaped.push(c), |
| 92 | } |
| 93 | } |
| 94 | Cow::Owned(escaped) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | pub fn get_env_bool(key: &str) -> bool { |
| 99 | match env::var(key) { |