(&mut self, text: &str)
| 346 | } |
| 347 | |
| 348 | fn write_escaped(&mut self, text: &str) -> Result<(), InlineError> { |
| 349 | let mut last_end = 0; |
| 350 | for (start, part) in text.match_indices(['&', '\u{00A0}', '<', '>']) { |
| 351 | self.writer.write_all( |
| 352 | text.get(last_end..start) |
| 353 | .expect("Invalid substring") |
| 354 | .as_bytes(), |
| 355 | )?; |
| 356 | // This is slightly faster than matching on `char` |
| 357 | // Notably, this approach does not work in `write_attributes` below |
| 358 | match (part.as_bytes()[0] & 0b0000_1110) >> 1 { |
| 359 | 1 => self.writer.write_all(b" ")?, |
| 360 | 3 => self.writer.write_all(b"&")?, |
| 361 | 6 => self.writer.write_all(b"<")?, |
| 362 | 7 => self.writer.write_all(b">")?, |
| 363 | _ => unreachable!(), |
| 364 | } |
| 365 | last_end = start.checked_add(part.len()).expect("Size overflow"); |
| 366 | } |
| 367 | self.writer.write_all( |
| 368 | text.get(last_end..text.len()) |
| 369 | .expect("Invalid substring") |
| 370 | .as_bytes(), |
| 371 | )?; |
| 372 | Ok(()) |
| 373 | } |
| 374 | |
| 375 | #[allow(clippy::arithmetic_side_effects)] |
| 376 | fn write_attributes(&mut self, text: &str) -> Result<(), InlineError> { |
no test coverage detected