From a72aeef9f7f1baa059e26c9eb35204aa65bafb7d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 28 Jan 2013 19:32:02 -0800 Subject: [PATCH] Revert readline optimization and add test --- src/libcore/io.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 37e8784b68d..cf49ee0becc 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -185,13 +185,13 @@ impl T : ReaderUtil { } fn read_line(&self) -> ~str { - let mut line = ~""; + let mut bytes = ~[]; loop { let ch = self.read_byte(); if ch == -1 || ch == 10 { break; } - str::push_char(&mut line, ch as char); + bytes.push(ch as u8); } - line + str::from_bytes(bytes) } fn read_chars(&self, n: uint) -> ~[char] { @@ -1221,6 +1221,14 @@ mod tests { } } + #[test] + fn test_read_line_utf8() { + do io::with_str_reader(~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| { + let line = inp.read_line(); + assert line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤"; + } + } + #[test] fn test_readchars_wide() { let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";