comparison src/th06/ecl.rs @ 669:1bb8b34dbd32

Don’t allocate a Vec while reading a String in ECL.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 12 Aug 2019 15:10:19 +0200
parents 965ecdbf0316
children 3e4cc64a254d
comparison
equal deleted inserted replaced
668:140ee7de6d90 669:1bb8b34dbd32
133 } 133 }
134 134
135 /// Parse a SHIFT_JIS byte string of length 34 into a String. 135 /// Parse a SHIFT_JIS byte string of length 34 into a String.
136 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> { 136 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> {
137 assert_eq!(i.len(), 34); 137 assert_eq!(i.len(), 34);
138 let data = i.splitn(2, |c| *c == b'\0').collect::<Vec<_>>()[0]; 138 let data = i.splitn(2, |c| *c == b'\0').nth(0).unwrap();
139 let (string, encoding, replaced) = SHIFT_JIS.decode(data); 139 let (string, encoding, replaced) = SHIFT_JIS.decode(data);
140 Ok((&i[34..], string.into_owned())) 140 Ok((&i[34..], string.into_owned()))
141 } 141 }
142 142
143 macro_rules! declare_sub_instructions { 143 macro_rules! declare_sub_instructions {