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

Method fmt

crates/css_lexer/src/source_cursor.rs:32–70  ·  view source on GitHub ↗
(&self, f: &mut Formatter<'_>)

Source from the content-addressed store, hash-verified

30
31impl<'a> Display for SourceCursor<'a> {
32 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
33 match self.token().kind() {
34 Kind::Eof => Ok(()),
35 #[cfg(feature = "egg")]
36 Kind::String if self.should_expand => self.fmt_expanded_string(f),
37 Kind::String if self.should_compact && self.token().contains_escape_chars() => self.fmt_compacted_string(f),
38 // It is important to manually write out quotes for 2 reasons:
39 // 1. The quote style can be mutated from the source string (such as the case of normalising/switching quotes.
40 // 2. Some strings may not have the closing quote, which should be corrected.
41 Kind::String => match self.token().quote_style() {
42 QuoteStyle::Single => {
43 let inner =
44 &self.source[1..(self.token().len() as usize) - self.token().has_close_quote() as usize];
45 write!(f, "'{inner}'")
46 }
47 QuoteStyle::Double => {
48 let inner =
49 &self.source[1..(self.token().len() as usize) - self.token().has_close_quote() as usize];
50 write!(f, "\"{inner}\"")
51 }
52 // Strings must always be quoted!
53 QuoteStyle::None => unreachable!(),
54 },
55 Kind::Delim
56 | Kind::Colon
57 | Kind::Semicolon
58 | Kind::Comma
59 | Kind::LeftSquare
60 | Kind::LeftParen
61 | Kind::RightSquare
62 | Kind::RightParen
63 | Kind::LeftCurly
64 | Kind::RightCurly => self.token().char().unwrap().fmt(f),
65 _ if self.should_compact => self.fmt_compacted(f),
66 #[cfg(feature = "egg")]
67 _ if self.should_expand => self.fmt_expanded(f),
68 _ => f.write_str(self.source),
69 }
70 }
71}
72
73impl<'a> SourceCursor<'a> {

Callers 1

fmt_compacted_numberMethod · 0.45

Calls 12

fmt_expanded_stringMethod · 0.80
contains_escape_charsMethod · 0.80
fmt_compacted_stringMethod · 0.80
quote_styleMethod · 0.80
has_close_quoteMethod · 0.80
charMethod · 0.80
fmt_compactedMethod · 0.80
fmt_expandedMethod · 0.80
write_strMethod · 0.80
kindMethod · 0.45
tokenMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected