diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-05-19 23:19:56 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-05-22 14:42:02 -0700 |
| commit | e878721d70349e2055f0ef854085de92e9498fde (patch) | |
| tree | 35940d52f145bca81dcf73e5e7da7f3847ceb413 /src/libstd | |
| parent | 5633d4641f7d63805e3c12c899f8401410bd825f (diff) | |
| download | rust-e878721d70349e2055f0ef854085de92e9498fde.tar.gz rust-e878721d70349e2055f0ef854085de92e9498fde.zip | |
libcore: Remove all uses of `~str` from `libcore`.
[breaking-change]
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 6 | ||||
| -rw-r--r-- | src/libstd/io/fs.rs | 9 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 6 | ||||
| -rw-r--r-- | src/libstd/os.rs | 61 | ||||
| -rw-r--r-- | src/libstd/rt/args.rs | 44 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 1 | ||||
| -rw-r--r-- | src/libstd/str.rs | 146 | ||||
| -rw-r--r-- | src/libstd/strbuf.rs | 7 | ||||
| -rw-r--r-- | src/libstd/unstable/dynamic_lib.rs | 5 |
9 files changed, 148 insertions, 137 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 0b3dd414967..e5689158601 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -656,7 +656,7 @@ mod tests { while i <= 500 { let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } else { i }; - assert_eq!(from_char(from_u32(i).unwrap()).to_ascii_upper(), + assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_upper(), from_char(from_u32(upper).unwrap()).to_strbuf()) i += 1; } @@ -672,7 +672,7 @@ mod tests { while i <= 500 { let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } else { i }; - assert_eq!(from_char(from_u32(i).unwrap()).to_ascii_lower(), + assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_lower(), from_char(from_u32(lower).unwrap()).to_strbuf()) i += 1; } @@ -730,7 +730,7 @@ mod tests { .eq_ignore_ascii_case( from_char( from_u32(lower) - .unwrap()))); + .unwrap()).as_slice())); i += 1; } } diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 6feaf10d5c5..d8edd6517d5 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -855,7 +855,7 @@ mod test { } check!(unlink(filename)); let read_str = str::from_utf8(read_mem).unwrap(); - assert!(read_str == final_msg.to_owned()); + assert!(read_str.as_slice() == final_msg.as_slice()); }) iotest!(fn file_test_io_seek_shakedown() { @@ -955,9 +955,8 @@ mod test { for n in range(0,3) { let f = dir.join(format_strbuf!("{}.txt", n)); let mut w = check!(File::create(&f)); - let msg_str = - (prefix + n.to_str().into_owned()).to_owned(); - let msg = msg_str.as_bytes(); + let msg_str = format!("{}{}", prefix, n.to_str()); + let msg = msg_str.as_slice().as_bytes(); check!(w.write(msg)); } let files = check!(readdir(dir)); @@ -969,7 +968,7 @@ mod test { let read_str = str::from_utf8(mem).unwrap(); let expected = match n { None|Some("") => fail!("really shouldn't happen.."), - Some(n) => prefix+n + Some(n) => format!("{}{}", prefix, n), }; assert_eq!(expected.as_slice(), read_str); } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index f1f3e0a468a..7d84530282f 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -827,10 +827,12 @@ mod tests { for &(ref k, ref v) in r.iter() { // don't check android RANDOM variables if *k != "RANDOM".to_strbuf() { - assert!(output.contains(format!("{}={}", + assert!(output.as_slice() + .contains(format!("{}={}", *k, *v).as_slice()) || - output.contains(format!("{}=\'{}\'", + output.as_slice() + .contains(format!("{}=\'{}\'", *k, *v).as_slice())); } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 349f50b8ac7..493dd86b276 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -41,7 +41,7 @@ use path::{Path, GenericPath}; use ptr::RawPtr; use ptr; use result::{Err, Ok, Result}; -use slice::{Vector, CloneableVector, ImmutableVector, MutableVector, OwnedVector}; +use slice::{Vector, ImmutableVector, MutableVector, OwnedVector}; use str::{Str, StrSlice, StrAllocating}; use str; use strbuf::StrBuf; @@ -104,6 +104,7 @@ pub mod win32 { use option; use os::TMPBUF_SZ; use slice::{MutableVector, ImmutableVector}; + use strbuf::StrBuf; use str::{StrSlice, StrAllocating}; use str; use vec::Vec; @@ -177,18 +178,18 @@ fn with_env_lock<T>(f: || -> T) -> T { /// for details. pub fn env() -> Vec<(StrBuf,StrBuf)> { env_as_bytes().move_iter().map(|(k,v)| { - let k = str::from_utf8_lossy(k).to_strbuf(); - let v = str::from_utf8_lossy(v).to_strbuf(); + let k = str::from_utf8_lossy(k.as_slice()).to_strbuf(); + let v = str::from_utf8_lossy(v.as_slice()).to_strbuf(); (k,v) }).collect() } /// Returns a vector of (variable, value) byte-vector pairs for all the /// environment variables of the current process. -pub fn env_as_bytes() -> Vec<(~[u8],~[u8])> { +pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> { unsafe { #[cfg(windows)] - unsafe fn get_env_pairs() -> Vec<~[u8]> { + unsafe fn get_env_pairs() -> Vec<Vec<u8>> { use slice::raw; use libc::funcs::extra::kernel32::{ @@ -228,7 +229,7 @@ pub fn env_as_bytes() -> Vec<(~[u8],~[u8])> { result } #[cfg(unix)] - unsafe fn get_env_pairs() -> Vec<~[u8]> { + unsafe fn get_env_pairs() -> Vec<Vec<u8>> { use c_str::CString; extern { @@ -241,18 +242,19 @@ pub fn env_as_bytes() -> Vec<(~[u8],~[u8])> { } let mut result = Vec::new(); ptr::array_each(environ, |e| { - let env_pair = CString::new(e, false).as_bytes_no_nul().to_owned(); + let env_pair = + Vec::from_slice(CString::new(e, false).as_bytes_no_nul()); result.push(env_pair); }); result } - fn env_convert(input: Vec<~[u8]>) -> Vec<(~[u8], ~[u8])> { + fn env_convert(input: Vec<Vec<u8>>) -> Vec<(Vec<u8>, Vec<u8>)> { let mut pairs = Vec::new(); for p in input.iter() { - let mut it = p.splitn(1, |b| *b == '=' as u8); - let key = it.next().unwrap().to_owned(); - let val = it.next().unwrap_or(&[]).to_owned(); + let mut it = p.as_slice().splitn(1, |b| *b == '=' as u8); + let key = Vec::from_slice(it.next().unwrap()); + let val = Vec::from_slice(it.next().unwrap_or(&[])); pairs.push((key, val)); } pairs @@ -275,7 +277,7 @@ pub fn env_as_bytes() -> Vec<(~[u8],~[u8])> { /// /// Fails if `n` has any interior NULs. pub fn getenv(n: &str) -> Option<StrBuf> { - getenv_as_bytes(n).map(|v| str::from_utf8_lossy(v).to_strbuf()) + getenv_as_bytes(n).map(|v| str::from_utf8_lossy(v.as_slice()).to_strbuf()) } #[cfg(unix)] @@ -285,7 +287,7 @@ pub fn getenv(n: &str) -> Option<StrBuf> { /// # Failure /// /// Fails if `n` has any interior NULs. -pub fn getenv_as_bytes(n: &str) -> Option<~[u8]> { +pub fn getenv_as_bytes(n: &str) -> Option<Vec<u8>> { use c_str::CString; unsafe { @@ -294,7 +296,8 @@ pub fn getenv_as_bytes(n: &str) -> Option<~[u8]> { if s.is_null() { None } else { - Some(CString::new(s, false).as_bytes_no_nul().to_owned()) + Some(Vec::from_slice(CString::new(s, + false).as_bytes_no_nul())) } }) } @@ -319,7 +322,7 @@ pub fn getenv(n: &str) -> Option<StrBuf> { #[cfg(windows)] /// Fetches the environment variable `n` byte vector from the current process, /// returning None if the variable isn't set. -pub fn getenv_as_bytes(n: &str) -> Option<~[u8]> { +pub fn getenv_as_bytes(n: &str) -> Option<Vec<u8>> { getenv(n).map(|s| s.into_bytes()) } @@ -528,7 +531,7 @@ pub fn self_exe_path() -> Option<Path> { * Otherwise, homedir returns option::none. */ pub fn homedir() -> Option<Path> { - // FIXME (#7188): getenv needs a ~[u8] variant + // FIXME (#7188): getenv needs a Vec<u8> variant return match getenv("HOME") { Some(ref p) if !p.is_empty() => Path::new_opt(p.as_slice()), _ => secondary() @@ -817,11 +820,12 @@ pub fn get_exit_status() -> int { } #[cfg(target_os = "macos")] -unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> Vec<~[u8]> { +unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> Vec<Vec<u8>> { use c_str::CString; Vec::from_fn(argc as uint, |i| { - CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_owned() + Vec::from_slice(CString::new(*argv.offset(i as int), + false).as_bytes_no_nul()) }) } @@ -831,7 +835,7 @@ unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> Vec<~[u8]> { * Returns a list of the command line arguments. */ #[cfg(target_os = "macos")] -fn real_args_as_bytes() -> Vec<~[u8]> { +fn real_args_as_bytes() -> Vec<Vec<u8>> { unsafe { let (argc, argv) = (*_NSGetArgc() as int, *_NSGetArgv() as **c_char); @@ -842,7 +846,7 @@ fn real_args_as_bytes() -> Vec<~[u8]> { #[cfg(target_os = "linux")] #[cfg(target_os = "android")] #[cfg(target_os = "freebsd")] -fn real_args_as_bytes() -> Vec<~[u8]> { +fn real_args_as_bytes() -> Vec<Vec<u8>> { use rt; match rt::args::clone() { @@ -854,8 +858,9 @@ fn real_args_as_bytes() -> Vec<~[u8]> { #[cfg(not(windows))] fn real_args() -> Vec<StrBuf> { real_args_as_bytes().move_iter() - .map(|v| str::from_utf8_lossy(v).into_strbuf()) - .collect() + .map(|v| { + str::from_utf8_lossy(v.as_slice()).into_strbuf() + }).collect() } #[cfg(windows)] @@ -889,7 +894,7 @@ fn real_args() -> Vec<StrBuf> { } #[cfg(windows)] -fn real_args_as_bytes() -> Vec<~[u8]> { +fn real_args_as_bytes() -> Vec<Vec<u8>> { real_args().move_iter().map(|s| s.into_bytes()).collect() } @@ -926,7 +931,7 @@ pub fn args() -> ::realstd::vec::Vec<::realstd::strbuf::StrBuf> { /// Returns the arguments which this program was started with (normally passed /// via the command line) as byte vectors. -pub fn args_as_bytes() -> Vec<~[u8]> { +pub fn args_as_bytes() -> Vec<Vec<u8>> { real_args_as_bytes() } @@ -1680,8 +1685,12 @@ mod tests { setenv("USERPROFILE", "/home/PaloAlto"); assert!(os::homedir() == Some(Path::new("/home/MountainView"))); - for s in oldhome.iter() { setenv("HOME", *s) } - for s in olduserprofile.iter() { setenv("USERPROFILE", *s) } + for s in oldhome.iter() { + setenv("HOME", s.as_slice()) + } + for s in olduserprofile.iter() { + setenv("USERPROFILE", s.as_slice()) + } } #[test] diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 95d0eabd336..cde20521c2f 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -37,8 +37,8 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } #[cfg(test)] pub unsafe fn cleanup() { realargs::cleanup() } /// Take the global arguments from global storage. -#[cfg(not(test))] pub fn take() -> Option<Vec<~[u8]>> { imp::take() } -#[cfg(test)] pub fn take() -> Option<Vec<~[u8]>> { +#[cfg(not(test))] pub fn take() -> Option<Vec<Vec<u8>>> { imp::take() } +#[cfg(test)] pub fn take() -> Option<Vec<Vec<u8>>> { match realargs::take() { realstd::option::Some(v) => Some(unsafe{ ::mem::transmute(v) }), realstd::option::None => None, @@ -48,12 +48,16 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } /// Give the global arguments to global storage. /// /// It is an error if the arguments already exist. -#[cfg(not(test))] pub fn put(args: Vec<~[u8]>) { imp::put(args) } -#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::mem::transmute(args) }) } +#[cfg(not(test))] pub fn put(args: Vec<Vec<u8>>) { imp::put(args) } +#[cfg(test)] pub fn put(args: Vec<Vec<u8>>) { + realargs::put(unsafe { + ::mem::transmute(args) + }) +} /// Make a clone of the global arguments. -#[cfg(not(test))] pub fn clone() -> Option<Vec<~[u8]>> { imp::clone() } -#[cfg(test)] pub fn clone() -> Option<Vec<~[u8]>> { +#[cfg(not(test))] pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() } +#[cfg(test)] pub fn clone() -> Option<Vec<Vec<u8>>> { match realargs::clone() { realstd::option::Some(v) => Some(unsafe { ::mem::transmute(v) }), realstd::option::None => None, @@ -88,15 +92,15 @@ mod imp { lock.destroy(); } - pub fn take() -> Option<Vec<~[u8]>> { + pub fn take() -> Option<Vec<Vec<u8>>> { with_lock(|| unsafe { let ptr = get_global_ptr(); let val = mem::replace(&mut *ptr, None); - val.as_ref().map(|s: &Box<Vec<~[u8]>>| (**s).clone()) + val.as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone()) }) } - pub fn put(args: Vec<~[u8]>) { + pub fn put(args: Vec<Vec<u8>>) { with_lock(|| unsafe { let ptr = get_global_ptr(); rtassert!((*ptr).is_none()); @@ -104,10 +108,10 @@ mod imp { }) } - pub fn clone() -> Option<Vec<~[u8]>> { + pub fn clone() -> Option<Vec<Vec<u8>>> { with_lock(|| unsafe { let ptr = get_global_ptr(); - (*ptr).as_ref().map(|s: &Box<Vec<~[u8]>>| (**s).clone()) + (*ptr).as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone()) }) } @@ -118,22 +122,21 @@ mod imp { } } - fn get_global_ptr() -> *mut Option<Box<Vec<~[u8]>>> { + fn get_global_ptr() -> *mut Option<Box<Vec<Vec<u8>>>> { unsafe { mem::transmute(&global_args_ptr) } } // Copied from `os`. #[cfg(not(test))] - unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> Vec<~[u8]> { + unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> Vec<Vec<u8>> { use c_str::CString; use ptr::RawPtr; use libc; - use slice::CloneableVector; use vec::Vec; Vec::from_fn(argc as uint, |i| { let cs = CString::new(*(argv as **libc::c_char).offset(i as int), false); - cs.as_bytes_no_nul().to_owned() + Vec::from_slice(cs.as_bytes_no_nul()) }) } @@ -148,7 +151,10 @@ mod imp { // Preserve the actual global state. let saved_value = take(); - let expected = vec![bytes!("happy").to_owned(), bytes!("today?").to_owned()]; + let expected = vec![ + Vec::from_slice(bytes!("happy")), + Vec::from_slice(bytes!("today?")), + ]; put(expected.clone()); assert!(clone() == Some(expected.clone())); @@ -179,15 +185,15 @@ mod imp { pub fn cleanup() { } - pub fn take() -> Option<Vec<~[u8]>> { + pub fn take() -> Option<Vec<Vec<u8>>> { fail!() } - pub fn put(_args: Vec<~[u8]>) { + pub fn put(_args: Vec<Vec<u8>>) { fail!() } - pub fn clone() -> Option<Vec<~[u8]>> { + pub fn clone() -> Option<Vec<Vec<u8>>> { fail!() } } diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 7aebb6e4796..1ab9ac1b11e 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -145,6 +145,7 @@ which at the time convulsed us with joy, yet which are now partly lost to my memory and partly incapable of presentation to others.", _ => "You've met with a terrible fate, haven't you?" }; + ::alloc::util::make_stdlib_link_work(); // see comments in liballoc rterrln!("{}", ""); rterrln!("{}", quote); rterrln!("{}", ""); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index f406cc9532f..4ba711c4611 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -85,7 +85,7 @@ use vec::Vec; pub use core::str::{from_utf8, CharEq, Chars, CharOffsets, RevChars}; pub use core::str::{RevCharOffsets, Bytes, RevBytes, CharSplits, RevCharSplits}; pub use core::str::{CharSplitsN, Words, AnyLines, MatchIndices, StrSplits}; -pub use core::str::{eq_slice, eq, is_utf8, is_utf16, UTF16Items}; +pub use core::str::{eq_slice, is_utf8, is_utf16, UTF16Items}; pub use core::str::{UTF16Item, ScalarValue, LoneSurrogate, utf16_items}; pub use core::str::{truncate_utf16_at_nul, utf8_char_width, CharRange}; pub use core::str::{Str, StrSlice}; @@ -660,6 +660,7 @@ pub mod raw { use c_str::CString; use libc; use mem; + use raw::Slice; use strbuf::StrBuf; use vec::Vec; @@ -668,7 +669,12 @@ pub mod raw { /// Create a Rust string from a *u8 buffer of the given length pub unsafe fn from_buf_len(buf: *u8, len: uint) -> StrBuf { - StrBuf::from_raw_parts(len, len, mem::transmute(buf)) + let mut result = StrBuf::new(); + result.push_bytes(mem::transmute(Slice { + data: buf, + len: len, + })); + result } /// Create a Rust string from a null-terminated C string @@ -920,13 +926,6 @@ mod tests { use strbuf::StrBuf; #[test] - fn test_eq() { - assert!((eq(&"".to_owned(), &"".to_owned()))); - assert!((eq(&"foo".to_owned(), &"foo".to_owned()))); - assert!((!eq(&"foo".to_owned(), &"bar".to_owned()))); - } - - #[test] fn test_eq_slice() { assert!((eq_slice("foobar".slice(0, 3), "foo"))); assert!((eq_slice("barfoo".slice(3, 6), "foo"))); @@ -984,10 +983,10 @@ mod tests { #[test] fn test_collect() { let empty = "".to_owned(); - let s: StrBuf = empty.chars().collect(); + let s: StrBuf = empty.as_slice().chars().collect(); assert_eq!(empty, s); let data = "ประเทศไทย中".to_owned(); - let s: StrBuf = data.chars().collect(); + let s: StrBuf = data.as_slice().chars().collect(); assert_eq!(data, s); } @@ -1009,23 +1008,24 @@ mod tests { assert_eq!(data.slice(2u, 6u).find_str("ab"), Some(3u - 2u)); assert!(data.slice(2u, 4u).find_str("ab").is_none()); - let mut data = "ประเทศไทย中华Việt Nam".to_owned(); - data = data + data; - assert!(data.find_str("ไท华").is_none()); - assert_eq!(data.slice(0u, 43u).find_str(""), Some(0u)); - assert_eq!(data.slice(6u, 43u).find_str(""), Some(6u - 6u)); + let string = "ประเทศไทย中华Việt Nam"; + let mut data = string.to_strbuf(); + data.push_str(string); + assert!(data.as_slice().find_str("ไท华").is_none()); + assert_eq!(data.as_slice().slice(0u, 43u).find_str(""), Some(0u)); + assert_eq!(data.as_slice().slice(6u, 43u).find_str(""), Some(6u - 6u)); - assert_eq!(data.slice(0u, 43u).find_str("ประ"), Some( 0u)); - assert_eq!(data.slice(0u, 43u).find_str("ทศไ"), Some(12u)); - assert_eq!(data.slice(0u, 43u).find_str("ย中"), Some(24u)); - assert_eq!(data.slice(0u, 43u).find_str("iệt"), Some(34u)); - assert_eq!(data.slice(0u, 43u).find_str("Nam"), Some(40u)); + assert_eq!(data.as_slice().slice(0u, 43u).find_str("ประ"), Some( 0u)); + assert_eq!(data.as_slice().slice(0u, 43u).find_str("ทศไ"), Some(12u)); + assert_eq!(data.as_slice().slice(0u, 43u).find_str("ย中"), Some(24u)); + assert_eq!(data.as_slice().slice(0u, 43u).find_str("iệt"), Some(34u)); + assert_eq!(data.as_slice().slice(0u, 43u).find_str("Nam"), Some(40u)); - assert_eq!(data.slice(43u, 86u).find_str("ประ"), Some(43u - 43u)); - assert_eq!(data.slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u)); - assert_eq!(data.slice(43u, 86u).find_str("ย中"), Some(67u - 43u)); - assert_eq!(data.slice(43u, 86u).find_str("iệt"), Some(77u - 43u)); - assert_eq!(data.slice(43u, 86u).find_str("Nam"), Some(83u - 43u)); + assert_eq!(data.as_slice().slice(43u, 86u).find_str("ประ"), Some(43u - 43u)); + assert_eq!(data.as_slice().slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u)); + assert_eq!(data.as_slice().slice(43u, 86u).find_str("ย中"), Some(67u - 43u)); + assert_eq!(data.as_slice().slice(43u, 86u).find_str("iệt"), Some(77u - 43u)); + assert_eq!(data.as_slice().slice(43u, 86u).find_str("Nam"), Some(83u - 43u)); } #[test] @@ -1122,7 +1122,9 @@ mod tests { } let letters = a_million_letter_a(); assert!(half_a_million_letter_a() == - unsafe {raw::slice_bytes(letters, 0u, 500000)}.to_owned()); + unsafe {raw::slice_bytes(letters.as_slice(), + 0u, + 500000)}.to_owned()); } #[test] @@ -1167,41 +1169,41 @@ mod tests { #[test] fn test_replace_2a() { - let data = "ประเทศไทย中华".to_owned(); - let repl = "دولة الكويت".to_owned(); + let data = "ประเทศไทย中华"; + let repl = "دولة الكويت"; - let a = "ประเ".to_owned(); - let a2 = "دولة الكويتทศไทย中华".to_owned(); - assert_eq!(data.replace(a, repl), a2); + let a = "ประเ"; + let a2 = "دولة الكويتทศไทย中华"; + assert_eq!(data.replace(a, repl).as_slice(), a2); } #[test] fn test_replace_2b() { - let data = "ประเทศไทย中华".to_owned(); - let repl = "دولة الكويت".to_owned(); + let data = "ประเทศไทย中华"; + let repl = "دولة الكويت"; - let b = "ะเ".to_owned(); - let b2 = "ปรدولة الكويتทศไทย中华".to_owned(); - assert_eq!(data.replace(b, repl), b2); + let b = "ะเ"; + let b2 = "ปรدولة الكويتทศไทย中华"; + assert_eq!(data.replace(b, repl).as_slice(), b2); } #[test] fn test_replace_2c() { - let data = "ประเทศไทย中华".to_owned(); - let repl = "دولة الكويت".to_owned(); + let data = "ประเทศไทย中华"; + let repl = "دولة الكويت"; - let c = "中华".to_owned(); - let c2 = "ประเทศไทยدولة الكويت".to_owned(); - assert_eq!(data.replace(c, repl), c2); + let c = "中华"; + let c2 = "ประเทศไทยدولة الكويت"; + assert_eq!(data.replace(c, repl).as_slice(), c2); } #[test] fn test_replace_2d() { - let data = "ประเทศไทย中华".to_owned(); - let repl = "دولة الكويت".to_owned(); + let data = "ประเทศไทย中华"; + let repl = "دولة الكويت"; - let d = "ไท华".to_owned(); - assert_eq!(data.replace(d, repl), data); + let d = "ไท华"; + assert_eq!(data.replace(d, repl).as_slice(), data); } #[test] @@ -1237,7 +1239,7 @@ mod tests { } let letters = a_million_letter_X(); assert!(half_a_million_letter_X() == - letters.slice(0u, 3u * 500000u).to_owned()); + letters.as_slice().slice(0u, 3u * 500000u).to_owned()); } #[test] @@ -1533,14 +1535,14 @@ mod tests { let s1: StrBuf = "All mimsy were the borogoves".to_strbuf(); let v: Vec<u8> = Vec::from_slice(s1.as_bytes()); - let s2: StrBuf = from_utf8(v).unwrap().to_strbuf(); + let s2: StrBuf = from_utf8(v.as_slice()).unwrap().to_strbuf(); let mut i: uint = 0u; let n1: uint = s1.len(); let n2: uint = v.len(); assert_eq!(n1, n2); while i < n1 { - let a: u8 = s1[i]; - let b: u8 = s2[i]; + let a: u8 = s1.as_slice()[i]; + let b: u8 = s2.as_slice()[i]; debug!("{}", a); debug!("{}", b); assert_eq!(a, b); @@ -1558,7 +1560,7 @@ mod tests { assert!(!"abcde".contains("def")); assert!(!"".contains("a")); - let data = "ประเทศไทย中华Việt Nam".to_owned(); + let data = "ประเทศไทย中华Việt Nam"; assert!(data.contains("ประเ")); assert!(data.contains("ะเ")); assert!(data.contains("中华")); @@ -1678,7 +1680,7 @@ mod tests { #[test] fn test_char_at() { - let s = "ศไทย中华Việt Nam".to_owned(); + let s = "ศไทย中华Việt Nam"; let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = 0; for ch in v.iter() { @@ -1689,7 +1691,7 @@ mod tests { #[test] fn test_char_at_reverse() { - let s = "ศไทย中华Việt Nam".to_owned(); + let s = "ศไทย中华Việt Nam"; let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = s.len(); for ch in v.iter().rev() { @@ -1734,7 +1736,7 @@ mod tests { #[test] fn test_char_range_at() { - let data = "b¢€𤭢𤭢€¢b".to_owned(); + let data = "b¢€𤭢𤭢€¢b"; assert_eq!('b', data.char_range_at(0).ch); assert_eq!('¢', data.char_range_at(1).ch); assert_eq!('€', data.char_range_at(3).ch); @@ -1751,28 +1753,9 @@ mod tests { } #[test] - fn test_add() { - #![allow(unnecessary_allocation)] - macro_rules! t ( - ($s1:expr, $s2:expr, $e:expr) => { { - let s1 = $s1; - let s2 = $s2; - let e = $e; - assert_eq!(s1 + s2, e.to_owned()); - assert_eq!(s1.to_owned() + s2, e.to_owned()); - } } - ); - - t!("foo", "bar", "foobar"); - t!("foo", "bar".to_owned(), "foobar"); - t!("ศไทย中", "华Việt Nam", "ศไทย中华Việt Nam"); - t!("ศไทย中", "华Việt Nam".to_owned(), "ศไทย中华Việt Nam"); - } - - #[test] fn test_iterator() { use iter::*; - let s = "ศไทย中华Việt Nam".to_owned(); + let s = "ศไทย中华Việt Nam"; let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = 0; @@ -1788,7 +1771,7 @@ mod tests { #[test] fn test_rev_iterator() { use iter::*; - let s = "ศไทย中华Việt Nam".to_owned(); + let s = "ศไทย中华Việt Nam"; let v = box ['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ']; let mut pos = 0; @@ -1811,7 +1794,7 @@ mod tests { #[test] fn test_bytesator() { - let s = "ศไทย中华Việt Nam".to_owned(); + 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, @@ -1827,7 +1810,7 @@ mod tests { #[test] fn test_bytes_revator() { - let s = "ศไทย中华Việt Nam".to_owned(); + 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, @@ -2081,14 +2064,15 @@ mod tests { #[test] fn test_str_from_utf8_owned() { - let xs = bytes!("hello").to_owned(); + let xs = Vec::from_slice(bytes!("hello")); assert_eq!(from_utf8_owned(xs), Ok("hello".to_owned())); - let xs = bytes!("ศไทย中华Việt Nam").to_owned(); + let xs = Vec::from_slice(bytes!("ศไทย中华Việt Nam")); assert_eq!(from_utf8_owned(xs), Ok("ศไทย中华Việt Nam".to_owned())); - let xs = bytes!("hello", 0xff).to_owned(); - assert_eq!(from_utf8_owned(xs), Err(bytes!("hello", 0xff).to_owned())); + let xs = Vec::from_slice(bytes!("hello", 0xff)); + assert_eq!(from_utf8_owned(xs), + Err(Vec::from_slice(bytes!("hello", 0xff)))); } #[test] diff --git a/src/libstd/strbuf.rs b/src/libstd/strbuf.rs index 8f5d8340526..dd462ff5ab5 100644 --- a/src/libstd/strbuf.rs +++ b/src/libstd/strbuf.rs @@ -14,6 +14,7 @@ use c_vec::CVec; use char::Char; use cmp::Equiv; use container::{Container, Mutable}; +use default::Default; use fmt; use from_str::FromStr; use io::Writer; @@ -331,6 +332,12 @@ impl StrAllocating for StrBuf { } } +impl Default for StrBuf { + fn default() -> StrBuf { + StrBuf::new() + } +} + impl fmt::Show for StrBuf { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.as_slice().fmt(f) diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index f73ebc2255b..8e85283ee55 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -119,7 +119,9 @@ impl DynamicLibrary { let mut ret = Vec::new(); match os::getenv_as_bytes(DynamicLibrary::envvar()) { Some(env) => { - for portion in env.split(|a| *a == DynamicLibrary::separator()) { + for portion in + env.as_slice() + .split(|a| *a == DynamicLibrary::separator()) { ret.push(Path::new(portion)); } } @@ -274,6 +276,7 @@ pub mod dl { use os; use ptr; use result::{Ok, Err, Result}; + use strbuf::StrBuf; use str; use c_str::ToCStr; |
