From 12bdc92ff14533b22185ca5bec40a134de68d209 Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Wed, 7 Jan 2015 03:31:20 +0100 Subject: [PATCH] Read strings in one go, not byte-by-byte. Also add a test with a unicode char. --- src/reader.rs | 5 +---- src/test.rs | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index e2d1a8e..3a897ad 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -71,10 +71,7 @@ impl<'a, R: Reader+Buffer> Decoder for DecoderReader<'a, R> { } fn read_str(&mut self) -> IoResult { 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(&mut self, _: &str, f: F) -> IoResult where diff --git a/src/test.rs b/src/test.rs index 159b5b1..a8a54e6 100644 --- a/src/test.rs +++ b/src/test.rs @@ -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]