Read strings in one go, not byte-by-byte.

Also add a test with a unicode char.
This commit is contained in:
Francesco Mazzoli 2015-01-07 03:31:20 +01:00
parent cea4129b05
commit 12bdc92ff1
2 changed files with 2 additions and 4 deletions

View File

@ -71,10 +71,7 @@ impl<'a, R: Reader+Buffer> Decoder for DecoderReader<'a, R> {
}
fn read_str(&mut self) -> IoResult<String> {
let len = try!(self.read_uint());
let mut vector = Vec::with_capacity(len as uint);
for _ in range(0, len) {
vector.push(try!(self.reader.read_u8()));
}
let vector = try!(self.reader.read_exact(len));
Ok(String::from_utf8(vector).unwrap())
}
fn read_enum<T, F>(&mut self, _: &str, f: F) -> IoResult<T> where

View File

@ -51,6 +51,7 @@ fn test_numbers() {
fn test_string() {
the_same("".to_string());
the_same("a".to_string());
the_same("ƒoo".to_string());
}
#[test]