comparison src/th06/ecl.rs @ 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 31fc0d881105
comparison
equal deleted inserted replaced
650:f6bfc9e6dab0 651:5f02984dd12a
95 Ok((i, instr)) 95 Ok((i, instr))
96 } 96 }
97 }; 97 };
98 } 98 }
99 99
100 /// XXX 100 /// Parse a SHIFT_JIS byte string of length 34 into a String.
101 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> { 101 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> {
102 let (string, encoding, replaced) = SHIFT_JIS.decode(i); 102 assert_eq!(i.len(), 34);
103 let data = i.splitn(2, |c| *c == b'\0').collect::<Vec<_>>()[0];
104 let (string, encoding, replaced) = SHIFT_JIS.decode(data);
103 Ok((&i[34..], string.into_owned())) 105 Ok((&i[34..], string.into_owned()))
104 } 106 }
105 107
106 macro_rules! declare_sub_instructions { 108 macro_rules! declare_sub_instructions {
107 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => { 109 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => {
299 let (data, instr) = parse_sub_instruction_args(data, opcode)?; 301 let (data, instr) = parse_sub_instruction_args(data, opcode)?;
300 assert_eq!(data.len(), 0); 302 assert_eq!(data.len(), 0);
301 instructions.push(CallSub { time, rank_mask, param_mask, instr }); 303 instructions.push(CallSub { time, rank_mask, param_mask, instr });
302 i = &i[size as usize..]; 304 i = &i[size as usize..];
303 } 305 }
304 println!("{:#?}", instructions);
305 subs.push(Sub { instructions }); 306 subs.push(Sub { instructions });
306 } 307 }
307 308
308 // Read all mains (always a single one atm). 309 // Read all mains (always a single one atm).
309 let mut mains = Vec::new(); 310 let mut mains = Vec::new();