Skip to main content

escape_html_cow

Function escape_html_cow 

Source
pub fn escape_html_cow(value: &str) -> Cow<'_, str>
Expand description

Escapes HTML without allocating when nothing needs escaping.

Returns Cow::Borrowed(value) when value contains none of &, <, >, " or ', and otherwise the same string escape_html produces.

ยงExample

use metadata_gen::utils::escape_html_cow;
use std::borrow::Cow;

assert!(matches!(escape_html_cow("plain"), Cow::Borrowed("plain")));
assert_eq!(escape_html_cow("a < b"), "a &lt; b");