MCPcopy Create free account
hub / github.com/csskit/csskit / len

Method len

crates/css_lexer/src/token.rs:692–723  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

690 /// Returns the amount of characters (utf-8 code points) this Token represents in the underlying source text.
691 #[inline]
692 pub const fn len(&self) -> u32 {
693 if self.kind_bits() == Kind::Eof as u8 {
694 0
695 } else if self.is_delim_like() {
696 debug_assert!(matches!(
697 self.kind(),
698 Kind::Delim
699 | Kind::Colon | Kind::Semicolon
700 | Kind::Comma | Kind::LeftSquare
701 | Kind::RightSquare
702 | Kind::LeftParen
703 | Kind::RightParen
704 | Kind::LeftCurly
705 | Kind::RightCurly
706 ));
707 self.char().unwrap().len_utf8() as u32
708 } else if self.kind_bits() & 0b1111 == Kind::Number as u8 {
709 self.numeric_len()
710 } else if self.kind_bits() & 0b1111 == Kind::Dimension as u8 {
711 if self.first_flag() {
712 self.numeric_len() + (self.0 >> 7 & 0b11111)
713 } else {
714 ((self.0 & LENGTH_MASK) >> 12) + (self.0 & !HALF_LENGTH_MASK)
715 }
716 } else if self.kind_bits() & 0b1111 == Kind::Hash as u8 {
717 self.0 & LENGTH_MASK
718 } else if self.kind_bits() == Kind::UnicodeRange as u8 {
719 self.1 >> 24
720 } else {
721 self.1
722 }
723 }
724
725 /// If the [Kind] is "Delim Like" (i.e. it is [Kind::Delim], [Kind::Colon], [Kind::Semicolon], [Kind::Comma],
726 /// [Kind::LeftSquare], [Kind::RightSquare], [Kind::LeftParen], [Kind::RightParen], [Kind::LeftCurly],

Callers 3

with_quotesMethod · 0.45
fmtMethod · 0.45
serializeMethod · 0.45

Calls 5

kind_bitsMethod · 0.80
is_delim_likeMethod · 0.80
charMethod · 0.80
numeric_lenMethod · 0.80
first_flagMethod · 0.80

Tested by

no test coverage detected