| #[derive(Clone, Copy, Eq, PartialEq)] |
| /// The state after seeing a `\`. |
| /// The state after seeing a `\x`. |
| /// The state after seeing a `\x[0-9A-Fa-f]`. |
| pub fn unescape(s: &str) -> Vec<u8> { |
| bytes.extend(format!(r"\{}", c).into_bytes()); |
| '0'..='9' | 'A'..='F' | 'a'..='f' => { |
| bytes.extend(format!(r"\x{}", c).into_bytes()); |
| HexSecond(first) => match c { |
| '0'..='9' | 'A'..='F' | 'a'..='f' => { |
| let ordinal = format!("{}{}", first, c); |
| let byte = u8::from_str_radix(&ordinal, 16).unwrap(); |
| let original = format!(r"\x{}{}", first, c); |
| bytes.extend(original.into_bytes()); |
| bytes.extend(c.to_string().as_bytes()); |
| Escape => bytes.push(b'\\'), |
| HexFirst => bytes.extend(b"\\x"), |
| HexSecond(c) => bytes.extend(format!("\\x{}", c).into_bytes()), |