From 9ad815e063e8c7785cc10ea1afac55a19ea4e51a Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 23 Jul 2013 16:56:17 -0700 Subject: [PATCH] std: rename str.as_bytes_with_null_consume to str.to_bytes_with_null --- src/libextra/terminfo/parm.rs | 2 +- src/libstd/str.rs | 13 ++++++------- src/test/run-pass/foreign-fn-linkname.rs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libextra/terminfo/parm.rs b/src/libextra/terminfo/parm.rs index b182a9057bd..114ab6702ae 100644 --- a/src/libextra/terminfo/parm.rs +++ b/src/libextra/terminfo/parm.rs @@ -545,7 +545,7 @@ impl FormatOp { String(s) => { match op { FormatString => { - let mut s = s.as_bytes_with_null_consume(); + let mut s = s.to_bytes_with_null(); s.pop(); // remove the null if flags.precision > 0 && flags.precision < s.len() { s.truncate(flags.precision); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 125df156ed0..3987f260065 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2073,8 +2073,7 @@ pub trait OwnedStr { fn reserve(&mut self, n: uint); fn reserve_at_least(&mut self, n: uint); fn capacity(&self) -> uint; - - fn as_bytes_with_null_consume(self) -> ~[u8]; + fn to_bytes_with_null(self) -> ~[u8]; } impl OwnedStr for ~str { @@ -2263,7 +2262,7 @@ fn capacity(&self) -> uint { /// Convert to a vector of bytes. This does not allocate a new /// string, and includes the null terminator. #[inline] - fn as_bytes_with_null_consume(self) -> ~[u8] { + fn to_bytes_with_null(self) -> ~[u8] { unsafe { ::cast::transmute(self) } } } @@ -3065,17 +3064,17 @@ fn test_as_bytes_with_null() { } #[test] - fn test_as_bytes_with_null_consume() { + fn test_to_bytes_with_null() { let s = ~"ศไทย中华Việt Nam"; let v = ~[ 224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228, 184, 173, 229, 141, 142, 86, 105, 225, 187, 135, 116, 32, 78, 97, 109, 0 ]; - assert_eq!((~"").as_bytes_with_null_consume(), ~[0]); - assert_eq!((~"abc").as_bytes_with_null_consume(), + assert_eq!((~"").to_bytes_with_null(), ~[0]); + assert_eq!((~"abc").to_bytes_with_null(), ~['a' as u8, 'b' as u8, 'c' as u8, 0]); - assert_eq!(s.as_bytes_with_null_consume(), v); + assert_eq!(s.to_bytes_with_null(), v); } #[test] diff --git a/src/test/run-pass/foreign-fn-linkname.rs b/src/test/run-pass/foreign-fn-linkname.rs index f0cac8f2f3e..38f36dd258b 100644 --- a/src/test/run-pass/foreign-fn-linkname.rs +++ b/src/test/run-pass/foreign-fn-linkname.rs @@ -26,7 +26,7 @@ mod libc { fn strlen(str: ~str) -> uint { unsafe { // C string is terminated with a zero - let bytes = str.as_bytes_with_null_consume(); + let bytes = str.to_bytes_with_null(); return libc::my_strlen(vec::raw::to_ptr(bytes)); } } -- 2.44.0