std: remove str::NullTerminatedStr

This commit is contained in:
Erick Tryzelaar 2013-07-03 20:02:09 -07:00
parent fd293dfb0f
commit dca9ff9a13
3 changed files with 2 additions and 76 deletions

View file

@ -63,7 +63,7 @@ pub use path::PosixPath;
pub use path::WindowsPath;
pub use ptr::RawPtr;
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, ToBytesConsume};
pub use str::{Str, StrVector, StrSlice, OwnedStr, NullTerminatedStr};
pub use str::{Str, StrVector, StrSlice, OwnedStr};
pub use from_str::{FromStr};
pub use to_bytes::IterBytes;
pub use to_str::{ToStr, ToStrConsume};

View file

@ -1981,35 +1981,6 @@ impl<'self> StrSlice<'self> for &'self str {
}
}
#[allow(missing_doc)]
pub trait NullTerminatedStr {
fn as_bytes_with_null<'a>(&'a self) -> &'a [u8];
}
impl NullTerminatedStr for ~str {
/// Work with the byte buffer of a string as a byte slice.
///
/// The byte slice does include the null terminator.
#[inline]
fn as_bytes_with_null<'a>(&'a self) -> &'a [u8] {
let ptr: &'a ~[u8] = unsafe { cast::transmute(self) };
let slice: &'a [u8] = *ptr;
slice
}
}
impl NullTerminatedStr for @str {
/// Work with the byte buffer of a string as a byte slice.
///
/// The byte slice does include the null terminator.
#[inline]
fn as_bytes_with_null<'a>(&'a self) -> &'a [u8] {
let ptr: &'a @[u8] = unsafe { cast::transmute(self) };
let slice: &'a [u8] = *ptr;
slice
}
}
#[allow(missing_doc)]
pub trait OwnedStr {
fn push_str_no_overallocate(&mut self, rhs: &str);
@ -2979,30 +2950,6 @@ mod tests {
assert_eq!("ศไทย中华Việt Nam".as_bytes(), v);
}
#[test]
fn test_as_bytes_with_null() {
// has null
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
];
let s1 = @"";
let s2 = @"abc";
let s3 = @"ศไทย中华Việt Nam";
assert_eq!(s1.as_bytes_with_null(), &[0]);
assert_eq!(s2.as_bytes_with_null(), &['a' as u8, 'b' as u8, 'c' as u8, 0]);
assert_eq!(s3.as_bytes_with_null(), v);
let s1 = ~"";
let s2 = ~"abc";
let s3 = ~"ศไทย中华Việt Nam";
assert_eq!(s1.as_bytes_with_null(), &[0]);
assert_eq!(s2.as_bytes_with_null(), &['a' as u8, 'b' as u8, 'c' as u8, 0]);
assert_eq!(s3.as_bytes_with_null(), v);
}
#[test]
fn test_to_bytes_with_null() {
let s = ~"ศไทย中华Việt Nam";
@ -3024,7 +2971,7 @@ mod tests {
// Don't double free. (I'm not sure if this exercises the
// original problem code path anymore.)
let s = ~"";
let _bytes = s.as_bytes_with_null();
let _bytes = s.as_bytes();
fail!();
}