(&self, f: &mut Formatter<'_>)
| 469 | |
| 470 | #[cfg(feature = "egg")] |
| 471 | fn fmt_expanded_string(&self, f: &mut Formatter<'_>) -> Result { |
| 472 | let token = self.token(); |
| 473 | let inner = &self.source[1..(token.len() as usize) - token.has_close_quote() as usize]; |
| 474 | // Use the opposite quote style to maximize escaping opportunity |
| 475 | let (open_quote, close_quote, escape_char) = match token.quote_style() { |
| 476 | QuoteStyle::Single => ('"', '"', '"'), |
| 477 | QuoteStyle::Double => ('\'', '\'', '\''), |
| 478 | QuoteStyle::None => unreachable!(), |
| 479 | }; |
| 480 | f.write_char(open_quote)?; |
| 481 | for c in inner.chars() { |
| 482 | if c == escape_char { |
| 483 | // Escape the quote character |
| 484 | write!(f, "\\{:06x} ", c as u32)?; |
| 485 | } else if c.is_ascii() && !c.is_ascii_control() { |
| 486 | // Escape all printable ASCII as hex |
| 487 | write!(f, "\\{:06x} ", c as u32)?; |
| 488 | } else { |
| 489 | // Non-ASCII or control chars: write as-is or escape |
| 490 | write!(f, "\\{:06x} ", c as u32)?; |
| 491 | } |
| 492 | } |
| 493 | f.write_char(close_quote)?; |
| 494 | Ok(()) |
| 495 | } |
| 496 | |
| 497 | pub fn eq_ignore_ascii_case(&self, other: &str) -> bool { |
| 498 | debug_assert!(self.token() != Kind::Delim && self.token() != Kind::Url); |
no test coverage detected