mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
remove unchecked_utf8 and read_in_unchecked
This commit is contained in:
parent
00e4efec86
commit
613199c089
2 changed files with 3 additions and 14 deletions
|
|
@ -17,7 +17,4 @@ bitstream_reader_derive = { version = "0.5", path = "bitstream_reader_derive" }
|
|||
[dev-dependencies]
|
||||
maplit = "1.0.1"
|
||||
|
||||
[features]
|
||||
unchecked_utf8 = []
|
||||
|
||||
[workspace]
|
||||
|
|
@ -255,7 +255,7 @@ where
|
|||
/// [`ReadError::NotEnoughData`]: enum.ReadError.html#variant.NotEnoughData
|
||||
/// [`ReadError::TooManyBits`]: enum.ReadError.html#variant.TooManyBits
|
||||
#[inline]
|
||||
pub fn read_int_unchecked<T>(&self, position: usize, count: usize) -> T
|
||||
fn read_int_unchecked<T>(&self, position: usize, count: usize) -> T
|
||||
where
|
||||
T: PrimInt + BitOrAssign + IsSigned + UncheckedPrimitiveInt,
|
||||
{
|
||||
|
|
@ -463,23 +463,15 @@ where
|
|||
match byte_len {
|
||||
Some(byte_len) => {
|
||||
let bytes = self.read_bytes(position, byte_len)?;
|
||||
let raw_string = if cfg!(feature = "unchecked_utf8") {
|
||||
unsafe { String::from_utf8_unchecked(bytes) }
|
||||
} else {
|
||||
String::from_utf8(bytes)?
|
||||
};
|
||||
let raw_string = String::from_utf8(bytes)?;
|
||||
Ok(raw_string.trim_end_matches(char::from(0)).to_owned())
|
||||
}
|
||||
None => {
|
||||
let bytes = self.read_string_bytes(position);
|
||||
if cfg!(feature = "unchecked_utf8") {
|
||||
unsafe { Ok(String::from_utf8_unchecked(bytes)) }
|
||||
} else {
|
||||
String::from_utf8(bytes).map_err(ReadError::from)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_string_bytes(&self, position: usize) -> Vec<u8> {
|
||||
let mut acc = Vec::with_capacity(32);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue