Reversible display for raw Git path/ref bytes.
(bytes: &[u8])
| 1487 | |
| 1488 | /// Reversible display for raw Git path/ref bytes. |
| 1489 | pub fn display_git_bytes(bytes: &[u8]) -> String { |
| 1490 | let mut output = String::new(); |
| 1491 | for byte in bytes { |
| 1492 | match *byte { |
| 1493 | b' '..=b'~' if *byte != b'\\' => output.push(*byte as char), |
| 1494 | b'\\' => output.push_str("\\\\"), |
| 1495 | _ => output.push_str(&format!("\\x{byte:02x}")), |
| 1496 | } |
| 1497 | } |
| 1498 | output |
| 1499 | } |
| 1500 | |
| 1501 | #[cfg(test)] |
| 1502 | mod tests { |