use alloc::string::String;
pub fn encode(value: &str, encode_html: bool) -> String {
let mut result = String::with_capacity(value.len());
let bytes = value.as_bytes();
let mut index = 0;
let mut start = 0;
while index < bytes.len() {
let byte = bytes[index];
if matches!(byte, b'\0') || (encode_html && matches!(byte, b'&' | b'"' | b'<' | b'>')) {
result.push_str(&value[start..index]);
result.push_str(match byte {
b'\0' => "�",
b'&' => "&",
b'"' => """,
b'<' => "<",
_ => ">",
});
start = index + 1;
}
index += 1;
}
result.push_str(&value[start..]);
result
}