1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//! # htmlentity crate
//!
//! A library for encoding and decoding HTML entities.
//!
//! # Examples
//!
//! ```
//! use htmlentity::entity::{
//! encode, decode,
//! EncodeType, CharacterSet, ICodedDataTrait
//! };
//! use htmlentity::types::{ AnyhowResult, Byte };
//! # fn main() -> AnyhowResult<()> {
//! let html = "<div name='htmlentity'>Hello!世界!</div>";
//! let html_after_encoded = "<div name='htmlentity'>Hello!世界!</div>";
//! // encode
//! let encoded_data = encode(
//! html.as_bytes(),
//! &EncodeType::NamedOrHex,
//! &CharacterSet::HtmlAndNonASCII
//! );
//! // encoded data to bytes
//! assert_eq!(
//! encoded_data.to_bytes(),
//! html_after_encoded.as_bytes()
//! );
//! // encoded data to string
//! assert_eq!(
//! encoded_data.to_string()?,
//! String::from(html_after_encoded)
//! );
//! // encoded data to chars
//! assert_eq!(
//! encoded_data.to_chars()?,
//! String::from(html_after_encoded).chars().collect::<Vec<char>>()
//! );
//! // decode
//! let bytes = encoded_data
//! .into_iter()
//! .map(|(byte, _)| *byte)
//! .collect::<Vec<Byte>>();
//! let decoded_data = decode(&bytes);
//! // decoded data to bytes
//! assert_eq!(
//! decoded_data.to_bytes(),
//! html.as_bytes()
//! );
//! // decoded data to string
//! assert_eq!(
//! decoded_data.to_string()?,
//! String::from(html)
//! );
//! // decoded data to chars
//! assert_eq!(
//! decoded_data.to_chars()?,
//! String::from(html).chars().collect::<Vec<char>>()
//! );
//! # Ok(())
//! # }
//! ```
/// The html entities data.
pub mod data;
/// The library main module.
pub mod entity;
/// The library's types.
pub mod types;