changeset 651:5f02984dd12a

Fix SHIFT_JIS parsing to not include nul bytes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 08 Aug 2019 17:13:20 +0200
parents f6bfc9e6dab0
children 93bdc7b9df15
files src/th06/ecl.rs
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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::<Vec<_>>()[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 });
     }