Restore Writer.write_char, see #10861.
This commit is contained in:
parent
239fb1f6ee
commit
195b23b34f
|
@ -419,6 +419,16 @@ mod test {
|
|||
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];
|
||||
|
|
|
@ -284,6 +284,7 @@ Out of scope
|
|||
#[allow(missing_doc)];
|
||||
|
||||
use cast;
|
||||
use char::Char;
|
||||
use condition::Guard;
|
||||
use container::Container;
|
||||
use int;
|
||||
|
@ -902,6 +903,13 @@ pub trait Writer {
|
|||
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))
|
||||
|
|
Loading…
Reference in New Issue