fix mac_roman_cstr API (should never fail)
parent
49b4b56aea
commit
745f32f3bd
|
@ -18,6 +18,7 @@ members = ["source/leela", "source/tycho"]
|
|||
bitflags = "1.0"
|
||||
failure = {version = "0.1", features = ["std"]}
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
memchr = "2.0"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
//! Text conversion utilities.
|
||||
|
||||
use crate::durandal::err::*;
|
||||
|
||||
/// Formats a binary size string for any given number.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -103,14 +101,17 @@ pub fn mac_roman_conv(s: &[u8]) -> String
|
|||
/// ```
|
||||
/// use maraiah::durandal::text::mac_roman_cstr;
|
||||
///
|
||||
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0ed").unwrap(), "I’ve awaken");
|
||||
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0ed"), "I’ve awaken");
|
||||
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0"), "I’ve awaken");
|
||||
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken"), "I’ve awaken");
|
||||
/// ```
|
||||
pub fn mac_roman_cstr(s: &[u8]) -> ResultS<String>
|
||||
#[inline]
|
||||
pub fn mac_roman_cstr(s: &[u8]) -> String
|
||||
{
|
||||
if let Some(s) = s.split(|&n| n == 0).nth(0) {
|
||||
Ok(mac_roman_conv(s))
|
||||
if let Some(n) = memchr::memchr(0, s) {
|
||||
mac_roman_conv(&s[..n])
|
||||
} else {
|
||||
bail!("no null in C string");
|
||||
mac_roman_conv(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ pub fn read_minf(b: &[u8]) -> ResultS<Minf>
|
|||
skypict_id = u16[4];
|
||||
miss_flags = u16[6];
|
||||
envi_flags = u16[8];
|
||||
level_name = mac_roman_cstr[18..84];
|
||||
level_name = mac_roman_cstr[18..84] no_try;
|
||||
entr_flags = u32[84];
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ pub fn read_note(b: &[u8]) -> ResultS<(Note, usize)>
|
|||
72, BE in b =>
|
||||
pos = read_point[2..6];
|
||||
poly = u16[6];
|
||||
text = mac_roman_cstr[8..72];
|
||||
text = mac_roman_cstr[8..72] no_try;
|
||||
}
|
||||
|
||||
Ok((Note{pos, poly, text}, 72))
|
||||
|
|
|
@ -83,7 +83,7 @@ pub fn read_term(b: &[u8]) -> ResultS<(Terminal, usize)>
|
|||
let beg = grp.beg;
|
||||
let len = grp.len;
|
||||
let text = ok!(text.get(beg..beg + len), "bad offset")?;
|
||||
let text = mac_roman_cstr(text)?;
|
||||
let text = mac_roman_cstr(text);
|
||||
|
||||
groups.push(Group{flags, ttype, lines, text});
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ pub fn read_wad(b: &[u8]) -> ResultS<Wad>
|
|||
128, BE in b =>
|
||||
ver_wad = u16[0];
|
||||
ver_dat = u16[2];
|
||||
name = mac_roman_cstr[4..68];
|
||||
name = mac_roman_cstr[4..68] no_try;
|
||||
siz_app = u16[78] usize;
|
||||
siz_wcnk = u16[80] usize;
|
||||
siz_went = u16[82] usize;
|
||||
|
|
Loading…
Reference in New Issue