From b0b34ef55e1d8a3783b7ddfbf5612b9176b20e66 Mon Sep 17 00:00:00 2001 From: Edward Barnard Date: Fri, 28 Aug 2015 15:52:54 +0700 Subject: Remove dependency on rust-encoding --- src/binary.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/binary.rs') diff --git a/src/binary.rs b/src/binary.rs index 0640d4f..ef293cb 100644 --- a/src/binary.rs +++ b/src/binary.rs @@ -1,8 +1,6 @@ use byteorder::{BigEndian, ReadBytesExt}; -use encoding::all::UTF_16BE; -use encoding::types::{DecoderTrap, Encoding}; use itertools::Interleave; -use std::io::{Read, Seek, SeekFrom}; +use std::io::{Cursor, Read, Seek, SeekFrom}; use super::{ParserError, ParserResult, PlistEvent}; @@ -179,7 +177,14 @@ impl StreamingParser { (0x6, n) => { // UTF-16 string let len = try!(self.read_object_len(n)); let raw = try!(self.read_data(len)); - let string = UTF_16BE.decode(&raw, DecoderTrap::Strict).unwrap(); + let mut cursor = Cursor::new(raw); + + let mut raw_utf16 = Vec::with_capacity(len as usize / 2); + while cursor.position() < len { + raw_utf16.push(try!(cursor.read_u16::())) + } + + let string = try!(String::from_utf16(&raw_utf16)); Some(PlistEvent::StringValue(string)) }, (0xa, n) => { // Array -- cgit v1.2.3