mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 10:05:06 +03:00
auto merge of #11310 : Dretch/rust/write_char, r=alexcrichton
This commit is contained in:
@@ -419,6 +419,16 @@ fn test_write_strings() {
|
||||
assert_eq!(r.read_to_str(), ~"testingtesting\ntesting");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_char() {
|
||||
let mut writer = MemWriter::new();
|
||||
writer.write_char('a');
|
||||
writer.write_char('\n');
|
||||
writer.write_char('ệ');
|
||||
let mut r = BufReader::new(*writer.inner_ref());
|
||||
assert_eq!(r.read_to_str(), ~"a\nệ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_whole_string_bad() {
|
||||
let buf = [0xff];
|
||||
|
||||
@@ -290,6 +290,7 @@
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use cast;
|
||||
use char::Char;
|
||||
use condition::Guard;
|
||||
use container::Container;
|
||||
use int;
|
||||
@@ -914,6 +915,13 @@ fn write_line(&mut self, s: &str) {
|
||||
self.write(['\n' as u8]);
|
||||
}
|
||||
|
||||
/// Write a single char, encoded as UTF-8.
|
||||
fn write_char(&mut self, c: char) {
|
||||
let mut buf = [0u8, ..4];
|
||||
let n = c.encode_utf8(buf.as_mut_slice());
|
||||
self.write(buf.slice_to(n));
|
||||
}
|
||||
|
||||
/// Write the result of passing n through `int::to_str_bytes`.
|
||||
fn write_int(&mut self, n: int) {
|
||||
int::to_str_bytes(n, 10u, |bytes| self.write(bytes))
|
||||
|
||||
Reference in New Issue
Block a user