diff --git a/bin/src/main.rs b/bin/src/main.rs index c32045b..5f97f63 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -110,14 +110,14 @@ impl OutRow { } fn from_bad_char(err: Utf8Error) -> Self { - let (bad_bytes, num_bad_bytes) = err.into_parts(); + let (bad_bytes, _num_bad_bytes, num_consumed_bad_bytes) = err.into_parts(); Self { display_char: CappedString::new_truncating("\u{fffd}"), codepoint: Optional::None, utf_8_bytes: Utf8Bytes { buf: bad_bytes, - len: num_bad_bytes, + len: num_consumed_bad_bytes, }, name: Optional::Some(""), category: Optional::None, diff --git a/lib/src/utf8.rs b/lib/src/utf8.rs index a15e18e..e98e4c3 100644 --- a/lib/src/utf8.rs +++ b/lib/src/utf8.rs @@ -128,6 +128,7 @@ where return Some(Err(Utf8Error { bad_bytes: bytes_seen, num_bad_bytes: 1, + num_consumed_bad_bytes: 1, })); }, } @@ -140,6 +141,7 @@ where None => return Some(Err(Utf8Error { bad_bytes: bytes_seen, num_bad_bytes: usize::from(i) + 1, + num_consumed_bad_bytes: usize::from(i), })), }; @@ -149,6 +151,7 @@ where return Some(Err(Utf8Error { bad_bytes: bytes_seen, num_bad_bytes: usize::from(i) + 2, + num_consumed_bad_bytes: usize::from(i) + 1, })); } @@ -172,6 +175,7 @@ where pub struct Utf8Error { bad_bytes: [u8; 4], num_bad_bytes: usize, + num_consumed_bad_bytes: usize, } impl Utf8Error { @@ -179,8 +183,9 @@ impl Utf8Error { &self.bad_bytes[..self.num_bad_bytes] } - pub fn into_parts(self) -> ([u8; 4], usize) { - (self.bad_bytes, self.num_bad_bytes) + // FIXME: return some type with u8 array + length + pub fn into_parts(self) -> ([u8; 4], usize, usize) { + (self.bad_bytes, self.num_bad_bytes, self.num_consumed_bad_bytes) } }