MCPcopy Create free account
hub / github.com/Stranger6667/css-inline / write_attributes

Method write_attributes

css-inline/src/html/serializer.rs:376–403  ·  view source on GitHub ↗
(&mut self, text: &str)

Source from the content-addressed store, hash-verified

374
375 #[allow(clippy::arithmetic_side_effects)]
376 fn write_attributes(&mut self, text: &str) -> Result<(), InlineError> {
377 let bytes = text.as_bytes();
378 let mut last_end = 0;
379
380 // Scan for '&' (0x26), '"' (0x22), and 0xC2 (first byte of \u{00A0})
381 for idx in memchr3_iter(b'&', b'"', 0xC2, bytes) {
382 match bytes[idx] {
383 b'&' => {
384 self.writer.write_all(&bytes[last_end..idx])?;
385 self.writer.write_all(b"&amp;")?;
386 last_end = idx + 1;
387 }
388 b'"' => {
389 self.writer.write_all(&bytes[last_end..idx])?;
390 self.writer.write_all(b"&quot;")?;
391 last_end = idx + 1;
392 }
393 0xC2 if bytes.get(idx + 1) == Some(&0xA0) => {
394 self.writer.write_all(&bytes[last_end..idx])?;
395 self.writer.write_all(b"&nbsp;")?;
396 last_end = idx + 2; // Skip both bytes of \u{00A0}
397 }
398 _ => {} // False positive for 0xC2 not followed by 0xA0
399 }
400 }
401 self.writer.write_all(&bytes[last_end..])?;
402 Ok(())
403 }
404
405 #[allow(clippy::too_many_lines)]
406 fn start_elem(

Callers 1

start_elemMethod · 0.80

Calls 2

as_bytesMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected