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

Method write

crates/css_parse/src/cursor_compact_write_sink.rs:48–96  ·  view source on GitHub ↗
(&mut self, c: SourceCursor<'a>)

Source from the content-addressed store, hash-verified

46 }
47
48 fn write(&mut self, c: SourceCursor<'a>) {
49 if c == Kind::Comment {
50 let can_separate =
51 self.pending.is_none() && self.pending_comment.is_none() && !self.last_forbids_ws_after();
52 if can_separate {
53 self.pending_comment = Some(c);
54 }
55 return;
56 }
57 if self.pending_comment.take().is_some()
58 && c != Kind::Whitespace
59 && c != Kind::Eof
60 && self.needs_separator(c.token())
61 {
62 self.emit(SourceCursor::EMPTY_COMMENT);
63 }
64
65 if c == Kind::Whitespace && self.pending.is_some_and(|c| c == Kind::Semicolon) {
66 return;
67 }
68
69 let suppress_separator = self.last_forbids_ws_after();
70 if let Some(prev) = self.pending.take() {
71 let keep = match prev.token().kind() {
72 Kind::Semicolon => {
73 c != REDUNDANT_SEMI_KINDSET && self.last_token.is_some_and(|t| t != REDUNDANT_SEMI_KINDSET)
74 }
75 _ => !suppress_separator && c != NO_WHITESPACE_BEFORE_KINDSET && self.needs_separator(c.token()),
76 };
77 if keep {
78 self.emit(prev.compact());
79 }
80 }
81
82 if c == PENDING_KINDSET {
83 self.pending = Some(c);
84 return;
85 }
86 if c == Kind::Eof {
87 return;
88 }
89
90 if !suppress_separator && self.needs_separator(c.token()) {
91 self.sink.append(SourceCursor::SPACE);
92 }
93
94 let out = if c == Kind::String { c.with_quotes(QuoteStyle::Double).compact() } else { c.compact() };
95 self.emit(out);
96 }
97}
98
99impl<'a, T: SourceCursorSink<'a>> Drop for CursorCompactWriteSink<'a, T> {

Callers 1

appendMethod · 0.45

Calls 8

last_forbids_ws_afterMethod · 0.80
needs_separatorMethod · 0.80
emitMethod · 0.80
compactMethod · 0.80
tokenMethod · 0.45
kindMethod · 0.45
appendMethod · 0.45
with_quotesMethod · 0.45

Tested by

no test coverage detected