# HG changeset patch # User Emmanuel Gil Peyrot # Date 1565277200 -7200 # Node ID 5f02984dd12a5d0448de153fcabaee6ed699674b # Parent f6bfc9e6dab0824330ae6611ce986afe3eaacefc Fix SHIFT_JIS parsing to not include nul bytes. diff --git a/src/th06/ecl.rs b/src/th06/ecl.rs --- a/src/th06/ecl.rs +++ b/src/th06/ecl.rs @@ -97,9 +97,11 @@ macro_rules! declare_main_instructions { }; } -/// XXX +/// Parse a SHIFT_JIS byte string of length 34 into a String. pub fn le_String(i: &[u8]) -> IResult<&[u8], String> { - let (string, encoding, replaced) = SHIFT_JIS.decode(i); + assert_eq!(i.len(), 34); + let data = i.splitn(2, |c| *c == b'\0').collect::>()[0]; + let (string, encoding, replaced) = SHIFT_JIS.decode(data); Ok((&i[34..], string.into_owned())) } @@ -301,7 +303,6 @@ fn parse_ecl(input: &[u8]) -> IResult<&[ instructions.push(CallSub { time, rank_mask, param_mask, instr }); i = &i[size as usize..]; } - println!("{:#?}", instructions); subs.push(Sub { instructions }); }