Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
hkratz committed Oct 31, 2024
1 parent b65f1ec commit 48168d0
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions portable/src/implementation/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,15 @@ impl Utf8ValidatorImp {
}
};
let rem_input = input.len() - e.valid_up_to() - 1;
if rem_input >= self.expected_cont_bytes as usize {
// too many continuation bytes so they are not valid
self.err = true;
return;
}
for i in 0..rem_input {
for i in 0..rem_input.min(self.expected_cont_bytes as usize) {
if input[e.valid_up_to() + i + 1] & 0b1100_0000 != 0b1000_0000 {
// not a continuation byte
self.err = true;
return;
}
self.expected_cont_bytes -= 1;
}
debug_assert!(self.expected_cont_bytes != 0); // otherwise from_utf8 would not have errored
}
}

Expand Down

0 comments on commit 48168d0

Please sign in to comment.