Properly support ranges on hex dump
This commit is contained in:
@@ -7,13 +7,12 @@ const SEP: &str = " | ";
|
||||
pub struct HexDump<'s, T: Scannable + ?Sized, R: RangeBounds<usize>>(pub &'s T, pub R);
|
||||
|
||||
pub fn hex<
|
||||
's,
|
||||
T: Scannable + ?Sized,
|
||||
R: RangeBounds<usize>
|
||||
>(
|
||||
data: &'s T,
|
||||
data: &T,
|
||||
range:R
|
||||
) -> HexDump<'s, T, R> {
|
||||
) -> HexDump<T, R> {
|
||||
HexDump(data, range)
|
||||
}
|
||||
|
||||
@@ -48,6 +47,7 @@ impl<'s, T: Scannable + ?Sized, R: RangeBounds<usize>> Display for HexDump<'s, T
|
||||
// if there is nothing to print then just return...
|
||||
// this also prevents the ilog below from crashing :)
|
||||
if end == 0 || start > end {
|
||||
write!(f,"<empty>");
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ impl<'s, T: Scannable + ?Sized, R: RangeBounds<usize>> Display for HexDump<'s, T
|
||||
|
||||
for (mut addr, chunk) in ChunkIter::new(self.0, start) {
|
||||
for chunk in chunk.chunks(16) {
|
||||
if addr >= end { return Ok(()) }
|
||||
|
||||
let chunk = &chunk[..(end - addr).min(chunk.len())];
|
||||
|
||||
|
||||
//╶───╴Column╶────────────────────────────────╴
|
||||
write!(f, "{:0digits$X}{SEP}", addr, digits = digits)?;
|
||||
@@ -85,9 +89,6 @@ impl<'s, T: Scannable + ?Sized, R: RangeBounds<usize>> Display for HexDump<'s, T
|
||||
}
|
||||
}
|
||||
|
||||
let mut last_addr = 0usize;
|
||||
let fchunk = self.0.chunk_at(0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user