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

Method fmt_expanded_ident

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

Source from the content-addressed store, hash-verified

414
415 #[cfg(feature = "egg")]
416 fn fmt_expanded_ident(&self, f: &mut Formatter<'_>) -> Result {
417 let token = self.token();
418 let start = token.leading_len() as usize;
419 let end = self.source.len() - token.trailing_len() as usize;
420 let source = &self.source[start..end];
421
422 match token.kind() {
423 Kind::AtKeyword => f.write_str("@")?,
424 Kind::Hash => f.write_str("#")?,
425 _ => {}
426 }
427
428 let mut chars = source.chars().peekable();
429 let mut i = 0;
430 while let Some(c) = chars.next() {
431 if c == '\0' {
432 write!(f, "\\{:06x} ", 0xFFFDu32)?;
433 i += 1;
434 } else if c == '\\' {
435 i += 1;
436 let (ch, n) = source[i..].chars().parse_escape_sequence();
437 write!(f, "\\{:06x} ", if ch == '\0' { REPLACEMENT_CHARACTER } else { ch } as u32)?;
438 i += n as usize;
439 chars = source[i..].chars().peekable();
440 } else {
441 write!(f, "\\{:06x} ", c as u32)?;
442 i += c.len_utf8();
443 }
444 }
445
446 if token.kind() == Kind::Function {
447 f.write_str("(")?;
448 }
449
450 Ok(())
451 }
452
453 #[cfg(feature = "egg")]
454 fn fmt_expanded_url(&self, f: &mut Formatter<'_>) -> Result {

Callers 1

fmt_expandedMethod · 0.80

Calls 8

leading_lenMethod · 0.80
trailing_lenMethod · 0.80
write_strMethod · 0.80
tokenMethod · 0.45
lenMethod · 0.45
kindMethod · 0.45
nextMethod · 0.45
parse_escape_sequenceMethod · 0.45

Tested by

no test coverage detected