lewp_css/domain/
custom_ident.rs1use {
5 super::Atom,
6 crate::CustomParseError,
7 cssparser::{CowRcStr, ParseError, ToCss},
8 std::fmt,
9};
10
11#[derive(Clone, Debug, Eq, Hash, PartialEq)]
13pub struct CustomIdent(pub Atom);
14
15impl CustomIdent {
16 pub(crate) fn from_ident<'i>(
18 ident: &CowRcStr<'i>,
19 excluding: &[&str],
20 ) -> Result<Self, ParseError<'i, CustomParseError<'i>>> {
21 match_ignore_ascii_case! {
22 ident,
23 "initial" | "inherit" | "unset" | "default" => return Err(ParseError::from(CustomParseError::UnexpectedCustomIdent(ident.clone()))),
24 _ =>
25 {
26 }
27 };
28
29 if excluding.iter().any(|s| ident.eq_ignore_ascii_case(s)) {
30 Err(ParseError::from(CustomParseError::CustomIdentWasExcluded(
31 ident.clone(),
32 )))
33 } else {
34 Ok(CustomIdent(Atom::from(ident)))
35 }
36 }
37}
38
39impl ToCss for CustomIdent {
40 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
41 self.0.to_css(dest)
42 }
43}