Simplify unescape_{char,byte}.

The `usize` isn't needed in the error case.
This commit is contained in:
Nicholas Nethercote
2022-11-08 15:59:19 +11:00
parent 43d21b535f
commit d6c97a32b4
2 changed files with 9 additions and 17 deletions

View File

@@ -94,19 +94,15 @@ where
}
/// Takes a contents of a char literal (without quotes), and returns an
/// unescaped char or an error
pub fn unescape_char(src: &str) -> Result<char, (usize, EscapeError)> {
let mut chars = src.chars();
unescape_char_or_byte(&mut chars, false).map_err(|err| (src.len() - chars.as_str().len(), err))
/// unescaped char or an error.
pub fn unescape_char(src: &str) -> Result<char, EscapeError> {
unescape_char_or_byte(&mut src.chars(), false)
}
/// Takes a contents of a byte literal (without quotes), and returns an
/// unescaped byte or an error.
pub fn unescape_byte(src: &str) -> Result<u8, (usize, EscapeError)> {
let mut chars = src.chars();
unescape_char_or_byte(&mut chars, true)
.map(byte_from_char)
.map_err(|err| (src.len() - chars.as_str().len(), err))
pub fn unescape_byte(src: &str) -> Result<u8, EscapeError> {
unescape_char_or_byte(&mut src.chars(), true).map(byte_from_char)
}
/// What kind of literal do we parse.