libcore: Remove all uses of ~str
from libcore
.
[breaking-change]
This commit is contained in:
parent
5633d4641f
commit
e878721d70
110 changed files with 868 additions and 792 deletions
|
@ -323,11 +323,15 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
|
|||
let mut valid = false;
|
||||
|
||||
for ext in valid_extensions.iter() {
|
||||
if name.ends_with(*ext) { valid = true; }
|
||||
if name.ends_with(ext.as_slice()) {
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
for pre in invalid_prefixes.iter() {
|
||||
if name.starts_with(*pre) { valid = false; }
|
||||
if name.starts_with(pre.as_slice()) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
|
|
|
@ -24,7 +24,7 @@ pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
|
|||
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
|
||||
|
||||
rdr.lines().enumerate().filter_map(|(line_no, ln)| {
|
||||
parse_expected(line_no + 1, ln.unwrap(), re)
|
||||
parse_expected(line_no + 1, ln.unwrap().as_slice(), re)
|
||||
}).collect()
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ use std::unstable::dynamic_lib::DynamicLibrary;
|
|||
|
||||
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf, StrBuf)> {
|
||||
let prog = if cfg!(windows) {prog.slice_to(prog.len() - 4)} else {prog};
|
||||
let aux_path = prog + ".libaux";
|
||||
let mut aux_path = prog.to_strbuf();
|
||||
aux_path.push_str(".libaux");
|
||||
|
||||
// Need to be sure to put both the lib_path and the aux path in the dylib
|
||||
// search path for the child.
|
||||
|
|
|
@ -351,7 +351,10 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||
cmds,
|
||||
"quit".to_strbuf()].connect("\n");
|
||||
debug!("script_str = {}", script_str);
|
||||
dump_output_file(config, testfile, script_str, "debugger.script");
|
||||
dump_output_file(config,
|
||||
testfile,
|
||||
script_str.as_slice(),
|
||||
"debugger.script");
|
||||
|
||||
|
||||
procsrv::run("",
|
||||
|
@ -459,7 +462,10 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
|
|||
"quit\n".to_strbuf()
|
||||
].connect("\n");
|
||||
debug!("script_str = {}", script_str);
|
||||
dump_output_file(config, testfile, script_str, "debugger.script");
|
||||
dump_output_file(config,
|
||||
testfile,
|
||||
script_str.as_slice(),
|
||||
"debugger.script");
|
||||
|
||||
// run debugger script with gdb
|
||||
#[cfg(windows)]
|
||||
|
@ -553,7 +559,10 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
|
|||
|
||||
// Write the script into a file
|
||||
debug!("script_str = {}", script_str);
|
||||
dump_output_file(config, testfile, script_str.into_owned(), "debugger.script");
|
||||
dump_output_file(config,
|
||||
testfile,
|
||||
script_str.as_slice(),
|
||||
"debugger.script");
|
||||
let debugger_script = make_out_name(config, testfile, "debugger.script");
|
||||
|
||||
// Let LLDB execute the script via lldb_batchmode.py
|
||||
|
@ -610,8 +619,8 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
|
|||
-> DebuggerCommands {
|
||||
use std::io::{BufferedReader, File};
|
||||
|
||||
let command_directive = debugger_prefix + "-command";
|
||||
let check_directive = debugger_prefix + "-check";
|
||||
let command_directive = format!("{}-command", debugger_prefix);
|
||||
let check_directive = format!("{}-check", debugger_prefix);
|
||||
|
||||
let mut breakpoint_lines = vec!();
|
||||
let mut commands = vec!();
|
||||
|
|
|
@ -60,8 +60,8 @@ To return an Owned String (StrBuf) use the str helper function [`from_utf8_owned
|
|||
~~~
|
||||
use std::str;
|
||||
|
||||
let x: Result<StrBuf,~[u8]> =
|
||||
str::from_utf8_owned(~[104u8,105u8]).map(|x| x.to_strbuf());
|
||||
let x: Option<StrBuf> =
|
||||
str::from_utf8([ 104u8, 105u8 ]).map(|x| x.to_strbuf());
|
||||
let y: StrBuf = x.unwrap();
|
||||
~~~
|
||||
|
||||
|
|
|
@ -116,18 +116,18 @@ pub fn stats_print() {
|
|||
}
|
||||
}
|
||||
|
||||
// The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size
|
||||
// allocations can point to this `static`. It would be incorrect to use a null
|
||||
// pointer, due to enums assuming types like unique pointers are never null.
|
||||
pub static mut EMPTY: uint = 12345;
|
||||
|
||||
/// The allocator for unique pointers.
|
||||
#[cfg(not(test))]
|
||||
#[lang="exchange_malloc"]
|
||||
#[inline]
|
||||
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
|
||||
// The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size
|
||||
// allocations can point to this `static`. It would be incorrect to use a null
|
||||
// pointer, due to enums assuming types like unique pointers are never null.
|
||||
static EMPTY: () = ();
|
||||
|
||||
if size == 0 {
|
||||
&EMPTY as *() as *mut u8
|
||||
&EMPTY as *uint as *mut u8
|
||||
} else {
|
||||
allocate(size, align)
|
||||
}
|
||||
|
|
|
@ -28,3 +28,20 @@ fn align_to(size: uint, align: uint) -> uint {
|
|||
assert!(align != 0);
|
||||
(size + align - 1) & !(align - 1)
|
||||
}
|
||||
|
||||
// FIXME(#14344): When linking liballoc with libstd, this library will be linked
|
||||
// as an rlib (it only exists as an rlib). It turns out that an
|
||||
// optimized standard library doesn't actually use *any* symbols
|
||||
// from this library. Everything is inlined and optimized away.
|
||||
// This means that linkers will actually omit the object for this
|
||||
// file, even though it may be needed in the future.
|
||||
//
|
||||
// To get around this for now, we define a dummy symbol which
|
||||
// will never get inlined so the stdlib can call it. The stdlib's
|
||||
// reference to this symbol will cause this library's object file
|
||||
// to get linked in to libstd successfully (the linker won't
|
||||
// optimize it out).
|
||||
#[deprecated]
|
||||
#[doc(hidden)]
|
||||
pub fn make_stdlib_link_work() {}
|
||||
|
||||
|
|
|
@ -1330,7 +1330,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_from_bytes() {
|
||||
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
|
||||
let str = "10110110".to_owned() + "00000000" + "11111111";
|
||||
let str = format!("{}{}{}", "10110110", "00000000", "11111111");
|
||||
assert_eq!(bitv.to_str(), str);
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ mod tests {
|
|||
use prelude::*;
|
||||
use super::*;
|
||||
use realstd::owned::{Box, AnyOwnExt};
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::str::{Str, StrAllocating};
|
||||
|
||||
#[deriving(Eq, Show)]
|
||||
struct Test;
|
||||
|
@ -249,13 +249,17 @@ mod tests {
|
|||
use realstd::to_str::ToStr;
|
||||
let a = box 8u as Box<::realstd::any::Any>;
|
||||
let b = box Test as Box<::realstd::any::Any>;
|
||||
assert_eq!(a.to_str(), "Box<Any>".to_owned());
|
||||
assert_eq!(b.to_str(), "Box<Any>".to_owned());
|
||||
let a_str = a.to_str();
|
||||
let b_str = b.to_str();
|
||||
assert_eq!(a_str.as_slice(), "Box<Any>");
|
||||
assert_eq!(b_str.as_slice(), "Box<Any>");
|
||||
|
||||
let a = &8u as &Any;
|
||||
let b = &Test as &Any;
|
||||
assert_eq!(format!("{}", a), "&Any".to_owned());
|
||||
assert_eq!(format!("{}", b), "&Any".to_owned());
|
||||
let s = format!("{}", a);
|
||||
assert_eq!(s.as_slice(), "&Any");
|
||||
let s = format!("{}", b);
|
||||
assert_eq!(s.as_slice(), "&Any");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -242,8 +242,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
assert_eq!(false.to_str(), "false".to_owned());
|
||||
assert_eq!(true.to_str(), "true".to_owned());
|
||||
let s = false.to_str();
|
||||
assert_eq!(s.as_slice(), "false");
|
||||
let s = true.to_str();
|
||||
assert_eq!(s.as_slice(), "true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -404,12 +404,13 @@ mod test {
|
|||
#[test]
|
||||
fn cell_has_sensible_show() {
|
||||
use str::StrSlice;
|
||||
use realstd::str::Str;
|
||||
|
||||
let x = Cell::new("foo bar");
|
||||
assert!(format!("{}", x).contains(x.get()));
|
||||
assert!(format!("{}", x).as_slice().contains(x.get()));
|
||||
|
||||
x.set("baz qux");
|
||||
assert!(format!("{}", x).contains(x.get()));
|
||||
assert!(format!("{}", x).as_slice().contains(x.get()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -637,7 +637,7 @@ mod test {
|
|||
use slice::ImmutableVector;
|
||||
use option::{Some, None};
|
||||
use realstd::strbuf::StrBuf;
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::str::{Str, StrAllocating};
|
||||
|
||||
#[test]
|
||||
fn test_is_lowercase() {
|
||||
|
@ -742,46 +742,65 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_escape_default() {
|
||||
fn string(c: char) -> ~str {
|
||||
fn string(c: char) -> StrBuf {
|
||||
let mut result = StrBuf::new();
|
||||
escape_default(c, |c| { result.push_char(c); });
|
||||
return result.into_owned();
|
||||
return result;
|
||||
}
|
||||
assert_eq!(string('\n'), "\\n".to_owned());
|
||||
assert_eq!(string('\r'), "\\r".to_owned());
|
||||
assert_eq!(string('\''), "\\'".to_owned());
|
||||
assert_eq!(string('"'), "\\\"".to_owned());
|
||||
assert_eq!(string(' '), " ".to_owned());
|
||||
assert_eq!(string('a'), "a".to_owned());
|
||||
assert_eq!(string('~'), "~".to_owned());
|
||||
assert_eq!(string('\x00'), "\\x00".to_owned());
|
||||
assert_eq!(string('\x1f'), "\\x1f".to_owned());
|
||||
assert_eq!(string('\x7f'), "\\x7f".to_owned());
|
||||
assert_eq!(string('\xff'), "\\xff".to_owned());
|
||||
assert_eq!(string('\u011b'), "\\u011b".to_owned());
|
||||
assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
|
||||
let s = string('\n');
|
||||
assert_eq!(s.as_slice(), "\\n");
|
||||
let s = string('\r');
|
||||
assert_eq!(s.as_slice(), "\\r");
|
||||
let s = string('\'');
|
||||
assert_eq!(s.as_slice(), "\\'");
|
||||
let s = string('"');
|
||||
assert_eq!(s.as_slice(), "\\\"");
|
||||
let s = string(' ');
|
||||
assert_eq!(s.as_slice(), " ");
|
||||
let s = string('a');
|
||||
assert_eq!(s.as_slice(), "a");
|
||||
let s = string('~');
|
||||
assert_eq!(s.as_slice(), "~");
|
||||
let s = string('\x00');
|
||||
assert_eq!(s.as_slice(), "\\x00");
|
||||
let s = string('\x1f');
|
||||
assert_eq!(s.as_slice(), "\\x1f");
|
||||
let s = string('\x7f');
|
||||
assert_eq!(s.as_slice(), "\\x7f");
|
||||
let s = string('\xff');
|
||||
assert_eq!(s.as_slice(), "\\xff");
|
||||
let s = string('\u011b');
|
||||
assert_eq!(s.as_slice(), "\\u011b");
|
||||
let s = string('\U0001d4b6');
|
||||
assert_eq!(s.as_slice(), "\\U0001d4b6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_unicode() {
|
||||
fn string(c: char) -> ~str {
|
||||
fn string(c: char) -> StrBuf {
|
||||
let mut result = StrBuf::new();
|
||||
escape_unicode(c, |c| { result.push_char(c); });
|
||||
return result.into_owned();
|
||||
return result;
|
||||
}
|
||||
assert_eq!(string('\x00'), "\\x00".to_owned());
|
||||
assert_eq!(string('\n'), "\\x0a".to_owned());
|
||||
assert_eq!(string(' '), "\\x20".to_owned());
|
||||
assert_eq!(string('a'), "\\x61".to_owned());
|
||||
assert_eq!(string('\u011b'), "\\u011b".to_owned());
|
||||
assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
|
||||
let s = string('\x00');
|
||||
assert_eq!(s.as_slice(), "\\x00");
|
||||
let s = string('\n');
|
||||
assert_eq!(s.as_slice(), "\\x0a");
|
||||
let s = string(' ');
|
||||
assert_eq!(s.as_slice(), "\\x20");
|
||||
let s = string('a');
|
||||
assert_eq!(s.as_slice(), "\\x61");
|
||||
let s = string('\u011b');
|
||||
assert_eq!(s.as_slice(), "\\u011b");
|
||||
let s = string('\U0001d4b6');
|
||||
assert_eq!(s.as_slice(), "\\U0001d4b6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
use realstd::to_str::ToStr;
|
||||
let s = 't'.to_str();
|
||||
assert_eq!(s, "t".to_owned());
|
||||
assert_eq!(s.as_slice(), "t");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -171,7 +171,7 @@ pub trait Ord: Eq {
|
|||
/// The equivalence relation. Two values may be equivalent even if they are
|
||||
/// of different types. The most common use case for this relation is
|
||||
/// container types; e.g. it is often desirable to be able to use `&str`
|
||||
/// values to look up entries in a container with `~str` keys.
|
||||
/// values to look up entries in a container with `StrBuf` keys.
|
||||
pub trait Equiv<T> {
|
||||
/// Implement this function to decide equivalent values.
|
||||
fn equiv(&self, other: &T) -> bool;
|
||||
|
|
|
@ -594,7 +594,7 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn format(args: &Arguments) -> ~str {
|
||||
pub fn format(args: &Arguments) -> ::realstd::strbuf::StrBuf {
|
||||
use str;
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::io::MemWriter;
|
||||
|
@ -613,7 +613,10 @@ pub fn format(args: &Arguments) -> ~str {
|
|||
|
||||
let mut i = MemWriter::new();
|
||||
let _ = write(&mut i, args);
|
||||
str::from_utf8(i.get_ref()).unwrap().to_owned()
|
||||
|
||||
let mut result = ::realstd::strbuf::StrBuf::new();
|
||||
result.push_str(str::from_utf8(i.get_ref()).unwrap());
|
||||
result
|
||||
}
|
||||
|
||||
/// When the compiler determines that the type of an argument *must* be a string
|
||||
|
@ -761,7 +764,6 @@ macro_rules! delegate(($ty:ty to $other:ident) => {
|
|||
}
|
||||
}
|
||||
})
|
||||
delegate!(~str to string)
|
||||
delegate!(&'a str to string)
|
||||
delegate!(bool to bool)
|
||||
delegate!(char to char)
|
||||
|
|
|
@ -194,7 +194,7 @@ mod tests {
|
|||
use fmt::radix;
|
||||
use super::{Binary, Octal, Decimal, LowerHex, UpperHex};
|
||||
use super::{GenericRadix, Radix};
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::str::{Str, StrAllocating};
|
||||
|
||||
#[test]
|
||||
fn test_radix_base() {
|
||||
|
@ -246,143 +246,143 @@ mod tests {
|
|||
// Formatting integers should select the right implementation based off
|
||||
// the type of the argument. Also, hex/octal/binary should be defined
|
||||
// for integers, but they shouldn't emit the negative sign.
|
||||
assert_eq!(format!("{}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i8), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i16), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i32), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i64), "-1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i64), "1".to_owned());
|
||||
assert!(format!("{}", 1i).as_slice() == "1");
|
||||
assert!(format!("{}", 1i8).as_slice() == "1");
|
||||
assert!(format!("{}", 1i16).as_slice() == "1");
|
||||
assert!(format!("{}", 1i32).as_slice() == "1");
|
||||
assert!(format!("{}", 1i64).as_slice() == "1");
|
||||
assert!(format!("{:d}", -1i).as_slice() == "-1");
|
||||
assert!(format!("{:d}", -1i8).as_slice() == "-1");
|
||||
assert!(format!("{:d}", -1i16).as_slice() == "-1");
|
||||
assert!(format!("{:d}", -1i32).as_slice() == "-1");
|
||||
assert!(format!("{:d}", -1i64).as_slice() == "-1");
|
||||
assert!(format!("{:t}", 1i).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1i8).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1i16).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1i32).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1i64).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1i).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1i8).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1i16).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1i32).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1i64).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1i).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1i8).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1i16).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1i32).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1i64).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1i).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1i8).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1i16).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1i32).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1i64).as_slice() == "1");
|
||||
|
||||
assert_eq!(format!("{}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u64), "1".to_owned());
|
||||
assert!(format!("{}", 1u).as_slice() == "1");
|
||||
assert!(format!("{}", 1u8).as_slice() == "1");
|
||||
assert!(format!("{}", 1u16).as_slice() == "1");
|
||||
assert!(format!("{}", 1u32).as_slice() == "1");
|
||||
assert!(format!("{}", 1u64).as_slice() == "1");
|
||||
assert!(format!("{:u}", 1u).as_slice() == "1");
|
||||
assert!(format!("{:u}", 1u8).as_slice() == "1");
|
||||
assert!(format!("{:u}", 1u16).as_slice() == "1");
|
||||
assert!(format!("{:u}", 1u32).as_slice() == "1");
|
||||
assert!(format!("{:u}", 1u64).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1u).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1u8).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1u16).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1u32).as_slice() == "1");
|
||||
assert!(format!("{:t}", 1u64).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1u).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1u8).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1u16).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1u32).as_slice() == "1");
|
||||
assert!(format!("{:x}", 1u64).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1u).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1u8).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1u16).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1u32).as_slice() == "1");
|
||||
assert!(format!("{:X}", 1u64).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1u).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1u8).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1u16).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1u32).as_slice() == "1");
|
||||
assert!(format!("{:o}", 1u64).as_slice() == "1");
|
||||
|
||||
// Test a larger number
|
||||
assert_eq!(format!("{:t}", 55), "110111".to_owned());
|
||||
assert_eq!(format!("{:o}", 55), "67".to_owned());
|
||||
assert_eq!(format!("{:d}", 55), "55".to_owned());
|
||||
assert_eq!(format!("{:x}", 55), "37".to_owned());
|
||||
assert_eq!(format!("{:X}", 55), "37".to_owned());
|
||||
assert!(format!("{:t}", 55).as_slice() == "110111");
|
||||
assert!(format!("{:o}", 55).as_slice() == "67");
|
||||
assert!(format!("{:d}", 55).as_slice() == "55");
|
||||
assert!(format!("{:x}", 55).as_slice() == "37");
|
||||
assert!(format!("{:X}", 55).as_slice() == "37");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_zero() {
|
||||
assert_eq!(format!("{}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:d}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:t}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:o}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:x}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:X}", 0i), "0".to_owned());
|
||||
assert!(format!("{}", 0i).as_slice() == "0");
|
||||
assert!(format!("{:d}", 0i).as_slice() == "0");
|
||||
assert!(format!("{:t}", 0i).as_slice() == "0");
|
||||
assert!(format!("{:o}", 0i).as_slice() == "0");
|
||||
assert!(format!("{:x}", 0i).as_slice() == "0");
|
||||
assert!(format!("{:X}", 0i).as_slice() == "0");
|
||||
|
||||
assert_eq!(format!("{}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:u}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:t}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:o}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:x}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:X}", 0u), "0".to_owned());
|
||||
assert!(format!("{}", 0u).as_slice() == "0");
|
||||
assert!(format!("{:u}", 0u).as_slice() == "0");
|
||||
assert!(format!("{:t}", 0u).as_slice() == "0");
|
||||
assert!(format!("{:o}", 0u).as_slice() == "0");
|
||||
assert!(format!("{:x}", 0u).as_slice() == "0");
|
||||
assert!(format!("{:X}", 0u).as_slice() == "0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_flags() {
|
||||
assert_eq!(format!("{:3d}", 1), " 1".to_owned());
|
||||
assert_eq!(format!("{:>3d}", 1), " 1".to_owned());
|
||||
assert_eq!(format!("{:>+3d}", 1), " +1".to_owned());
|
||||
assert_eq!(format!("{:<3d}", 1), "1 ".to_owned());
|
||||
assert_eq!(format!("{:#d}", 1), "1".to_owned());
|
||||
assert_eq!(format!("{:#x}", 10), "0xa".to_owned());
|
||||
assert_eq!(format!("{:#X}", 10), "0xA".to_owned());
|
||||
assert_eq!(format!("{:#5x}", 10), " 0xa".to_owned());
|
||||
assert_eq!(format!("{:#o}", 10), "0o12".to_owned());
|
||||
assert_eq!(format!("{:08x}", 10), "0000000a".to_owned());
|
||||
assert_eq!(format!("{:8x}", 10), " a".to_owned());
|
||||
assert_eq!(format!("{:<8x}", 10), "a ".to_owned());
|
||||
assert_eq!(format!("{:>8x}", 10), " a".to_owned());
|
||||
assert_eq!(format!("{:#08x}", 10), "0x00000a".to_owned());
|
||||
assert_eq!(format!("{:08d}", -10), "-0000010".to_owned());
|
||||
assert_eq!(format!("{:x}", -1u8), "ff".to_owned());
|
||||
assert_eq!(format!("{:X}", -1u8), "FF".to_owned());
|
||||
assert_eq!(format!("{:t}", -1u8), "11111111".to_owned());
|
||||
assert_eq!(format!("{:o}", -1u8), "377".to_owned());
|
||||
assert_eq!(format!("{:#x}", -1u8), "0xff".to_owned());
|
||||
assert_eq!(format!("{:#X}", -1u8), "0xFF".to_owned());
|
||||
assert_eq!(format!("{:#t}", -1u8), "0b11111111".to_owned());
|
||||
assert_eq!(format!("{:#o}", -1u8), "0o377".to_owned());
|
||||
assert!(format!("{:3d}", 1).as_slice() == " 1");
|
||||
assert!(format!("{:>3d}", 1).as_slice() == " 1");
|
||||
assert!(format!("{:>+3d}", 1).as_slice() == " +1");
|
||||
assert!(format!("{:<3d}", 1).as_slice() == "1 ");
|
||||
assert!(format!("{:#d}", 1).as_slice() == "1");
|
||||
assert!(format!("{:#x}", 10).as_slice() == "0xa");
|
||||
assert!(format!("{:#X}", 10).as_slice() == "0xA");
|
||||
assert!(format!("{:#5x}", 10).as_slice() == " 0xa");
|
||||
assert!(format!("{:#o}", 10).as_slice() == "0o12");
|
||||
assert!(format!("{:08x}", 10).as_slice() == "0000000a");
|
||||
assert!(format!("{:8x}", 10).as_slice() == " a");
|
||||
assert!(format!("{:<8x}", 10).as_slice() == "a ");
|
||||
assert!(format!("{:>8x}", 10).as_slice() == " a");
|
||||
assert!(format!("{:#08x}", 10).as_slice() == "0x00000a");
|
||||
assert!(format!("{:08d}", -10).as_slice() == "-0000010");
|
||||
assert!(format!("{:x}", -1u8).as_slice() == "ff");
|
||||
assert!(format!("{:X}", -1u8).as_slice() == "FF");
|
||||
assert!(format!("{:t}", -1u8).as_slice() == "11111111");
|
||||
assert!(format!("{:o}", -1u8).as_slice() == "377");
|
||||
assert!(format!("{:#x}", -1u8).as_slice() == "0xff");
|
||||
assert!(format!("{:#X}", -1u8).as_slice() == "0xFF");
|
||||
assert!(format!("{:#t}", -1u8).as_slice() == "0b11111111");
|
||||
assert!(format!("{:#o}", -1u8).as_slice() == "0o377");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_sign_padding() {
|
||||
assert_eq!(format!("{:+5d}", 1), " +1".to_owned());
|
||||
assert_eq!(format!("{:+5d}", -1), " -1".to_owned());
|
||||
assert_eq!(format!("{:05d}", 1), "00001".to_owned());
|
||||
assert_eq!(format!("{:05d}", -1), "-0001".to_owned());
|
||||
assert_eq!(format!("{:+05d}", 1), "+0001".to_owned());
|
||||
assert_eq!(format!("{:+05d}", -1), "-0001".to_owned());
|
||||
assert!(format!("{:+5d}", 1).as_slice() == " +1");
|
||||
assert!(format!("{:+5d}", -1).as_slice() == " -1");
|
||||
assert!(format!("{:05d}", 1).as_slice() == "00001");
|
||||
assert!(format!("{:05d}", -1).as_slice() == "-0001");
|
||||
assert!(format!("{:+05d}", 1).as_slice() == "+0001");
|
||||
assert!(format!("{:+05d}", -1).as_slice() == "-0001");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_twos_complement() {
|
||||
use {i8, i16, i32, i64};
|
||||
assert_eq!(format!("{}", i8::MIN), "-128".to_owned());
|
||||
assert_eq!(format!("{}", i16::MIN), "-32768".to_owned());
|
||||
assert_eq!(format!("{}", i32::MIN), "-2147483648".to_owned());
|
||||
assert_eq!(format!("{}", i64::MIN), "-9223372036854775808".to_owned());
|
||||
assert!(format!("{}", i8::MIN).as_slice() == "-128");
|
||||
assert!(format!("{}", i16::MIN).as_slice() == "-32768");
|
||||
assert!(format!("{}", i32::MIN).as_slice() == "-2147483648");
|
||||
assert!(format!("{}", i64::MIN).as_slice() == "-9223372036854775808");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_radix() {
|
||||
assert_eq!(format!("{:04}", radix(3, 2)), "0011".to_owned());
|
||||
assert_eq!(format!("{}", radix(55, 36)), "1j".to_owned());
|
||||
assert!(format!("{:04}", radix(3, 2)).as_slice() == "0011");
|
||||
assert!(format!("{}", radix(55, 36)).as_slice() == "1j");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -469,6 +469,7 @@ mod tests {
|
|||
use option::{Some,None};
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::owned::Box;
|
||||
use realstd::vec::Vec;
|
||||
use raw;
|
||||
|
||||
#[test]
|
||||
|
@ -568,7 +569,7 @@ mod tests {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
assert_eq!(box [76u8], transmute("L".to_owned()));
|
||||
assert!(Vec::from_slice([76u8]) == transmute("L".to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,14 +188,14 @@ impl<T> Option<T> {
|
|||
///
|
||||
/// # Example
|
||||
///
|
||||
/// Convert an `Option<~str>` into an `Option<int>`, preserving the original.
|
||||
/// Convert an `Option<StrBuf>` into an `Option<int>`, preserving the original.
|
||||
/// The `map` method takes the `self` argument by value, consuming the original,
|
||||
/// so this technique uses `as_ref` to first take an `Option` to a reference
|
||||
/// to the value inside the original.
|
||||
///
|
||||
/// ```
|
||||
/// let num_as_str: Option<~str> = Some("10".to_owned());
|
||||
/// // First, cast `Option<~str>` to `Option<&~str>` with `as_ref`,
|
||||
/// let num_as_str: Option<StrBuf> = Some("10".to_strbuf());
|
||||
/// // First, cast `Option<StrBuf>` to `Option<&StrBuf>` with `as_ref`,
|
||||
/// // then consume *that* with `map`, leaving `num_as_str` on the stack.
|
||||
/// let num_as_int: Option<uint> = num_as_str.as_ref().map(|n| n.len());
|
||||
/// println!("still can print num_as_str: {}", num_as_str);
|
||||
|
@ -278,10 +278,10 @@ impl<T> Option<T> {
|
|||
///
|
||||
/// # Example
|
||||
///
|
||||
/// Convert an `Option<~str>` into an `Option<uint>`, consuming the original:
|
||||
/// Convert an `Option<StrBuf>` into an `Option<uint>`, consuming the original:
|
||||
///
|
||||
/// ```
|
||||
/// let num_as_str: Option<~str> = Some("10".to_owned());
|
||||
/// let num_as_str: Option<StrBuf> = Some("10".to_strbuf());
|
||||
/// // `Option::map` takes self *by value*, consuming `num_as_str`
|
||||
/// let num_as_int: Option<uint> = num_as_str.map(|n| n.len());
|
||||
/// ```
|
||||
|
@ -596,9 +596,10 @@ pub fn collect<T, Iter: Iterator<Option<T>>, V: FromIterator<T>>(iter: Iter) ->
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use realstd::vec::Vec;
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::strbuf::StrBuf;
|
||||
use option::collect;
|
||||
use prelude::*;
|
||||
use realstd::str::{Str, StrAllocating};
|
||||
use iter::range;
|
||||
|
||||
use str::StrSlice;
|
||||
|
@ -619,11 +620,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_str() {
|
||||
let x = "test".to_owned();
|
||||
let addr_x = x.as_ptr();
|
||||
let x = "test".to_strbuf();
|
||||
let addr_x = x.as_slice().as_ptr();
|
||||
let opt = Some(x);
|
||||
let y = opt.unwrap();
|
||||
let addr_y = y.as_ptr();
|
||||
let addr_y = y.as_slice().as_ptr();
|
||||
assert_eq!(addr_x, addr_y);
|
||||
}
|
||||
|
||||
|
@ -745,7 +746,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_unwrap() {
|
||||
assert_eq!(Some(1).unwrap(), 1);
|
||||
assert_eq!(Some("hello".to_owned()).unwrap(), "hello".to_owned());
|
||||
let s = Some("hello".to_strbuf()).unwrap();
|
||||
assert_eq!(s.as_slice(), "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -758,7 +760,7 @@ mod tests {
|
|||
#[test]
|
||||
#[should_fail]
|
||||
fn test_unwrap_fail2() {
|
||||
let x: Option<~str> = None;
|
||||
let x: Option<StrBuf> = None;
|
||||
x.unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -486,6 +486,7 @@ pub mod ptr_tests {
|
|||
use mem;
|
||||
use libc;
|
||||
use realstd::str;
|
||||
use realstd::str::Str;
|
||||
use slice::{ImmutableVector, MutableVector};
|
||||
|
||||
#[test]
|
||||
|
@ -660,7 +661,7 @@ pub mod ptr_tests {
|
|||
let expected = expected_arr[ctr].with_ref(|buf| {
|
||||
str::raw::from_c_str(buf)
|
||||
});
|
||||
assert_eq!(actual, expected);
|
||||
assert_eq!(actual.as_slice(), expected.as_slice());
|
||||
ctr += 1;
|
||||
iteration_count += 1;
|
||||
});
|
||||
|
@ -693,7 +694,7 @@ pub mod ptr_tests {
|
|||
let expected = expected_arr[ctr].with_ref(|buf| {
|
||||
str::raw::from_c_str(buf)
|
||||
});
|
||||
assert_eq!(actual, expected);
|
||||
assert_eq!(actual.as_slice(), expected.as_slice());
|
||||
ctr += 1;
|
||||
iteration_count += 1;
|
||||
});
|
||||
|
|
|
@ -81,7 +81,6 @@ impl<'a, T> Repr<Slice<T>> for &'a [T] {}
|
|||
impl<'a> Repr<Slice<u8>> for &'a str {}
|
||||
impl<T> Repr<*Box<T>> for @T {}
|
||||
impl<T> Repr<*Vec<T>> for ~[T] {}
|
||||
impl Repr<*String> for ~str {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -169,20 +169,24 @@
|
|||
//! ~~~
|
||||
//! use std::io::{File, Open, Write, IoError};
|
||||
//!
|
||||
//! struct Info { name: ~str, age: int, rating: int }
|
||||
//! struct Info {
|
||||
//! name: StrBuf,
|
||||
//! age: int,
|
||||
//! rating: int
|
||||
//! }
|
||||
//!
|
||||
//! fn write_info(info: &Info) -> Result<(), IoError> {
|
||||
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
|
||||
//! // Early return on error
|
||||
//! match file.write_line(format!("name: {}", info.name)) {
|
||||
//! match file.write_line(format!("name: {}", info.name).as_slice()) {
|
||||
//! Ok(_) => (),
|
||||
//! Err(e) => return Err(e)
|
||||
//! }
|
||||
//! match file.write_line(format!("age: {}", info.age)) {
|
||||
//! match file.write_line(format!("age: {}", info.age).as_slice()) {
|
||||
//! Ok(_) => (),
|
||||
//! Err(e) => return Err(e)
|
||||
//! }
|
||||
//! return file.write_line(format!("rating: {}", info.rating));
|
||||
//! return file.write_line(format!("rating: {}", info.rating).as_slice());
|
||||
//! }
|
||||
//! ~~~
|
||||
//!
|
||||
|
@ -191,14 +195,18 @@
|
|||
//! ~~~
|
||||
//! use std::io::{File, Open, Write, IoError};
|
||||
//!
|
||||
//! struct Info { name: ~str, age: int, rating: int }
|
||||
//! struct Info {
|
||||
//! name: StrBuf,
|
||||
//! age: int,
|
||||
//! rating: int
|
||||
//! }
|
||||
//!
|
||||
//! fn write_info(info: &Info) -> Result<(), IoError> {
|
||||
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
|
||||
//! // Early return on error
|
||||
//! try!(file.write_line(format!("name: {}", info.name)));
|
||||
//! try!(file.write_line(format!("age: {}", info.age)));
|
||||
//! try!(file.write_line(format!("rating: {}", info.rating)));
|
||||
//! try!(file.write_line(format!("name: {}", info.name).as_slice()));
|
||||
//! try!(file.write_line(format!("age: {}", info.age).as_slice()));
|
||||
//! try!(file.write_line(format!("rating: {}", info.rating).as_slice()));
|
||||
//! return Ok(());
|
||||
//! }
|
||||
//! ~~~
|
||||
|
@ -421,10 +429,10 @@ impl<T, E> Result<T, E> {
|
|||
/// let mut sum = 0;
|
||||
///
|
||||
/// while !reader.eof() {
|
||||
/// let line: IoResult<~str> = reader.read_line();
|
||||
/// let line: IoResult<StrBuf> = reader.read_line();
|
||||
/// // Convert the string line to a number using `map` and `from_str`
|
||||
/// let val: IoResult<int> = line.map(|line| {
|
||||
/// from_str::<int>(line).unwrap_or(0)
|
||||
/// from_str::<int>(line.as_slice()).unwrap_or(0)
|
||||
/// });
|
||||
/// // Add the value if there were no errors, otherwise add 0
|
||||
/// sum += val.ok().unwrap_or(0);
|
||||
|
@ -629,69 +637,68 @@ pub fn fold_<T,E,Iter:Iterator<Result<T,E>>>(iterator: Iter) -> Result<(),E> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use realstd::vec::Vec;
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::strbuf::StrBuf;
|
||||
|
||||
use result::{collect, fold, fold_};
|
||||
use prelude::*;
|
||||
use realstd::str::{Str, StrAllocating};
|
||||
use iter::range;
|
||||
|
||||
pub fn op1() -> Result<int, ~str> { Ok(666) }
|
||||
pub fn op2() -> Result<int, ~str> { Err("sadface".to_owned()) }
|
||||
pub fn op1() -> Result<int, &'static str> { Ok(666) }
|
||||
pub fn op2() -> Result<int, &'static str> { Err("sadface") }
|
||||
|
||||
#[test]
|
||||
pub fn test_and() {
|
||||
assert_eq!(op1().and(Ok(667)).unwrap(), 667);
|
||||
assert_eq!(op1().and(Err::<(), ~str>("bad".to_owned())).unwrap_err(), "bad".to_owned());
|
||||
assert_eq!(op1().and(Err::<(), &'static str>("bad")).unwrap_err(),
|
||||
"bad");
|
||||
|
||||
assert_eq!(op2().and(Ok(667)).unwrap_err(), "sadface".to_owned());
|
||||
assert_eq!(op2().and(Err::<(), ~str>("bad".to_owned())).unwrap_err(), "sadface".to_owned());
|
||||
assert_eq!(op2().and(Ok(667)).unwrap_err(), "sadface");
|
||||
assert_eq!(op2().and(Err::<(),&'static str>("bad")).unwrap_err(),
|
||||
"sadface");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_and_then() {
|
||||
assert_eq!(op1().and_then(|i| Ok::<int, ~str>(i + 1)).unwrap(), 667);
|
||||
assert_eq!(op1().and_then(|_| Err::<int, ~str>("bad".to_owned())).unwrap_err(),
|
||||
"bad".to_owned());
|
||||
assert_eq!(op1().and_then(|i| Ok::<int, &'static str>(i + 1)).unwrap(), 667);
|
||||
assert_eq!(op1().and_then(|_| Err::<int, &'static str>("bad")).unwrap_err(),
|
||||
"bad");
|
||||
|
||||
assert_eq!(op2().and_then(|i| Ok::<int, ~str>(i + 1)).unwrap_err(),
|
||||
"sadface".to_owned());
|
||||
assert_eq!(op2().and_then(|_| Err::<int, ~str>("bad".to_owned())).unwrap_err(),
|
||||
"sadface".to_owned());
|
||||
assert_eq!(op2().and_then(|i| Ok::<int, &'static str>(i + 1)).unwrap_err(),
|
||||
"sadface");
|
||||
assert_eq!(op2().and_then(|_| Err::<int, &'static str>("bad")).unwrap_err(),
|
||||
"sadface");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_or() {
|
||||
assert_eq!(op1().or(Ok(667)).unwrap(), 666);
|
||||
assert_eq!(op1().or(Err("bad".to_owned())).unwrap(), 666);
|
||||
assert_eq!(op1().or(Err("bad")).unwrap(), 666);
|
||||
|
||||
assert_eq!(op2().or(Ok(667)).unwrap(), 667);
|
||||
assert_eq!(op2().or(Err("bad".to_owned())).unwrap_err(), "bad".to_owned());
|
||||
assert_eq!(op2().or(Err("bad")).unwrap_err(), "bad");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_or_else() {
|
||||
assert_eq!(op1().or_else(|_| Ok::<int, ~str>(667)).unwrap(), 666);
|
||||
assert_eq!(op1().or_else(|e| Err::<int, ~str>(e + "!")).unwrap(), 666);
|
||||
assert_eq!(op1().or_else(|_| Ok::<int, &'static str>(667)).unwrap(), 666);
|
||||
assert_eq!(op1().or_else(|e| Err::<int, &'static str>(e)).unwrap(), 666);
|
||||
|
||||
assert_eq!(op2().or_else(|_| Ok::<int, ~str>(667)).unwrap(), 667);
|
||||
assert_eq!(op2().or_else(|e| Err::<int, ~str>(e + "!")).unwrap_err(),
|
||||
"sadface!".to_owned());
|
||||
assert_eq!(op2().or_else(|_| Ok::<int, &'static str>(667)).unwrap(), 667);
|
||||
assert_eq!(op2().or_else(|e| Err::<int, &'static str>(e)).unwrap_err(),
|
||||
"sadface");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_map() {
|
||||
assert_eq!(Ok::<~str, ~str>("a".to_owned()).map(|x| x + "b"),
|
||||
Ok("ab".to_owned()));
|
||||
assert_eq!(Err::<~str, ~str>("a".to_owned()).map(|x| x + "b"),
|
||||
Err("a".to_owned()));
|
||||
assert!(Ok::<int, int>(1).map(|x| x + 1) == Ok(2));
|
||||
assert!(Err::<int, int>(1).map(|x| x + 1) == Err(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_map_err() {
|
||||
assert_eq!(Ok::<~str, ~str>("a".to_owned()).map_err(|x| x + "b"),
|
||||
Ok("a".to_owned()));
|
||||
assert_eq!(Err::<~str, ~str>("a".to_owned()).map_err(|x| x + "b"),
|
||||
Err("ab".to_owned()));
|
||||
assert!(Ok::<int, int>(1).map_err(|x| x + 1) == Ok(1));
|
||||
assert!(Err::<int, int>(1).map_err(|x| x + 1) == Err(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -736,17 +743,19 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn test_fmt_default() {
|
||||
let ok: Result<int, ~str> = Ok(100);
|
||||
let err: Result<int, ~str> = Err("Err".to_owned());
|
||||
let ok: Result<int, &'static str> = Ok(100);
|
||||
let err: Result<int, &'static str> = Err("Err");
|
||||
|
||||
assert_eq!(format!("{}", ok), "Ok(100)".to_owned());
|
||||
assert_eq!(format!("{}", err), "Err(Err)".to_owned());
|
||||
let s = format!("{}", ok);
|
||||
assert_eq!(s.as_slice(), "Ok(100)");
|
||||
let s = format!("{}", err);
|
||||
assert_eq!(s.as_slice(), "Err(Err)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_unwrap_or() {
|
||||
let ok: Result<int, ~str> = Ok(100);
|
||||
let ok_err: Result<int, ~str> = Err("Err".to_owned());
|
||||
let ok: Result<int, &'static str> = Ok(100);
|
||||
let ok_err: Result<int, &'static str> = Err("Err");
|
||||
|
||||
assert_eq!(ok.unwrap_or(50), 100);
|
||||
assert_eq!(ok_err.unwrap_or(50), 50);
|
||||
|
@ -754,16 +763,16 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn test_unwrap_or_else() {
|
||||
fn handler(msg: ~str) -> int {
|
||||
if msg == "I got this.".to_owned() {
|
||||
fn handler(msg: &'static str) -> int {
|
||||
if msg == "I got this." {
|
||||
50
|
||||
} else {
|
||||
fail!("BadBad")
|
||||
}
|
||||
}
|
||||
|
||||
let ok: Result<int, ~str> = Ok(100);
|
||||
let ok_err: Result<int, ~str> = Err("I got this.".to_owned());
|
||||
let ok: Result<int, &'static str> = Ok(100);
|
||||
let ok_err: Result<int, &'static str> = Err("I got this.");
|
||||
|
||||
assert_eq!(ok.unwrap_or_else(handler), 100);
|
||||
assert_eq!(ok_err.unwrap_or_else(handler), 50);
|
||||
|
@ -772,15 +781,15 @@ mod tests {
|
|||
#[test]
|
||||
#[should_fail]
|
||||
pub fn test_unwrap_or_else_failure() {
|
||||
fn handler(msg: ~str) -> int {
|
||||
if msg == "I got this.".to_owned() {
|
||||
fn handler(msg: &'static str) -> int {
|
||||
if msg == "I got this." {
|
||||
50
|
||||
} else {
|
||||
fail!("BadBad")
|
||||
}
|
||||
}
|
||||
|
||||
let bad_err: Result<int, ~str> = Err("Unrecoverable mess.".to_owned());
|
||||
let bad_err: Result<int, &'static str> = Err("Unrecoverable mess.");
|
||||
let _ : int = bad_err.unwrap_or_else(handler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
// As noted by this file name, this file should not exist. This file should not
|
||||
// exist because it performs allocations which libcore is not allowed to do. The
|
||||
// reason for this file's existence is that the `~[T]` and `~str` types are
|
||||
// language-defined types. Traits are defined in libcore, such as `Clone`, which
|
||||
// these types need to implement, but the implementation can only be found in
|
||||
// reason for this file's existence is that the `~[T]` type is a language-
|
||||
// defined type. Traits are defined in libcore, such as `Clone`, which these
|
||||
// types need to implement, but the implementation can only be found in
|
||||
// libcore.
|
||||
//
|
||||
// Plan of attack for solving this problem:
|
||||
|
@ -24,13 +24,11 @@
|
|||
//
|
||||
// Currently, no progress has been made on this list.
|
||||
|
||||
use char::Char;
|
||||
use clone::Clone;
|
||||
use container::Container;
|
||||
use default::Default;
|
||||
use finally::try_finally;
|
||||
use intrinsics;
|
||||
use iter::{range, Iterator, FromIterator};
|
||||
use iter::{range, Iterator};
|
||||
use mem;
|
||||
use num::{CheckedMul, CheckedAdd};
|
||||
use option::{Some, None};
|
||||
|
@ -38,9 +36,6 @@ use ptr::RawPtr;
|
|||
use ptr;
|
||||
use raw::Vec;
|
||||
use slice::ImmutableVector;
|
||||
use str::StrSlice;
|
||||
|
||||
#[cfg(not(test))] use ops::Add;
|
||||
|
||||
#[allow(ctypes)]
|
||||
extern {
|
||||
|
@ -60,105 +55,6 @@ unsafe fn alloc(cap: uint) -> *mut Vec<()> {
|
|||
ret
|
||||
}
|
||||
|
||||
// Strings
|
||||
|
||||
impl Default for ~str {
|
||||
fn default() -> ~str {
|
||||
unsafe {
|
||||
// Get some memory
|
||||
let ptr = alloc(0);
|
||||
|
||||
// Initialize the memory
|
||||
(*ptr).fill = 0;
|
||||
(*ptr).alloc = 0;
|
||||
|
||||
mem::transmute(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for ~str {
|
||||
fn clone(&self) -> ~str {
|
||||
// Don't use the clone() implementation above because it'll start
|
||||
// requiring the eh_personality lang item (no fun)
|
||||
unsafe {
|
||||
let bytes = self.as_bytes().as_ptr();
|
||||
let len = self.len();
|
||||
|
||||
let ptr = alloc(len) as *mut Vec<u8>;
|
||||
ptr::copy_nonoverlapping_memory(&mut (*ptr).data, bytes, len);
|
||||
(*ptr).fill = len;
|
||||
(*ptr).alloc = len;
|
||||
|
||||
mem::transmute(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<char> for ~str {
|
||||
#[inline]
|
||||
fn from_iter<T: Iterator<char>>(mut iterator: T) -> ~str {
|
||||
let (lower, _) = iterator.size_hint();
|
||||
let mut cap = if lower == 0 {16} else {lower};
|
||||
let mut len = 0;
|
||||
let mut tmp = [0u8, ..4];
|
||||
|
||||
unsafe {
|
||||
let mut ptr = alloc(cap) as *mut Vec<u8>;
|
||||
let mut ret = mem::transmute(ptr);
|
||||
for ch in iterator {
|
||||
let amt = ch.encode_utf8(tmp);
|
||||
|
||||
if len + amt > cap {
|
||||
cap = cap.checked_mul(&2).unwrap();
|
||||
if cap < len + amt {
|
||||
cap = len + amt;
|
||||
}
|
||||
let ptr2 = alloc(cap) as *mut Vec<u8>;
|
||||
ptr::copy_nonoverlapping_memory(&mut (*ptr2).data,
|
||||
&(*ptr).data,
|
||||
len);
|
||||
// FIXME: #13994: port to the sized deallocation API when available
|
||||
rust_deallocate(ptr as *u8, 0, 8);
|
||||
mem::forget(ret);
|
||||
ret = mem::transmute(ptr2);
|
||||
ptr = ptr2;
|
||||
}
|
||||
|
||||
let base = &mut (*ptr).data as *mut u8;
|
||||
for byte in tmp.slice_to(amt).iter() {
|
||||
*base.offset(len as int) = *byte;
|
||||
len += 1;
|
||||
}
|
||||
(*ptr).fill = len;
|
||||
}
|
||||
ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl<'a> Add<&'a str,~str> for &'a str {
|
||||
#[inline]
|
||||
fn add(&self, rhs: & &'a str) -> ~str {
|
||||
let amt = self.len().checked_add(&rhs.len()).unwrap();
|
||||
unsafe {
|
||||
let ptr = alloc(amt) as *mut Vec<u8>;
|
||||
let base = &mut (*ptr).data as *mut _;
|
||||
ptr::copy_nonoverlapping_memory(base,
|
||||
self.as_bytes().as_ptr(),
|
||||
self.len());
|
||||
let base = base.offset(self.len() as int);
|
||||
ptr::copy_nonoverlapping_memory(base,
|
||||
rhs.as_bytes().as_ptr(),
|
||||
rhs.len());
|
||||
(*ptr).fill = amt;
|
||||
(*ptr).alloc = amt;
|
||||
mem::transmute(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Arrays
|
||||
|
||||
impl<A: Clone> Clone for ~[A] {
|
||||
|
|
|
@ -25,7 +25,7 @@ use iter::range;
|
|||
use num::Saturating;
|
||||
use option::{None, Option, Some};
|
||||
use raw::Repr;
|
||||
use slice::{ImmutableVector, Vector};
|
||||
use slice::ImmutableVector;
|
||||
use slice;
|
||||
use uint;
|
||||
|
||||
|
@ -596,20 +596,6 @@ pub fn eq_slice(a: &str, b: &str) -> bool {
|
|||
eq_slice_(a, b)
|
||||
}
|
||||
|
||||
/// Bytewise string equality
|
||||
#[cfg(not(test))]
|
||||
#[lang="uniq_str_eq"]
|
||||
#[inline]
|
||||
pub fn eq(a: &~str, b: &~str) -> bool {
|
||||
eq_slice(*a, *b)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[inline]
|
||||
pub fn eq(a: &~str, b: &~str) -> bool {
|
||||
eq_slice(*a, *b)
|
||||
}
|
||||
|
||||
/*
|
||||
Section: Misc
|
||||
*/
|
||||
|
@ -976,11 +962,6 @@ pub mod traits {
|
|||
}
|
||||
}
|
||||
|
||||
impl TotalOrd for ~str {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &~str) -> Ordering { self.as_slice().cmp(&other.as_slice()) }
|
||||
}
|
||||
|
||||
impl<'a> Eq for &'a str {
|
||||
#[inline]
|
||||
fn eq(&self, other: & &'a str) -> bool {
|
||||
|
@ -990,36 +971,17 @@ pub mod traits {
|
|||
fn ne(&self, other: & &'a str) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
impl Eq for ~str {
|
||||
#[inline]
|
||||
fn eq(&self, other: &~str) -> bool {
|
||||
eq_slice((*self), (*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TotalEq for &'a str {}
|
||||
|
||||
impl TotalEq for ~str {}
|
||||
|
||||
impl<'a> Ord for &'a str {
|
||||
#[inline]
|
||||
fn lt(&self, other: & &'a str) -> bool { self.cmp(other) == Less }
|
||||
}
|
||||
|
||||
impl Ord for ~str {
|
||||
#[inline]
|
||||
fn lt(&self, other: &~str) -> bool { self.cmp(other) == Less }
|
||||
}
|
||||
|
||||
impl<'a, S: Str> Equiv<S> for &'a str {
|
||||
#[inline]
|
||||
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
|
||||
}
|
||||
|
||||
impl<'a, S: Str> Equiv<S> for ~str {
|
||||
#[inline]
|
||||
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1036,11 +998,6 @@ impl<'a> Str for &'a str {
|
|||
fn as_slice<'a>(&'a self) -> &'a str { *self }
|
||||
}
|
||||
|
||||
impl<'a> Str for ~str {
|
||||
#[inline]
|
||||
fn as_slice<'a>(&'a self) -> &'a str { let s: &'a str = *self; s }
|
||||
}
|
||||
|
||||
impl<'a> Container for &'a str {
|
||||
#[inline]
|
||||
fn len(&self) -> uint {
|
||||
|
@ -1048,11 +1005,6 @@ impl<'a> Container for &'a str {
|
|||
}
|
||||
}
|
||||
|
||||
impl Container for ~str {
|
||||
#[inline]
|
||||
fn len(&self) -> uint { self.as_slice().len() }
|
||||
}
|
||||
|
||||
/// Methods for string slices
|
||||
pub trait StrSlice<'a> {
|
||||
/// Returns true if one string contains another
|
||||
|
|
|
@ -246,11 +246,11 @@ mod tests {
|
|||
use super::*;
|
||||
use clone::Clone;
|
||||
use cmp::*;
|
||||
use realstd::str::StrAllocating;
|
||||
use realstd::str::{Str, StrAllocating};
|
||||
|
||||
#[test]
|
||||
fn test_clone() {
|
||||
let a = (1, "2".to_owned());
|
||||
let a = (1, "2");
|
||||
let b = a.clone();
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
@ -323,8 +323,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
assert_eq!(format!("{}", (1,)), "(1,)".to_owned());
|
||||
assert_eq!(format!("{}", (1, true)), "(1, true)".to_owned());
|
||||
assert_eq!(format!("{}", (1, "hi".to_owned(), true)), "(1, hi, true)".to_owned());
|
||||
let s = format!("{}", (1,));
|
||||
assert_eq!(s.as_slice(), "(1,)");
|
||||
let s = format!("{}", (1, true));
|
||||
assert_eq!(s.as_slice(), "(1, true)");
|
||||
let s = format!("{}", (1, "hi", true));
|
||||
assert_eq!(s.as_slice(), "(1, hi, true)");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -690,13 +690,13 @@ mod test {
|
|||
|
||||
let pat = Pattern::new("a[0-9]b");
|
||||
for i in range(0, 10) {
|
||||
assert!(pat.matches(format!("a{}b", i)));
|
||||
assert!(pat.matches(format!("a{}b", i).as_slice()));
|
||||
}
|
||||
assert!(!pat.matches("a_b"));
|
||||
|
||||
let pat = Pattern::new("a[!0-9]b");
|
||||
for i in range(0, 10) {
|
||||
assert!(!pat.matches(format!("a{}b", i)));
|
||||
assert!(!pat.matches(format!("a{}b", i).as_slice()));
|
||||
}
|
||||
assert!(pat.matches("a_b"));
|
||||
|
||||
|
@ -704,11 +704,11 @@ mod test {
|
|||
for &p in pats.iter() {
|
||||
let pat = Pattern::new(p);
|
||||
for c in "abcdefghijklmnopqrstuvwxyz".chars() {
|
||||
assert!(pat.matches(c.to_str()));
|
||||
assert!(pat.matches(c.to_str().as_slice()));
|
||||
}
|
||||
for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars() {
|
||||
let options = MatchOptions {case_sensitive: false, .. MatchOptions::new()};
|
||||
assert!(pat.matches_with(c.to_str(), options));
|
||||
assert!(pat.matches_with(c.to_str().as_slice(), options));
|
||||
}
|
||||
assert!(pat.matches("1"));
|
||||
assert!(pat.matches("2"));
|
||||
|
|
|
@ -450,7 +450,9 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
|
|||
libc::VOLUME_NAME_DOS)
|
||||
});
|
||||
let ret = match ret {
|
||||
Some(ref s) if s.starts_with(r"\\?\") => Ok(Path::new(s.slice_from(4))),
|
||||
Some(ref s) if s.as_slice().starts_with(r"\\?\") => {
|
||||
Ok(Path::new(s.as_slice().slice_from(4)))
|
||||
}
|
||||
Some(s) => Ok(Path::new(s)),
|
||||
None => Err(super::last_error()),
|
||||
};
|
||||
|
|
|
@ -323,7 +323,7 @@ fn spawn_process_os(cfg: ProcessConfig, in_fd: c_int, out_fd: c_int, err_fd: c_i
|
|||
|
||||
with_envp(cfg.env, |envp| {
|
||||
with_dirp(cfg.cwd, |dirp| {
|
||||
os::win32::as_mut_utf16_p(cmd_str, |cmdp| {
|
||||
os::win32::as_mut_utf16_p(cmd_str.as_slice(), |cmdp| {
|
||||
let created = CreateProcessW(ptr::null(),
|
||||
cmdp,
|
||||
ptr::mut_null(),
|
||||
|
@ -396,7 +396,7 @@ fn zeroed_process_information() -> libc::types::os::arch::extra::PROCESS_INFORMA
|
|||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn make_command_line(prog: &CString, args: &[CString]) -> ~str {
|
||||
fn make_command_line(prog: &CString, args: &[CString]) -> StrBuf {
|
||||
let mut cmd = StrBuf::new();
|
||||
append_arg(&mut cmd, prog.as_str()
|
||||
.expect("expected program name to be utf-8 encoded"));
|
||||
|
@ -405,7 +405,7 @@ fn make_command_line(prog: &CString, args: &[CString]) -> ~str {
|
|||
append_arg(&mut cmd, arg.as_str()
|
||||
.expect("expected argument to be utf-8 encoded"));
|
||||
}
|
||||
return cmd.into_owned();
|
||||
return cmd;
|
||||
|
||||
fn append_arg(cmd: &mut StrBuf, arg: &str) {
|
||||
let quote = arg.chars().any(|c| c == ' ' || c == '\t');
|
||||
|
@ -1093,7 +1093,7 @@ mod tests {
|
|||
use std::c_str::CString;
|
||||
use super::make_command_line;
|
||||
|
||||
fn test_wrapper(prog: &str, args: &[&str]) -> ~str {
|
||||
fn test_wrapper(prog: &str, args: &[&str]) -> StrBuf {
|
||||
make_command_line(&prog.to_c_str(),
|
||||
args.iter()
|
||||
.map(|a| a.to_c_str())
|
||||
|
|
|
@ -634,7 +634,7 @@ impl ToStrRadix for BigUint {
|
|||
let mut s = StrBuf::with_capacity(v.len() * l);
|
||||
for n in v.iter().rev() {
|
||||
let ss = (*n as uint).to_str_radix(radix);
|
||||
s.push_str("0".repeat(l - ss.len()));
|
||||
s.push_str("0".repeat(l - ss.len()).as_slice());
|
||||
s.push_str(ss.as_slice());
|
||||
}
|
||||
s.as_slice().trim_left_chars('0').to_strbuf()
|
||||
|
@ -1478,29 +1478,112 @@ mod biguint_tests {
|
|||
check("0", 3, "0");
|
||||
check("1", 3, "8");
|
||||
|
||||
check("1" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 3,
|
||||
"8" + "0000" + "0000" + "0000" + "0008" + "0000" + "0000" + "0000" + "0008");
|
||||
check("1" + "0000" + "0001" + "0000" + "0001", 2,
|
||||
"4" + "0000" + "0004" + "0000" + "0004");
|
||||
check("1" + "0001" + "0001", 1,
|
||||
"2" + "0002" + "0002");
|
||||
check("1\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0001\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0001",
|
||||
3,
|
||||
"8\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0008\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0008");
|
||||
check("1\
|
||||
0000\
|
||||
0001\
|
||||
0000\
|
||||
0001",
|
||||
2,
|
||||
"4\
|
||||
0000\
|
||||
0004\
|
||||
0000\
|
||||
0004");
|
||||
check("1\
|
||||
0001\
|
||||
0001",
|
||||
1,
|
||||
"2\
|
||||
0002\
|
||||
0002");
|
||||
|
||||
check("" + "4000" + "0000" + "0000" + "0000", 3,
|
||||
"2" + "0000" + "0000" + "0000" + "0000");
|
||||
check("" + "4000" + "0000", 2,
|
||||
"1" + "0000" + "0000");
|
||||
check("" + "4000", 2,
|
||||
"1" + "0000");
|
||||
check("\
|
||||
4000\
|
||||
0000\
|
||||
0000\
|
||||
0000",
|
||||
3,
|
||||
"2\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000");
|
||||
check("4000\
|
||||
0000",
|
||||
2,
|
||||
"1\
|
||||
0000\
|
||||
0000");
|
||||
check("4000",
|
||||
2,
|
||||
"1\
|
||||
0000");
|
||||
|
||||
check("" + "4000" + "0000" + "0000" + "0000", 67,
|
||||
"2" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000");
|
||||
check("" + "4000" + "0000", 35,
|
||||
"2" + "0000" + "0000" + "0000" + "0000");
|
||||
check("" + "4000", 19,
|
||||
"2" + "0000" + "0000");
|
||||
check("4000\
|
||||
0000\
|
||||
0000\
|
||||
0000",
|
||||
67,
|
||||
"2\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000");
|
||||
check("4000\
|
||||
0000",
|
||||
35,
|
||||
"2\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000");
|
||||
check("4000",
|
||||
19,
|
||||
"2\
|
||||
0000\
|
||||
0000");
|
||||
|
||||
check("" + "fedc" + "ba98" + "7654" + "3210" + "fedc" + "ba98" + "7654" + "3210", 4,
|
||||
"f" + "edcb" + "a987" + "6543" + "210f" + "edcb" + "a987" + "6543" + "2100");
|
||||
check("fedc\
|
||||
ba98\
|
||||
7654\
|
||||
3210\
|
||||
fedc\
|
||||
ba98\
|
||||
7654\
|
||||
3210",
|
||||
4,
|
||||
"f\
|
||||
edcb\
|
||||
a987\
|
||||
6543\
|
||||
210f\
|
||||
edcb\
|
||||
a987\
|
||||
6543\
|
||||
2100");
|
||||
check("88887777666655554444333322221111", 16,
|
||||
"888877776666555544443333222211110000");
|
||||
}
|
||||
|
@ -1517,28 +1600,107 @@ mod biguint_tests {
|
|||
check("0", 3, "0");
|
||||
check("f", 3, "1");
|
||||
|
||||
check("1" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 3,
|
||||
"" + "2000" + "0000" + "0000" + "0000" + "2000" + "0000" + "0000" + "0000");
|
||||
check("1" + "0000" + "0001" + "0000" + "0001", 2,
|
||||
"" + "4000" + "0000" + "4000" + "0000");
|
||||
check("1" + "0001" + "0001", 1,
|
||||
"" + "8000" + "8000");
|
||||
check("1\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0001\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0001",
|
||||
3,
|
||||
"2000\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
2000\
|
||||
0000\
|
||||
0000\
|
||||
0000");
|
||||
check("1\
|
||||
0000\
|
||||
0001\
|
||||
0000\
|
||||
0001",
|
||||
2,
|
||||
"4000\
|
||||
0000\
|
||||
4000\
|
||||
0000");
|
||||
check("1\
|
||||
0001\
|
||||
0001",
|
||||
1,
|
||||
"8000\
|
||||
8000");
|
||||
|
||||
check("2" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 67,
|
||||
"" + "4000" + "0000" + "0000" + "0000");
|
||||
check("2" + "0000" + "0001" + "0000" + "0001", 35,
|
||||
"" + "4000" + "0000");
|
||||
check("2" + "0001" + "0001", 19,
|
||||
"" + "4000");
|
||||
check("2\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0001\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0001",
|
||||
67,
|
||||
"4000\
|
||||
0000\
|
||||
0000\
|
||||
0000");
|
||||
check("2\
|
||||
0000\
|
||||
0001\
|
||||
0000\
|
||||
0001",
|
||||
35,
|
||||
"4000\
|
||||
0000");
|
||||
check("2\
|
||||
0001\
|
||||
0001",
|
||||
19,
|
||||
"4000");
|
||||
|
||||
check("1" + "0000" + "0000" + "0000" + "0000", 1,
|
||||
"" + "8000" + "0000" + "0000" + "0000");
|
||||
check("1" + "0000" + "0000", 1,
|
||||
"" + "8000" + "0000");
|
||||
check("1" + "0000", 1,
|
||||
"" + "8000");
|
||||
check("f" + "edcb" + "a987" + "6543" + "210f" + "edcb" + "a987" + "6543" + "2100", 4,
|
||||
"" + "fedc" + "ba98" + "7654" + "3210" + "fedc" + "ba98" + "7654" + "3210");
|
||||
check("1\
|
||||
0000\
|
||||
0000\
|
||||
0000\
|
||||
0000",
|
||||
1,
|
||||
"8000\
|
||||
0000\
|
||||
0000\
|
||||
0000");
|
||||
check("1\
|
||||
0000\
|
||||
0000",
|
||||
1,
|
||||
"8000\
|
||||
0000");
|
||||
check("1\
|
||||
0000",
|
||||
1,
|
||||
"8000");
|
||||
check("f\
|
||||
edcb\
|
||||
a987\
|
||||
6543\
|
||||
210f\
|
||||
edcb\
|
||||
a987\
|
||||
6543\
|
||||
2100",
|
||||
4,
|
||||
"fedc\
|
||||
ba98\
|
||||
7654\
|
||||
3210\
|
||||
fedc\
|
||||
ba98\
|
||||
7654\
|
||||
3210");
|
||||
|
||||
check("888877776666555544443333222211110000", 16,
|
||||
"88887777666655554444333322221111");
|
||||
|
@ -2545,7 +2707,7 @@ mod bigint_tests {
|
|||
fn test_to_str_radix() {
|
||||
fn check(n: int, ans: &str) {
|
||||
let n: BigInt = FromPrimitive::from_int(n).unwrap();
|
||||
assert!(ans == n.to_str_radix(10));
|
||||
assert!(ans == n.to_str_radix(10).as_slice());
|
||||
}
|
||||
check(10, "10");
|
||||
check(1, "1");
|
||||
|
@ -2574,7 +2736,8 @@ mod bigint_tests {
|
|||
|
||||
// issue 10522, this hit an edge case that caused it to
|
||||
// attempt to allocate a vector of size (-1u) == huge.
|
||||
let x: BigInt = from_str("1" + "0".repeat(36)).unwrap();
|
||||
let x: BigInt =
|
||||
from_str(format!("1{}", "0".repeat(36)).as_slice()).unwrap();
|
||||
let _y = x.to_str();
|
||||
}
|
||||
|
||||
|
|
|
@ -584,7 +584,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_to_from_str_radix() {
|
||||
fn test(r: Rational, s: StrBuf, n: uint) {
|
||||
assert_eq!(FromStrRadix::from_str_radix(s.to_owned(), n),
|
||||
assert_eq!(FromStrRadix::from_str_radix(s.as_slice(), n),
|
||||
Some(r));
|
||||
assert_eq!(r.to_str_radix(n).to_strbuf(), s);
|
||||
}
|
||||
|
|
|
@ -513,11 +513,11 @@ impl<'a> Parser<'a> {
|
|||
|
||||
// Parse the min and max values from the regex.
|
||||
let (mut min, mut max): (uint, Option<uint>);
|
||||
if !inner.contains(",") {
|
||||
min = try!(self.parse_uint(inner));
|
||||
if !inner.as_slice().contains(",") {
|
||||
min = try!(self.parse_uint(inner.as_slice()));
|
||||
max = Some(min);
|
||||
} else {
|
||||
let pieces: Vec<&str> = inner.splitn(',', 1).collect();
|
||||
let pieces: Vec<&str> = inner.as_slice().splitn(',', 1).collect();
|
||||
let (smin, smax) = (*pieces.get(0), *pieces.get(1));
|
||||
if smin.len() == 0 {
|
||||
return self.err("Max repetitions cannot be specified \
|
||||
|
|
|
@ -20,38 +20,40 @@ fn bench_assert_match(b: &mut Bencher, re: Regex, text: &str) {
|
|||
#[bench]
|
||||
fn no_exponential(b: &mut Bencher) {
|
||||
let n = 100;
|
||||
let re = Regex::new("a?".repeat(n) + "a".repeat(n)).unwrap();
|
||||
let re = Regex::new(format!("{}{}",
|
||||
"a?".repeat(n),
|
||||
"a".repeat(n)).as_slice()).unwrap();
|
||||
let text = "a".repeat(n);
|
||||
bench_assert_match(b, re, text);
|
||||
bench_assert_match(b, re, text.as_slice());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn literal(b: &mut Bencher) {
|
||||
let re = regex!("y");
|
||||
let text = "x".repeat(50) + "y";
|
||||
bench_assert_match(b, re, text);
|
||||
let text = format!("{}y", "x".repeat(50));
|
||||
bench_assert_match(b, re, text.as_slice());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn not_literal(b: &mut Bencher) {
|
||||
let re = regex!(".y");
|
||||
let text = "x".repeat(50) + "y";
|
||||
bench_assert_match(b, re, text);
|
||||
let text = format!("{}y", "x".repeat(50));
|
||||
bench_assert_match(b, re, text.as_slice());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn match_class(b: &mut Bencher) {
|
||||
let re = regex!("[abcdw]");
|
||||
let text = "xxxx".repeat(20) + "w";
|
||||
bench_assert_match(b, re, text);
|
||||
let text = format!("{}w", "xxxx".repeat(20));
|
||||
bench_assert_match(b, re, text.as_slice());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn match_class_in_range(b: &mut Bencher) {
|
||||
// 'b' is between 'a' and 'c', so the class range checking doesn't help.
|
||||
let re = regex!("[ac]");
|
||||
let text = "bbbb".repeat(20) + "c";
|
||||
bench_assert_match(b, re, text);
|
||||
let text = format!("{}c", "bbbb".repeat(20));
|
||||
bench_assert_match(b, re, text.as_slice());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
@ -75,7 +77,7 @@ fn anchored_literal_short_non_match(b: &mut Bencher) {
|
|||
fn anchored_literal_long_non_match(b: &mut Bencher) {
|
||||
let re = regex!("^zbc(d|e)");
|
||||
let text = "abcdefghijklmnopqrstuvwxyz".repeat(15);
|
||||
b.iter(|| re.is_match(text));
|
||||
b.iter(|| re.is_match(text.as_slice()));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
@ -89,7 +91,7 @@ fn anchored_literal_short_match(b: &mut Bencher) {
|
|||
fn anchored_literal_long_match(b: &mut Bencher) {
|
||||
let re = regex!("^.bc(d|e)");
|
||||
let text = "abcdefghijklmnopqrstuvwxyz".repeat(15);
|
||||
b.iter(|| re.is_match(text));
|
||||
b.iter(|| re.is_match(text.as_slice()));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
|
|
@ -82,7 +82,7 @@ fn native(cx: &mut ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree])
|
|||
// error is logged in 'parse' with cx.span_err
|
||||
None => return DummyResult::any(sp),
|
||||
};
|
||||
let re = match Regex::new(regex.to_owned()) {
|
||||
let re = match Regex::new(regex.as_slice()) {
|
||||
Ok(re) => re,
|
||||
Err(err) => {
|
||||
cx.span_err(sp, err.to_str().as_slice());
|
||||
|
|
|
@ -62,7 +62,9 @@ pub fn llvm_err(sess: &Session, msg: StrBuf) -> ! {
|
|||
} else {
|
||||
let err = CString::new(cstr, true);
|
||||
let err = str::from_utf8_lossy(err.as_bytes());
|
||||
sess.fatal((msg.as_slice() + ": " + err.as_slice()));
|
||||
sess.fatal(format!("{}: {}",
|
||||
msg.as_slice(),
|
||||
err.as_slice()).as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -647,7 +649,7 @@ pub fn sanitize(s: &str) -> StrBuf {
|
|||
if result.len() > 0u &&
|
||||
result.as_slice()[0] != '_' as u8 &&
|
||||
! char::is_XID_start(result.as_slice()[0] as char) {
|
||||
return ("_" + result.as_slice()).to_strbuf();
|
||||
return format!("_{}", result.as_slice()).to_strbuf();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<StrBuf> {
|
|||
pub fn rpaths_to_flags(rpaths: &[StrBuf]) -> Vec<StrBuf> {
|
||||
let mut ret = Vec::new();
|
||||
for rpath in rpaths.iter() {
|
||||
ret.push(("-Wl,-rpath," + (*rpath).as_slice()).to_strbuf());
|
||||
ret.push(format!("-Wl,-rpath,{}", (*rpath).as_slice()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -132,8 +132,9 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
|
|||
let relative = lib.path_relative_from(&output);
|
||||
let relative = relative.expect("could not create rpath relative to output");
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
(prefix + "/" + relative.as_str()
|
||||
.expect("non-utf8 component in path")).to_strbuf()
|
||||
format!("{}/{}",
|
||||
prefix,
|
||||
relative.as_str().expect("non-utf8 component in path"))
|
||||
}
|
||||
|
||||
pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> StrBuf {
|
||||
|
|
|
@ -469,8 +469,8 @@ pub fn build_target_config(sopts: &Options) -> Config {
|
|||
let arch = match get_arch(sopts.target_triple.as_slice()) {
|
||||
Some(arch) => arch,
|
||||
None => {
|
||||
early_error("unknown architecture: " +
|
||||
sopts.target_triple.as_slice())
|
||||
early_error(format!("unknown architecture: {}",
|
||||
sopts.target_triple.as_slice()).as_slice())
|
||||
}
|
||||
};
|
||||
let (int_type, uint_type) = match arch {
|
||||
|
|
|
@ -259,7 +259,9 @@ impl<'a> Visitor<()> for Context<'a> {
|
|||
else {
|
||||
for "e in quotes.iter() {
|
||||
if id == token::str_to_ident(quote) {
|
||||
self.gate_feature("quote", path.span, quote + msg);
|
||||
self.gate_feature("quote",
|
||||
path.span,
|
||||
format!("{}{}", quote, msg).as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,8 @@ pub fn register_static(ccx: &CrateContext,
|
|||
});
|
||||
lib::llvm::SetLinkage(g1, linkage);
|
||||
|
||||
let real_name = "_rust_extern_with_linkage_" + ident.get();
|
||||
let mut real_name = "_rust_extern_with_linkage_".to_strbuf();
|
||||
real_name.push_str(ident.get());
|
||||
let g2 = real_name.with_c_str(|buf| {
|
||||
llvm::LLVMAddGlobal(ccx.llmod, llty.to_ref(), buf)
|
||||
});
|
||||
|
|
|
@ -117,9 +117,9 @@ impl<'a, 'b> Reflector<'a, 'b> {
|
|||
bracket_name: &str,
|
||||
extra: &[ValueRef],
|
||||
inner: |&mut Reflector|) {
|
||||
self.visit("enter_" + bracket_name, extra);
|
||||
self.visit(format!("enter_{}", bracket_name).as_slice(), extra);
|
||||
inner(self);
|
||||
self.visit("leave_" + bracket_name, extra);
|
||||
self.visit(format!("leave_{}", bracket_name).as_slice(), extra);
|
||||
}
|
||||
|
||||
pub fn leaf(&mut self, name: &str) {
|
||||
|
|
|
@ -85,7 +85,7 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
|
|||
$(
|
||||
if missing.contains(&lang_items::$item) && items.$name().is_none() {
|
||||
sess.err(format!("language item required, but not found: `{}`",
|
||||
stringify!($name)));
|
||||
stringify!($name)).as_slice());
|
||||
|
||||
}
|
||||
)*
|
||||
|
@ -100,7 +100,7 @@ impl<'a> Context<'a> {
|
|||
} else)* {
|
||||
self.sess.span_err(span,
|
||||
format!("unknown external lang item: `{}`",
|
||||
name));
|
||||
name).as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1015,7 +1015,10 @@ impl Clean<Type> for ty::t {
|
|||
let fqn: Vec<StrBuf> = fqn.move_iter().map(|i| {
|
||||
i.to_str().to_strbuf()
|
||||
}).collect();
|
||||
let mut path = external_path(fqn.last().unwrap().to_str());
|
||||
let mut path = external_path(fqn.last()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.as_slice());
|
||||
let kind = match ty::get(*self).sty {
|
||||
ty::ty_struct(..) => TypeStruct,
|
||||
ty::ty_trait(..) => TypeTrait,
|
||||
|
|
|
@ -206,7 +206,7 @@ fn path(w: &mut fmt::Formatter, path: &clean::Path, print_all: bool,
|
|||
let amt = path.segments.len() - 1;
|
||||
match rel_root {
|
||||
Some(root) => {
|
||||
let mut root = StrBuf::from_str(root);
|
||||
let mut root = StrBuf::from_str(root.as_slice());
|
||||
for seg in path.segments.slice_to(amt).iter() {
|
||||
if "super" == seg.name.as_slice() ||
|
||||
"self" == seg.name.as_slice() {
|
||||
|
|
|
@ -177,8 +177,9 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
|
|||
};
|
||||
|
||||
if !rendered {
|
||||
let output = highlight::highlight(text, None).as_slice()
|
||||
.to_c_str();
|
||||
let output = highlight::highlight(text.as_slice(),
|
||||
None).as_slice()
|
||||
.to_c_str();
|
||||
output.with_ref(|r| {
|
||||
hoedown_buffer_puts(ob, r)
|
||||
})
|
||||
|
@ -202,7 +203,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
|
|||
};
|
||||
|
||||
// Transform the contents of the header into a hyphenated string
|
||||
let id = (s.words().map(|s| {
|
||||
let id = (s.as_slice().words().map(|s| {
|
||||
match s.to_ascii_opt() {
|
||||
Some(s) => s.to_lower().into_str().to_strbuf(),
|
||||
None => s.to_strbuf()
|
||||
|
|
|
@ -971,7 +971,7 @@ impl Context {
|
|||
// does make formatting *a lot* nicer.
|
||||
current_location_key.replace(Some(cx.current.clone()));
|
||||
|
||||
let mut title = StrBuf::from_str(cx.current.connect("::"));
|
||||
let mut title = cx.current.connect("::");
|
||||
if pushname {
|
||||
if title.len() > 0 {
|
||||
title.push_str("::");
|
||||
|
@ -1141,7 +1141,7 @@ fn item_path(item: &clean::Item) -> StrBuf {
|
|||
}
|
||||
|
||||
fn full_path(cx: &Context, item: &clean::Item) -> StrBuf {
|
||||
let mut s = StrBuf::from_str(cx.current.connect("::"));
|
||||
let mut s = cx.current.connect("::");
|
||||
s.push_str("::");
|
||||
s.push_str(item.name.get_ref().as_slice());
|
||||
return s
|
||||
|
|
|
@ -346,14 +346,14 @@ mod unindent_tests {
|
|||
#[test]
|
||||
fn should_unindent() {
|
||||
let s = " line1\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
let r = unindent(s.as_slice());
|
||||
assert_eq!(r.as_slice(), "line1\nline2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_unindent_multiple_paragraphs() {
|
||||
let s = " line1\n\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
let r = unindent(s.as_slice());
|
||||
assert_eq!(r.as_slice(), "line1\n\nline2");
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ mod unindent_tests {
|
|||
// Line 2 is indented another level beyond the
|
||||
// base indentation and should be preserved
|
||||
let s = " line1\n\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
let r = unindent(s.as_slice());
|
||||
assert_eq!(r.as_slice(), "line1\n\n line2");
|
||||
}
|
||||
|
||||
|
@ -374,14 +374,14 @@ mod unindent_tests {
|
|||
// #[doc = "Start way over here
|
||||
// and continue here"]
|
||||
let s = "line1\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
let r = unindent(s.as_slice());
|
||||
assert_eq!(r.as_slice(), "line1\nline2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_ignore_first_line_indent_in_a_single_line_para() {
|
||||
let s = "line1\n\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
let r = unindent(s.as_slice());
|
||||
assert_eq!(r.as_slice(), "line1\n\n line2");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
|||
|
||||
// Remove the previous dylib search path var
|
||||
let var = DynamicLibrary::envvar();
|
||||
let mut env: Vec<(~str,~str)> = os::env().move_iter().collect();
|
||||
let mut env: Vec<(StrBuf,StrBuf)> = os::env().move_iter().collect();
|
||||
match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
|
||||
Some(i) => { env.remove(i); }
|
||||
None => {}
|
||||
|
@ -276,7 +276,7 @@ impl Collector {
|
|||
},
|
||||
testfn: testing::DynTestFn(proc() {
|
||||
runtest(test.as_slice(),
|
||||
cratename,
|
||||
cratename.as_slice(),
|
||||
libs,
|
||||
should_fail,
|
||||
no_run,
|
||||
|
|
|
@ -182,8 +182,16 @@ mod tests {
|
|||
#[test]
|
||||
pub fn test_from_hex_all_bytes() {
|
||||
for i in range(0, 256) {
|
||||
assert_eq!(format!("{:02x}", i as uint).from_hex().unwrap().as_slice(), &[i as u8]);
|
||||
assert_eq!(format!("{:02X}", i as uint).from_hex().unwrap().as_slice(), &[i as u8]);
|
||||
assert_eq!(format!("{:02x}", i as uint).as_slice()
|
||||
.from_hex()
|
||||
.unwrap()
|
||||
.as_slice(),
|
||||
&[i as u8]);
|
||||
assert_eq!(format!("{:02X}", i as uint).as_slice()
|
||||
.from_hex()
|
||||
.unwrap()
|
||||
.as_slice(),
|
||||
&[i as u8]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2483,7 +2483,7 @@ mod tests {
|
|||
|
||||
// We can't compare the strings directly because the object fields be
|
||||
// printed in a different order.
|
||||
assert_eq!(a.clone(), from_str(a.to_str()).unwrap());
|
||||
assert_eq!(a.clone(), from_str(a.to_str().as_slice()).unwrap());
|
||||
assert_eq!(a.clone(),
|
||||
from_str(a.to_pretty_str().as_slice()).unwrap());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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!("{}", "");
|
||||
|
|
|
@ -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
|
||||
|
@ -919,13 +925,6 @@ mod tests {
|
|||
use str::*;
|
||||
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")));
|
||||
|
@ -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);
|
||||
|
@ -1750,29 +1752,10 @@ mod tests {
|
|||
assert_eq!("abc".char_range_at_reverse(0).next, 0);
|
||||
}
|
||||
|
||||
#[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]
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -107,7 +107,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
|||
(Some('+'), operand) => {
|
||||
// Save a reference to the output
|
||||
read_write_operands.push((outputs.len(), out));
|
||||
Some(token::intern_and_get_ident("=" + operand))
|
||||
Some(token::intern_and_get_ident(format!(
|
||||
"={}",
|
||||
operand).as_slice()))
|
||||
}
|
||||
_ => {
|
||||
cx.span_err(span, "output operand constraint lacks '=' or '+'");
|
||||
|
|
|
@ -188,7 +188,9 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[Rc<NamedMatch>])
|
|||
if ret_val.contains_key(&bind_name) {
|
||||
let string = token::get_ident(bind_name);
|
||||
p_s.span_diagnostic
|
||||
.span_fatal(span, "duplicated bind name: " + string.get())
|
||||
.span_fatal(span,
|
||||
format!("duplicated bind name: {}",
|
||||
string.get()).as_slice())
|
||||
}
|
||||
ret_val.insert(bind_name, res[idx].clone());
|
||||
}
|
||||
|
|
|
@ -4259,12 +4259,14 @@ impl<'a> Parser<'a> {
|
|||
self.span_note(id_sp,
|
||||
format!("maybe move this module `{0}` \
|
||||
to its own directory via \
|
||||
`{0}/mod.rs`", this_module));
|
||||
`{0}/mod.rs`",
|
||||
this_module).as_slice());
|
||||
if default_exists || secondary_exists {
|
||||
self.span_note(id_sp,
|
||||
format!("... or maybe `use` the module \
|
||||
`{}` instead of possibly \
|
||||
redeclaring it", mod_name));
|
||||
redeclaring it",
|
||||
mod_name).as_slice());
|
||||
}
|
||||
self.abort_if_errors();
|
||||
}
|
||||
|
|
|
@ -2252,7 +2252,10 @@ impl<'a> State<'a> {
|
|||
}
|
||||
ast::LitFloat(ref f, t) => {
|
||||
word(&mut self.s,
|
||||
f.get() + ast_util::float_ty_to_str(t).as_slice())
|
||||
format!(
|
||||
"{}{}",
|
||||
f.get(),
|
||||
ast_util::float_ty_to_str(t).as_slice()).as_slice())
|
||||
}
|
||||
ast::LitFloatUnsuffixed(ref f) => word(&mut self.s, f.get()),
|
||||
ast::LitNil => word(&mut self.s, "()"),
|
||||
|
|
|
@ -623,7 +623,9 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
fail_out.push_str(format!("---- {} stdout ----\n\t",
|
||||
f.name.as_slice()).as_slice());
|
||||
let output = str::from_utf8_lossy(stdout.as_slice());
|
||||
fail_out.push_str(output.as_slice().replace("\n", "\n\t"));
|
||||
fail_out.push_str(output.as_slice()
|
||||
.replace("\n", "\n\t")
|
||||
.as_slice());
|
||||
fail_out.push_str("\n");
|
||||
}
|
||||
}
|
||||
|
@ -776,7 +778,9 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn> ) -> io::IoR
|
|||
let MetricMap(mm) = mm;
|
||||
for (k,v) in mm.iter() {
|
||||
st.metrics
|
||||
.insert_metric(tname + "." + k.as_slice(),
|
||||
.insert_metric(format!("{}.{}",
|
||||
tname,
|
||||
k).as_slice(),
|
||||
v.value,
|
||||
v.noise);
|
||||
}
|
||||
|
|
|
@ -1432,13 +1432,6 @@ mod tests {
|
|||
assert_eq!(local.strftime("%z"), "-0800".to_strbuf());
|
||||
assert_eq!(local.strftime("%%"), "%".to_strbuf());
|
||||
|
||||
// FIXME (#2350): We should probably standardize on the timezone
|
||||
// abbreviation.
|
||||
let rfc822 = local.rfc822();
|
||||
let prefix = "Fri, 13 Feb 2009 15:31:30 ".to_strbuf();
|
||||
assert!(rfc822 == format_strbuf!("{}PST", prefix) ||
|
||||
rfc822 == format_strbuf!("{}Pacific Standard Time", prefix));
|
||||
|
||||
assert_eq!(local.ctime(), "Fri Feb 13 15:31:30 2009".to_strbuf());
|
||||
assert_eq!(local.rfc822z(), "Fri, 13 Feb 2009 15:31:30 -0800".to_strbuf());
|
||||
assert_eq!(local.rfc3339(), "2009-02-13T15:31:30-08:00".to_strbuf());
|
||||
|
|
|
@ -426,14 +426,16 @@ impl Uuid {
|
|||
|
||||
// At this point, we know we have a valid hex string, without hyphens
|
||||
assert!(vs.len() == 32);
|
||||
assert!(vs.chars().all(|c| c.is_digit_radix(16)));
|
||||
assert!(vs.as_slice().chars().all(|c| c.is_digit_radix(16)));
|
||||
|
||||
// Allocate output UUID buffer
|
||||
let mut ub = [0u8, ..16];
|
||||
|
||||
// Extract each hex digit from the string
|
||||
for i in range(0u, 16u) {
|
||||
ub[i] = FromStrRadix::from_str_radix(vs.slice(i*2, (i+1)*2), 16).unwrap();
|
||||
ub[i] = FromStrRadix::from_str_radix(vs.as_slice()
|
||||
.slice(i*2, (i+1)*2),
|
||||
16).unwrap();
|
||||
}
|
||||
|
||||
Ok(Uuid::from_bytes(ub).unwrap())
|
||||
|
@ -624,7 +626,7 @@ mod test {
|
|||
// Round-trip
|
||||
let uuid_orig = Uuid::new_v4();
|
||||
let orig_str = uuid_orig.to_str();
|
||||
let uuid_out = Uuid::parse_string(orig_str).unwrap();
|
||||
let uuid_out = Uuid::parse_string(orig_str.as_slice()).unwrap();
|
||||
assert!(uuid_orig == uuid_out);
|
||||
|
||||
// Test error reporting
|
||||
|
@ -706,7 +708,7 @@ mod test {
|
|||
assert!(uuid_hs == uuid);
|
||||
|
||||
let ss = uuid.to_str();
|
||||
let uuid_ss = Uuid::parse_string(ss).unwrap();
|
||||
let uuid_ss = Uuid::parse_string(ss.as_slice()).unwrap();
|
||||
assert!(uuid_ss == uuid);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ fn main() {
|
|||
let args = args.as_slice();
|
||||
let n_keys = {
|
||||
if args.len() == 2 {
|
||||
from_str::<uint>(args[1]).unwrap()
|
||||
from_str::<uint>(args[1].as_slice()).unwrap()
|
||||
} else {
|
||||
1000000
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ fn main() {
|
|||
let args = args.as_slice();
|
||||
let num_keys = {
|
||||
if args.len() == 2 {
|
||||
from_str::<uint>(args[1]).unwrap()
|
||||
from_str::<uint>(args[1].as_slice()).unwrap()
|
||||
} else {
|
||||
100 // woefully inadequate for any real measurement
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ fn main() {
|
|||
args.move_iter().collect()
|
||||
};
|
||||
|
||||
let n = from_str::<uint>(*args.get(1)).unwrap();
|
||||
let n = from_str::<uint>(args.get(1).as_slice()).unwrap();
|
||||
|
||||
for i in range(0u, n) {
|
||||
let x = i.to_str();
|
||||
|
|
|
@ -70,8 +70,8 @@ fn main() {
|
|||
args.clone().move_iter().collect()
|
||||
};
|
||||
|
||||
let num_tasks = from_str::<uint>(*args.get(1)).unwrap();
|
||||
let msg_per_task = from_str::<uint>(*args.get(2)).unwrap();
|
||||
let num_tasks = from_str::<uint>(args.get(1).as_slice()).unwrap();
|
||||
let msg_per_task = from_str::<uint>(args.get(2).as_slice()).unwrap();
|
||||
|
||||
let (mut num_chan, num_port) = init();
|
||||
|
||||
|
|
|
@ -71,8 +71,8 @@ fn main() {
|
|||
args.clone().move_iter().collect()
|
||||
};
|
||||
|
||||
let num_tasks = from_str::<uint>(*args.get(1)).unwrap();
|
||||
let msg_per_task = from_str::<uint>(*args.get(2)).unwrap();
|
||||
let num_tasks = from_str::<uint>(args.get(1).as_slice()).unwrap();
|
||||
let msg_per_task = from_str::<uint>(args.get(2).as_slice()).unwrap();
|
||||
|
||||
let (mut num_chan, num_port) = init();
|
||||
|
||||
|
|
|
@ -63,13 +63,13 @@ fn main() {
|
|||
let args = os::args();
|
||||
let args = args.as_slice();
|
||||
let n = if args.len() == 3 {
|
||||
from_str::<uint>(args[1]).unwrap()
|
||||
from_str::<uint>(args[1].as_slice()).unwrap()
|
||||
} else {
|
||||
10000
|
||||
};
|
||||
|
||||
let m = if args.len() == 3 {
|
||||
from_str::<uint>(args[2]).unwrap()
|
||||
from_str::<uint>(args[2].as_slice()).unwrap()
|
||||
} else {
|
||||
4
|
||||
};
|
||||
|
|
|
@ -33,7 +33,7 @@ fn main() {
|
|||
let args = os::args();
|
||||
let args = args.as_slice();
|
||||
let n = if args.len() == 2 {
|
||||
from_str::<uint>(args[1]).unwrap()
|
||||
from_str::<uint>(args[1].as_slice()).unwrap()
|
||||
} else {
|
||||
10
|
||||
};
|
||||
|
|
|
@ -30,7 +30,7 @@ fn main() {
|
|||
let args = os::args();
|
||||
let args = args.as_slice();
|
||||
let n = if args.len() == 2 {
|
||||
from_str::<uint>(args[1]).unwrap()
|
||||
from_str::<uint>(args[1].as_slice()).unwrap()
|
||||
} else {
|
||||
100000
|
||||
};
|
||||
|
|
|
@ -31,6 +31,6 @@ fn main() {
|
|||
} else {
|
||||
args.move_iter().collect()
|
||||
};
|
||||
let n = from_str::<int>(*args.get(1)).unwrap();
|
||||
let n = from_str::<int>(args.get(1).as_slice()).unwrap();
|
||||
println!("Ack(3,{}): {}\n", n, ack(3, n));
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ fn main() {
|
|||
} else if args.len() <= 1u {
|
||||
8
|
||||
} else {
|
||||
from_str(args[1]).unwrap()
|
||||
from_str(args[1].as_slice()).unwrap()
|
||||
};
|
||||
let min_depth = 4;
|
||||
let max_depth = if min_depth + 2 > n {min_depth + 2} else {n};
|
||||
|
|
|
@ -48,7 +48,7 @@ fn show_color_list(set: Vec<Color>) -> StrBuf {
|
|||
let mut out = StrBuf::new();
|
||||
for col in set.iter() {
|
||||
out.push_char(' ');
|
||||
out.push_str(col.to_str());
|
||||
out.push_str(col.to_str().as_slice());
|
||||
}
|
||||
out
|
||||
}
|
||||
|
@ -198,7 +198,10 @@ fn main() {
|
|||
let nn = if std::os::getenv("RUST_BENCH").is_some() {
|
||||
200000
|
||||
} else {
|
||||
std::os::args().as_slice().get(1).and_then(|arg| from_str(*arg)).unwrap_or(600)
|
||||
std::os::args().as_slice()
|
||||
.get(1)
|
||||
.and_then(|arg| from_str(arg.as_slice()))
|
||||
.unwrap_or(600)
|
||||
};
|
||||
|
||||
print_complements();
|
||||
|
|
|
@ -53,7 +53,10 @@ fn fannkuch(n: uint, i: uint) -> (int, int) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let n = std::os::args().as_slice().get(1).and_then(|arg| from_str(*arg)).unwrap_or(2u);
|
||||
let n = std::os::args().as_slice()
|
||||
.get(1)
|
||||
.and_then(|arg| from_str(arg.as_slice()))
|
||||
.unwrap_or(2u);
|
||||
|
||||
let (tx, rx) = channel();
|
||||
for i in range(0, n) {
|
||||
|
|
|
@ -179,7 +179,7 @@ fn main() {
|
|||
let args = os::args();
|
||||
let args = args.as_slice();
|
||||
let n = if args.len() > 1 {
|
||||
from_str::<uint>(args[1]).unwrap()
|
||||
from_str::<uint>(args[1].as_slice()).unwrap()
|
||||
} else {
|
||||
5
|
||||
};
|
||||
|
|
|
@ -80,7 +80,7 @@ fn run<W: Writer>(writer: &mut W) {
|
|||
} else if args.len() <= 1u {
|
||||
1000
|
||||
} else {
|
||||
from_str(args[1]).unwrap()
|
||||
from_str(args[1].as_slice()).unwrap()
|
||||
};
|
||||
|
||||
let rng = &mut MyRandom::new();
|
||||
|
|
|
@ -27,6 +27,6 @@ fn main() {
|
|||
} else {
|
||||
args.move_iter().collect()
|
||||
};
|
||||
let n = from_str::<int>(*args.get(1)).unwrap();
|
||||
let n = from_str::<int>(args.get(1).as_slice()).unwrap();
|
||||
println!("{}\n", fib(n));
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> StrBuf {
|
|||
k.as_slice()
|
||||
.to_ascii()
|
||||
.to_upper()
|
||||
.into_str(), v));
|
||||
.into_str(), v).as_slice());
|
||||
}
|
||||
|
||||
return buffer
|
||||
|
@ -179,15 +179,15 @@ fn main() {
|
|||
let mut proc_mode = false;
|
||||
|
||||
for line in rdr.lines() {
|
||||
let line = line.unwrap().trim().to_owned();
|
||||
let line = line.unwrap().as_slice().trim().to_owned();
|
||||
|
||||
if line.len() == 0u { continue; }
|
||||
|
||||
match (line[0] as char, proc_mode) {
|
||||
match (line.as_slice()[0] as char, proc_mode) {
|
||||
|
||||
// start processing if this is the one
|
||||
('>', false) => {
|
||||
match line.slice_from(1).find_str("THREE") {
|
||||
match line.as_slice().slice_from(1).find_str("THREE") {
|
||||
option::Some(_) => { proc_mode = true; }
|
||||
option::None => { }
|
||||
}
|
||||
|
|
|
@ -252,9 +252,9 @@ fn print_occurrences(frequencies: &mut Table, occurrence: &'static str) {
|
|||
fn get_sequence<R: Buffer>(r: &mut R, key: &str) -> Vec<u8> {
|
||||
let mut res = Vec::new();
|
||||
for l in r.lines().map(|l| l.ok().unwrap())
|
||||
.skip_while(|l| key != l.slice_to(key.len())).skip(1)
|
||||
.skip_while(|l| key != l.as_slice().slice_to(key.len())).skip(1)
|
||||
{
|
||||
res.push_all(l.trim().as_bytes());
|
||||
res.push_all(l.as_slice().trim().as_bytes());
|
||||
}
|
||||
for b in res.mut_iter() {
|
||||
*b = b.to_ascii().to_upper().to_byte();
|
||||
|
|
|
@ -169,7 +169,7 @@ fn main() {
|
|||
which interferes with the test runner.");
|
||||
mandelbrot(1000, io::util::NullWriter)
|
||||
} else {
|
||||
mandelbrot(from_str(args[1]).unwrap(), io::stdout())
|
||||
mandelbrot(from_str(args[1].as_slice()).unwrap(), io::stdout())
|
||||
};
|
||||
res.unwrap();
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ fn main() {
|
|||
5000000
|
||||
} else {
|
||||
std::os::args().as_slice().get(1)
|
||||
.and_then(|arg| from_str(*arg))
|
||||
.and_then(|arg| from_str(arg.as_slice()))
|
||||
.unwrap_or(1000)
|
||||
};
|
||||
let mut bodies = BODIES;
|
||||
|
|
|
@ -92,7 +92,7 @@ fn main() {
|
|||
let n = if args.len() < 2 {
|
||||
512
|
||||
} else {
|
||||
FromStr::from_str(args[1]).unwrap()
|
||||
FromStr::from_str(args[1].as_slice()).unwrap()
|
||||
};
|
||||
pidigits(n);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ fn main() {
|
|||
} else {
|
||||
box io::stdin() as Box<io::Reader>
|
||||
};
|
||||
let mut seq = StrBuf::from_str(rdr.read_to_str().unwrap());
|
||||
let mut seq = rdr.read_to_str().unwrap();
|
||||
let ilen = seq.len();
|
||||
|
||||
seq = regex!(">[^\n]*\n|\n").replace_all(seq.as_slice(), NoExpand(""));
|
||||
|
|
|
@ -100,7 +100,7 @@ fn main() {
|
|||
} else if args.len() < 2 {
|
||||
2000
|
||||
} else {
|
||||
FromStr::from_str(args[1]).unwrap()
|
||||
FromStr::from_str(args[1].as_slice()).unwrap()
|
||||
};
|
||||
let u = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
|
||||
let v = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
|
||||
|
|
|
@ -39,9 +39,11 @@ fn main() {
|
|||
let token = if std::os::getenv("RUST_BENCH").is_some() {
|
||||
2000000
|
||||
} else {
|
||||
args.get(1).and_then(|arg| from_str(*arg)).unwrap_or(1000)
|
||||
args.get(1).and_then(|arg| from_str(arg.as_slice())).unwrap_or(1000)
|
||||
};
|
||||
let n_tasks = args.get(2).and_then(|arg| from_str(*arg)).unwrap_or(503);
|
||||
let n_tasks = args.get(2)
|
||||
.and_then(|arg| from_str(arg.as_slice()))
|
||||
.unwrap_or(503);
|
||||
|
||||
start(n_tasks, token);
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ fn main() {
|
|||
} else {
|
||||
args.move_iter().collect()
|
||||
};
|
||||
let max = from_str::<uint>(*args.get(1)).unwrap();
|
||||
let rep = from_str::<uint>(*args.get(2)).unwrap();
|
||||
let max = from_str::<uint>(args.get(1).as_slice()).unwrap();
|
||||
let rep = from_str::<uint>(args.get(2).as_slice()).unwrap();
|
||||
|
||||
let mut checkf = 0.0;
|
||||
let mut appendf = 0.0;
|
||||
|
|
|
@ -72,7 +72,10 @@ impl Sudoku {
|
|||
let mut g = Vec::from_fn(10u, { |_i| vec!(0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8) });
|
||||
for line in reader.lines() {
|
||||
let line = line.unwrap();
|
||||
let comps: Vec<&str> = line.trim().split(',').collect();
|
||||
let comps: Vec<&str> = line.as_slice()
|
||||
.trim()
|
||||
.split(',')
|
||||
.collect();
|
||||
|
||||
if comps.len() == 3u {
|
||||
let row = from_str::<uint>(*comps.get(0)).unwrap() as u8;
|
||||
|
|
|
@ -49,7 +49,7 @@ fn main() {
|
|||
};
|
||||
|
||||
let (tx, rx) = channel();
|
||||
child_generation(from_str::<uint>(*args.get(1)).unwrap(), tx);
|
||||
child_generation(from_str::<uint>(args.get(1).as_slice()).unwrap(), tx);
|
||||
if rx.recv_opt().is_err() {
|
||||
fail!("it happened when we slumbered");
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ fn main() {
|
|||
} else {
|
||||
args.move_iter().collect()
|
||||
};
|
||||
let n = from_str::<uint>(*args.get(1)).unwrap();
|
||||
let n = from_str::<uint>(args.get(1).as_slice()).unwrap();
|
||||
let mut i = 0u;
|
||||
while i < n { task::spawn(proc() f(n) ); i += 1u; }
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ fn call_bare(f: fn(&str)) {
|
|||
|
||||
fn main() {
|
||||
let string = "world!";
|
||||
let f: |&str| = |s| println!("{}", s + string);
|
||||
let f: |&str| = |s| println!("{}{}", s, string);
|
||||
call_bare(f) //~ ERROR mismatched types
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,5 @@ fn main() {
|
|||
|
||||
box 2; //~ ERROR type uses owned
|
||||
fn g(_: Box<Clone>) {} //~ ERROR type uses owned
|
||||
"".to_owned(); //~ ERROR type uses owned
|
||||
proc() {}; //~ ERROR type uses owned
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ mod argparse {
|
|||
}
|
||||
|
||||
fn main () {
|
||||
let f : argparse::Flag = argparse::flag("flag".to_owned(), "My flag".to_owned());
|
||||
let updated_flag = f.set_desc("My new flag".to_owned());
|
||||
assert_eq!(updated_flag.desc, "My new flag");
|
||||
let f : argparse::Flag = argparse::flag("flag", "My flag");
|
||||
let updated_flag = f.set_desc("My new flag");
|
||||
assert_eq!(updated_flag.desc.as_slice(), "My new flag");
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Trait<&'static str> for Struct {
|
|||
|
||||
fn main() {
|
||||
let person = "Fred".to_owned();
|
||||
let person: &str = person; //~ ERROR `person[..]` does not live long enough
|
||||
let person: &str = person.as_slice(); //~ ERROR `person` does not live long enough
|
||||
let s: Box<Trait<&'static str>> = box Struct { person: person };
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let mut s = "test".to_owned();
|
||||
s[0] = 3; //~ ERROR: not allowed
|
||||
s[0] += 3; //~ ERROR: not allowed
|
||||
{
|
||||
let _a = &mut s[0]; //~ ERROR: not allowed
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// pp-exact
|
||||
|
||||
// actually this doesn't quite look how I want it to, but I can't
|
||||
// get the prettyprinter to indent the long expr
|
||||
|
||||
fn main() {
|
||||
let x = Some(3);
|
||||
let _y =
|
||||
match x {
|
||||
Some(_) =>
|
||||
"some".to_owned() + "very" + "very" + "very" + "very" + "very" +
|
||||
"very" + "very" + "very" + "long" + "string",
|
||||
None => "none".to_owned()
|
||||
};
|
||||
}
|
|
@ -19,5 +19,4 @@ fn main() {
|
|||
let y = vec!(3);
|
||||
fail!("so long");
|
||||
x.push_all_move(y);
|
||||
"good".to_owned() + "bye".to_owned();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,11 @@ fn main() {
|
|||
// rustc is passed to us with --out-dir and -L etc., so we
|
||||
// can't exec it directly
|
||||
let result = Command::new("sh")
|
||||
.arg("-c").arg(rustc + " " + main_file.as_str().unwrap())
|
||||
.arg("-c")
|
||||
.arg(format!("{} {}",
|
||||
rustc,
|
||||
main_file.as_str()
|
||||
.unwrap()).as_slice())
|
||||
.output().unwrap();
|
||||
let err = str::from_utf8_lossy(result.error.as_slice());
|
||||
|
||||
|
|
|
@ -52,13 +52,17 @@ fn main() {
|
|||
// rustc is passed to us with --out-dir and -L etc., so we
|
||||
// can't exec it directly
|
||||
let result = Command::new("sh")
|
||||
.arg("-c").arg(rustc + " " + main_file.as_str().unwrap())
|
||||
.arg("-c")
|
||||
.arg(format!("{} {}",
|
||||
rustc,
|
||||
main_file.as_str()
|
||||
.unwrap()).as_slice())
|
||||
.output().unwrap();
|
||||
|
||||
let err = str::from_utf8_lossy(result.error.as_slice());
|
||||
|
||||
// the span should end the line (e.g no extra ~'s)
|
||||
let expected_span = "^" + "~".repeat(n - 1) + "\n";
|
||||
assert!(err.as_slice().contains(expected_span));
|
||||
let expected_span = format!("^{}\n", "~".repeat(n - 1));
|
||||
assert!(err.as_slice().contains(expected_span.as_slice()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ pub fn main() {
|
|||
(vec!(1)).as_slice().test_imm();
|
||||
(&[1]).test_imm();
|
||||
("test").test_imm();
|
||||
("test".to_owned()).test_imm();
|
||||
("test").test_imm();
|
||||
|
||||
// FIXME: Other types of mutable vecs don't currently exist
|
||||
|
|
|
@ -8,21 +8,15 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(unnecessary_allocation)]
|
||||
|
||||
// rustc --test match_borrowed_str.rs.rs && ./match_borrowed_str.rs
|
||||
|
||||
fn compare(x: &str, y: &str) -> bool
|
||||
{
|
||||
match x
|
||||
{
|
||||
fn compare(x: &str, y: &str) -> bool {
|
||||
match x {
|
||||
"foo" => y == "foo",
|
||||
_ => y == "bar",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
pub fn main() {
|
||||
assert!(compare("foo", "foo"));
|
||||
assert!(compare("foo".to_owned(), "foo".to_owned()));
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue