Function rphtml::entity::encode_with_to

source ·
pub fn encode_with_to(
    content: &[u8],
    encode_type: &EncodeType,
    filter_fn: impl Fn(&char, &EncodeType) -> (bool, Option<(EntityType, Cow<'static, [u8]>)>),
    data: &mut Vec<u8>
)
Expand description

Similar to the encode_with method, but directly writes the byte data into the last parameter passed in.

§Examples

use htmlentity::entity::*;
use htmlentity::types::{ ByteList, AnyhowResult };
use std::borrow::Cow;
let html = "<div class='header'></div>";
let charset = CharacterSet::SpecialChars;
let mut data: ByteList = vec![];
let encoded_data = encode_with_to(&html.as_bytes(), &EncodeType::Named, |ch, encode_type|{
   return charset.filter(ch, encode_type);
}, &mut data);
assert_eq!(data, b"&lt;div class=&apos;header&apos;&gt;&lt;/div&gt;");