Skip to content

Commit

Permalink
CStr::count_bytes only arrived in 1.79
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpallant committed Nov 22, 2024
1 parent 057fc14 commit fbd7a99
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/strspn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ pub unsafe extern "C" fn strspn(s: *const CChar, charset: *const CChar) -> usize

let charset = unsafe { core::ffi::CStr::from_ptr(charset.cast()) };

for (idx, b) in s.to_bytes().iter().enumerate() {
let bytes = s.to_bytes();
for (idx, b) in bytes.iter().enumerate() {
if !is_c_in_charset(*b, charset) {
return idx;
}
}

s.count_bytes()
bytes.len()
}

fn is_c_in_charset(c: u8, charset: &core::ffi::CStr) -> bool {
Expand Down

0 comments on commit fbd7a99

Please sign in to comment.