use crate::prelude::*;
#[sanitizer]
pub struct RgbHex;
impl Sanitizer<String> for RgbHex {
fn sanitize(&self, value: String) -> String {
let hex = value.trim_start_matches('#').to_ascii_uppercase();
if hex.len() == 6 {
hex
} else {
String::from("FFFFFF")
}
}
}
#[sanitizer]
pub struct RgbaHex;
impl Sanitizer<String> for RgbaHex {
fn sanitize(&self, value: String) -> String {
let hex = value.trim_start_matches('#').to_ascii_uppercase();
match hex.len() {
6 => format!("{hex}FF"),
8 => hex,
_ => String::from("FFFFFFFF"),
}
}
}