File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -419,6 +419,16 @@ mod test {
419
419
assert_eq ! ( r. read_to_str( ) , ~"testingtesting\n testing");
420
420
}
421
421
422
+ #[test]
423
+ fn test_write_char() {
424
+ let mut writer = MemWriter::new();
425
+ writer.write_char('a');
426
+ writer.write_char('\n ');
427
+ writer.write_char('ệ');
428
+ let mut r = BufReader::new(*writer.inner_ref());
429
+ assert_eq!(r.read_to_str(), ~" a\n ệ") ;
430
+ }
431
+
422
432
#[ test]
423
433
fn test_read_whole_string_bad( ) {
424
434
let buf = [ 0xff ] ;
Original file line number Diff line number Diff line change @@ -284,6 +284,7 @@ Out of scope
284
284
#[ allow( missing_doc) ] ;
285
285
286
286
use cast;
287
+ use char:: Char ;
287
288
use condition:: Guard ;
288
289
use container:: Container ;
289
290
use int;
@@ -902,6 +903,13 @@ pub trait Writer {
902
903
self . write ( [ '\n' as u8 ] ) ;
903
904
}
904
905
906
+ /// Write a single char, encoded as UTF-8.
907
+ fn write_char ( & mut self , c : char ) {
908
+ let mut buf = [ 0u8 , ..4 ] ;
909
+ let n = c. encode_utf8 ( buf. as_mut_slice ( ) ) ;
910
+ self . write ( buf. slice_to ( n) ) ;
911
+ }
912
+
905
913
/// Write the result of passing n through `int::to_str_bytes`.
906
914
fn write_int ( & mut self , n : int ) {
907
915
int:: to_str_bytes ( n, 10 u, |bytes| self . write ( bytes) )
You can’t perform that action at this time.
0 commit comments