MCPcopy Index your code
hub / github.com/RustPython/RustPython / into_string_lossy

Method into_string_lossy

crates/wtf8/src/lib.rs:548–557  ·  view source on GitHub ↗

Consumes the WTF-8 string and converts it lossily to UTF-8. This does not copy the data (but may overwrite parts of it in place). Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”)

(mut self)

Source from the content-addressed store, hash-verified

546 ///
547 /// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”)
548 pub fn into_string_lossy(mut self) -> String {
549 let mut pos = 0;
550 while let Some((surrogate_pos, _)) = self.next_surrogate(pos) {
551 pos = surrogate_pos + 3;
552 // Surrogates and the replacement character are all 3 bytes, so
553 // they can substituted in-place.
554 self.bytes[surrogate_pos..pos].copy_from_slice(UTF8_REPLACEMENT_CHARACTER.as_bytes());
555 }
556 unsafe { String::from_utf8_unchecked(self.bytes) }
557 }
558
559 /// Converts this `Wtf8Buf` into a boxed `Wtf8`.
560 #[inline]

Callers

nothing calls this directly

Calls 2

next_surrogateMethod · 0.80
as_bytesMethod · 0.45

Tested by

no test coverage detected