diff options
| author | Edward Barnard | 2015-08-28 15:52:54 +0700 | 
|---|---|---|
| committer | Edward Barnard | 2015-08-28 15:52:54 +0700 | 
| commit | b0b34ef55e1d8a3783b7ddfbf5612b9176b20e66 (patch) | |
| tree | 9161c6fd4e9ade5008151f6b014b3af298ef7207 /src | |
| parent | 8b1d9bba631334fc16229a419370deb1800b21bf (diff) | |
| download | rust-plist-b0b34ef55e1d8a3783b7ddfbf5612b9176b20e66.tar.bz2 | |
Remove dependency on rust-encoding
Diffstat (limited to 'src')
| -rw-r--r-- | src/ascii.rs | 0 | ||||
| -rw-r--r-- | src/binary.rs | 13 | ||||
| -rw-r--r-- | src/lib.rs | 8 | 
3 files changed, 16 insertions, 5 deletions
diff --git a/src/ascii.rs b/src/ascii.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/ascii.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<R: Read+Seek> StreamingParser<R> {  			(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::<BigEndian>())) +				} + +				let string = try!(String::from_utf16(&raw_utf16));  				Some(PlistEvent::StringValue(string))  			},  			(0xa, n) => { // Array @@ -1,5 +1,4 @@  extern crate byteorder; -extern crate encoding;  extern crate itertools;  extern crate rustc_serialize;  extern crate xml as xml_rs; @@ -11,6 +10,7 @@ use byteorder::Error as ByteorderError;  use std::collections::HashMap;  use std::io::{Read, Seek, SeekFrom};  use std::io::Error as IoError; +use std::string::FromUtf16Error;  #[derive(Clone, Debug, PartialEq)]  pub enum Plist { @@ -74,6 +74,12 @@ impl From<ByteorderError> for ParserError {  	}  } +impl From<FromUtf16Error> for ParserError { +	fn from(_: FromUtf16Error) -> ParserError { +		ParserError::InvalidData +	} +} +  pub enum StreamingParser<R: Read+Seek> {  	Xml(xml::StreamingParser<R>),  	Binary(binary::StreamingParser<R>)  | 
