ascii::Char-ify the escaping code

This means that `EscapeIterInner::as_str` no longer needs unsafe code, because the type system ensures the internal buffer is only ASCII, and thus valid UTF-8.
This commit is contained in:
Scott McMurray
2023-05-12 19:37:02 -07:00
parent 4a59ba4d54
commit 28449daa22
5 changed files with 65 additions and 50 deletions

View File

@@ -91,7 +91,7 @@ pub struct EscapeDefault(escape::EscapeIterInner<4>);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn escape_default(c: u8) -> EscapeDefault {
let mut data = [0; 4];
let mut data = [Char::Null; 4];
let range = escape::escape_ascii_into(&mut data, c);
EscapeDefault(escape::EscapeIterInner::new(data, range))
}