mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
auto merge of #14233 : pcwalton/rust/detildestr-morelibs, r=alexcrichton
r? @alexcrichton
This commit is contained in:
commit
5e10686aab
@ -56,10 +56,10 @@ impl fmt::Show for Mode {
|
||||
#[deriving(Clone)]
|
||||
pub struct Config {
|
||||
// The library paths required for running the compiler
|
||||
pub compile_lib_path: ~str,
|
||||
pub compile_lib_path: StrBuf,
|
||||
|
||||
// The library paths required for running compiled programs
|
||||
pub run_lib_path: ~str,
|
||||
pub run_lib_path: StrBuf,
|
||||
|
||||
// The rustc executable
|
||||
pub rustc_path: Path,
|
||||
@ -80,7 +80,7 @@ pub struct Config {
|
||||
pub aux_base: Path,
|
||||
|
||||
// The name of the stage being built (stage1, etc)
|
||||
pub stage_id: ~str,
|
||||
pub stage_id: StrBuf,
|
||||
|
||||
// The test mode, compile-fail, run-fail, run-pass
|
||||
pub mode: Mode,
|
||||
@ -110,37 +110,37 @@ pub struct Config {
|
||||
|
||||
// A command line to prefix program execution with,
|
||||
// for running under valgrind
|
||||
pub runtool: Option<~str>,
|
||||
pub runtool: Option<StrBuf>,
|
||||
|
||||
// Flags to pass to the compiler when building for the host
|
||||
pub host_rustcflags: Option<~str>,
|
||||
pub host_rustcflags: Option<StrBuf>,
|
||||
|
||||
// Flags to pass to the compiler when building for the target
|
||||
pub target_rustcflags: Option<~str>,
|
||||
pub target_rustcflags: Option<StrBuf>,
|
||||
|
||||
// Run tests using the JIT
|
||||
pub jit: bool,
|
||||
|
||||
// Target system to be tested
|
||||
pub target: ~str,
|
||||
pub target: StrBuf,
|
||||
|
||||
// Host triple for the compiler being invoked
|
||||
pub host: ~str,
|
||||
pub host: StrBuf,
|
||||
|
||||
// Path to the android tools
|
||||
pub android_cross_path: Path,
|
||||
|
||||
// Extra parameter to run adb on arm-linux-androideabi
|
||||
pub adb_path: ~str,
|
||||
pub adb_path: StrBuf,
|
||||
|
||||
// Extra parameter to run test sute on arm-linux-androideabi
|
||||
pub adb_test_dir: ~str,
|
||||
pub adb_test_dir: StrBuf,
|
||||
|
||||
// status whether android device available or not
|
||||
pub adb_device_status: bool,
|
||||
|
||||
// the path containing LLDB's Python module
|
||||
pub lldb_python_dir: Option<~str>,
|
||||
pub lldb_python_dir: Option<StrBuf>,
|
||||
|
||||
// Explain what's going on
|
||||
pub verbose: bool
|
||||
|
@ -48,12 +48,14 @@ fn start(argc: int, argv: **u8) -> int {
|
||||
|
||||
pub fn main() {
|
||||
let args = os::args();
|
||||
let config = parse_config(args.move_iter().collect());
|
||||
let config = parse_config(args.move_iter()
|
||||
.map(|x| x.to_strbuf())
|
||||
.collect());
|
||||
log_config(&config);
|
||||
run_tests(&config);
|
||||
}
|
||||
|
||||
pub fn parse_config(args: Vec<~str> ) -> Config {
|
||||
pub fn parse_config(args: Vec<StrBuf> ) -> Config {
|
||||
|
||||
let groups : Vec<getopts::OptGroup> =
|
||||
vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
|
||||
@ -91,7 +93,7 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
|
||||
assert!(!args.is_empty());
|
||||
let argv0 = (*args.get(0)).clone();
|
||||
let args_ = args.tail();
|
||||
if *args.get(1) == "-h".to_owned() || *args.get(1) == "--help".to_owned() {
|
||||
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
|
||||
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
|
||||
println!("{}", getopts::usage(message, groups.as_slice()));
|
||||
println!("");
|
||||
@ -99,7 +101,7 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
|
||||
}
|
||||
|
||||
let matches =
|
||||
&match getopts::getopts(args_, groups.as_slice()) {
|
||||
&match getopts::getopts(args_.as_slice(), groups.as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => fail!("{}", f.to_err_msg())
|
||||
};
|
||||
@ -129,16 +131,20 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
|
||||
};
|
||||
|
||||
Config {
|
||||
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
|
||||
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
|
||||
compile_lib_path: matches.opt_str("compile-lib-path")
|
||||
.unwrap()
|
||||
.to_strbuf(),
|
||||
run_lib_path: matches.opt_str("run-lib-path").unwrap().to_strbuf(),
|
||||
rustc_path: opt_path(matches, "rustc-path"),
|
||||
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
|
||||
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
|
||||
src_base: opt_path(matches, "src-base"),
|
||||
build_base: opt_path(matches, "build-base"),
|
||||
aux_base: opt_path(matches, "aux-base"),
|
||||
stage_id: matches.opt_str("stage-id").unwrap(),
|
||||
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
|
||||
stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(),
|
||||
mode: FromStr::from_str(matches.opt_str("mode")
|
||||
.unwrap()
|
||||
.as_slice()).expect("invalid mode"),
|
||||
run_ignored: matches.opt_present("ignored"),
|
||||
filter: filter,
|
||||
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
|
||||
@ -146,22 +152,32 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
|
||||
ratchet_metrics:
|
||||
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
|
||||
ratchet_noise_percent:
|
||||
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
|
||||
runtool: matches.opt_str("runtool"),
|
||||
host_rustcflags: matches.opt_str("host-rustcflags"),
|
||||
target_rustcflags: matches.opt_str("target-rustcflags"),
|
||||
matches.opt_str("ratchet-noise-percent")
|
||||
.and_then(|s| from_str::<f64>(s.as_slice())),
|
||||
runtool: matches.opt_str("runtool").map(|x| x.to_strbuf()),
|
||||
host_rustcflags: matches.opt_str("host-rustcflags")
|
||||
.map(|x| x.to_strbuf()),
|
||||
target_rustcflags: matches.opt_str("target-rustcflags")
|
||||
.map(|x| x.to_strbuf()),
|
||||
jit: matches.opt_present("jit"),
|
||||
target: opt_str2(matches.opt_str("target")).to_str(),
|
||||
host: opt_str2(matches.opt_str("host")).to_str(),
|
||||
target: opt_str2(matches.opt_str("target").map(|x| x.to_strbuf())),
|
||||
host: opt_str2(matches.opt_str("host").map(|x| x.to_strbuf())),
|
||||
android_cross_path: opt_path(matches, "android-cross-path"),
|
||||
adb_path: opt_str2(matches.opt_str("adb-path")).to_str(),
|
||||
adb_test_dir:
|
||||
opt_str2(matches.opt_str("adb-test-dir")).to_str(),
|
||||
adb_path: opt_str2(matches.opt_str("adb-path")
|
||||
.map(|x| x.to_strbuf())),
|
||||
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")
|
||||
.map(|x| x.to_strbuf())),
|
||||
adb_device_status:
|
||||
"arm-linux-androideabi" == opt_str2(matches.opt_str("target")) &&
|
||||
"(none)" != opt_str2(matches.opt_str("adb-test-dir")) &&
|
||||
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
|
||||
lldb_python_dir: matches.opt_str("lldb-python-dir"),
|
||||
"arm-linux-androideabi" ==
|
||||
opt_str2(matches.opt_str("target")
|
||||
.map(|x| x.to_strbuf())).as_slice() &&
|
||||
"(none)" !=
|
||||
opt_str2(matches.opt_str("adb-test-dir")
|
||||
.map(|x| x.to_strbuf())).as_slice() &&
|
||||
!opt_str2(matches.opt_str("adb-test-dir")
|
||||
.map(|x| x.to_strbuf())).is_empty(),
|
||||
lldb_python_dir: matches.opt_str("lldb-python-dir")
|
||||
.map(|x| x.to_strbuf()),
|
||||
test_shard: test::opt_shard(matches.opt_str("test-shard")
|
||||
.map(|x| x.to_strbuf())),
|
||||
verbose: matches.opt_present("verbose")
|
||||
@ -170,50 +186,59 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
|
||||
|
||||
pub fn log_config(config: &Config) {
|
||||
let c = config;
|
||||
logv(c, format!("configuration:"));
|
||||
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
|
||||
logv(c, format!("run_lib_path: {}", config.run_lib_path));
|
||||
logv(c, format!("rustc_path: {}", config.rustc_path.display()));
|
||||
logv(c, format!("src_base: {}", config.src_base.display()));
|
||||
logv(c, format!("build_base: {}", config.build_base.display()));
|
||||
logv(c, format!("stage_id: {}", config.stage_id));
|
||||
logv(c, format!("mode: {}", config.mode));
|
||||
logv(c, format!("run_ignored: {}", config.run_ignored));
|
||||
logv(c, format!("filter: {}", opt_str(&config.filter.as_ref().map(|re| re.to_str()))));
|
||||
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
|
||||
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
|
||||
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
|
||||
logv(c, format!("jit: {}", config.jit));
|
||||
logv(c, format!("target: {}", config.target));
|
||||
logv(c, format!("host: {}", config.host));
|
||||
logv(c, format!("android-cross-path: {}", config.android_cross_path.display()));
|
||||
logv(c, format!("adb_path: {}", config.adb_path));
|
||||
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
|
||||
logv(c, format!("adb_device_status: {}", config.adb_device_status));
|
||||
logv(c, format_strbuf!("configuration:"));
|
||||
logv(c, format_strbuf!("compile_lib_path: {}", config.compile_lib_path));
|
||||
logv(c, format_strbuf!("run_lib_path: {}", config.run_lib_path));
|
||||
logv(c, format_strbuf!("rustc_path: {}", config.rustc_path.display()));
|
||||
logv(c, format_strbuf!("src_base: {}", config.src_base.display()));
|
||||
logv(c, format_strbuf!("build_base: {}", config.build_base.display()));
|
||||
logv(c, format_strbuf!("stage_id: {}", config.stage_id));
|
||||
logv(c, format_strbuf!("mode: {}", config.mode));
|
||||
logv(c, format_strbuf!("run_ignored: {}", config.run_ignored));
|
||||
logv(c, format_strbuf!("filter: {}",
|
||||
opt_str(&config.filter
|
||||
.as_ref()
|
||||
.map(|re| {
|
||||
re.to_str().into_strbuf()
|
||||
}))));
|
||||
logv(c, format_strbuf!("runtool: {}", opt_str(&config.runtool)));
|
||||
logv(c, format_strbuf!("host-rustcflags: {}",
|
||||
opt_str(&config.host_rustcflags)));
|
||||
logv(c, format_strbuf!("target-rustcflags: {}",
|
||||
opt_str(&config.target_rustcflags)));
|
||||
logv(c, format_strbuf!("jit: {}", config.jit));
|
||||
logv(c, format_strbuf!("target: {}", config.target));
|
||||
logv(c, format_strbuf!("host: {}", config.host));
|
||||
logv(c, format_strbuf!("android-cross-path: {}",
|
||||
config.android_cross_path.display()));
|
||||
logv(c, format_strbuf!("adb_path: {}", config.adb_path));
|
||||
logv(c, format_strbuf!("adb_test_dir: {}", config.adb_test_dir));
|
||||
logv(c, format_strbuf!("adb_device_status: {}",
|
||||
config.adb_device_status));
|
||||
match config.test_shard {
|
||||
None => logv(c, "test_shard: (all)".to_owned()),
|
||||
Some((a,b)) => logv(c, format!("test_shard: {}.{}", a, b))
|
||||
None => logv(c, "test_shard: (all)".to_strbuf()),
|
||||
Some((a,b)) => logv(c, format_strbuf!("test_shard: {}.{}", a, b))
|
||||
}
|
||||
logv(c, format!("verbose: {}", config.verbose));
|
||||
logv(c, format!("\n"));
|
||||
logv(c, format_strbuf!("verbose: {}", config.verbose));
|
||||
logv(c, format_strbuf!("\n"));
|
||||
}
|
||||
|
||||
pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str {
|
||||
pub fn opt_str<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
|
||||
match *maybestr {
|
||||
None => "(none)",
|
||||
Some(ref s) => {
|
||||
let s: &'a str = *s;
|
||||
s
|
||||
}
|
||||
Some(ref s) => s.as_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_str2(maybestr: Option<~str>) -> ~str {
|
||||
match maybestr { None => "(none)".to_owned(), Some(s) => { s } }
|
||||
pub fn opt_str2(maybestr: Option<StrBuf>) -> StrBuf {
|
||||
match maybestr {
|
||||
None => "(none)".to_strbuf(),
|
||||
Some(s) => s,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_tests(config: &Config) {
|
||||
if config.target == "arm-linux-androideabi".to_owned() {
|
||||
if config.target.as_slice() == "arm-linux-androideabi" {
|
||||
match config.mode {
|
||||
DebugInfoGdb => {
|
||||
println!("arm-linux-androideabi debug-info \
|
||||
@ -321,11 +346,11 @@ pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
|
||||
pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
|
||||
|
||||
// Try to elide redundant long paths
|
||||
fn shorten(path: &Path) -> ~str {
|
||||
fn shorten(path: &Path) -> StrBuf {
|
||||
let filename = path.filename_str();
|
||||
let p = path.dir_path();
|
||||
let dir = p.filename_str();
|
||||
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
|
||||
format_strbuf!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
|
||||
}
|
||||
|
||||
test::DynTestName(format_strbuf!("[{}] {}",
|
||||
@ -336,14 +361,16 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
|
||||
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
|
||||
let config = (*config).clone();
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let testfile = testfile.as_str().unwrap().to_owned();
|
||||
test::DynTestFn(proc() { runtest::run(config, testfile) })
|
||||
let testfile = testfile.as_str().unwrap().to_strbuf();
|
||||
test::DynTestFn(proc() {
|
||||
runtest::run(config, testfile)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
|
||||
let config = (*config).clone();
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let testfile = testfile.as_str().unwrap().to_owned();
|
||||
let testfile = testfile.as_str().unwrap().to_strbuf();
|
||||
test::DynMetricFn(proc(mm) {
|
||||
runtest::run_metrics(config, testfile, mm)
|
||||
})
|
||||
|
@ -12,8 +12,8 @@ use std::io::{BufferedReader, File};
|
||||
|
||||
pub struct ExpectedError {
|
||||
pub line: uint,
|
||||
pub kind: ~str,
|
||||
pub msg: ~str,
|
||||
pub kind: StrBuf,
|
||||
pub msg: StrBuf,
|
||||
}
|
||||
|
||||
// Load any test directives embedded in the file
|
||||
@ -23,17 +23,18 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
|
||||
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
|
||||
let mut line_num = 1u;
|
||||
for ln in rdr.lines() {
|
||||
error_patterns.push_all_move(parse_expected(line_num, ln.unwrap()));
|
||||
error_patterns.push_all_move(parse_expected(line_num,
|
||||
ln.unwrap().to_strbuf()));
|
||||
line_num += 1u;
|
||||
}
|
||||
return error_patterns;
|
||||
}
|
||||
|
||||
fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
|
||||
let line = line.trim();
|
||||
let error_tag = "//~".to_owned();
|
||||
fn parse_expected(line_num: uint, line: StrBuf) -> Vec<ExpectedError> {
|
||||
let line = line.as_slice().trim().to_strbuf();
|
||||
let error_tag = "//~".to_strbuf();
|
||||
let mut idx;
|
||||
match line.find_str(error_tag) {
|
||||
match line.as_slice().find_str(error_tag.as_slice()) {
|
||||
None => return Vec::new(),
|
||||
Some(nn) => { idx = (nn as uint) + error_tag.len(); }
|
||||
}
|
||||
@ -42,25 +43,34 @@ fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
|
||||
// three lines above current line:
|
||||
let mut adjust_line = 0u;
|
||||
let len = line.len();
|
||||
while idx < len && line[idx] == ('^' as u8) {
|
||||
while idx < len && line.as_slice()[idx] == ('^' as u8) {
|
||||
adjust_line += 1u;
|
||||
idx += 1u;
|
||||
}
|
||||
|
||||
// Extract kind:
|
||||
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||
while idx < len && line.as_slice()[idx] == (' ' as u8) {
|
||||
idx += 1u;
|
||||
}
|
||||
let start_kind = idx;
|
||||
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
|
||||
while idx < len && line.as_slice()[idx] != (' ' as u8) {
|
||||
idx += 1u;
|
||||
}
|
||||
|
||||
let kind = line.slice(start_kind, idx);
|
||||
let kind = kind.to_ascii().to_lower().into_str();
|
||||
let kind = line.as_slice().slice(start_kind, idx);
|
||||
let kind = kind.to_ascii().to_lower().into_str().to_strbuf();
|
||||
|
||||
// Extract msg:
|
||||
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||
let msg = line.slice(idx, len).to_owned();
|
||||
while idx < len && line.as_slice()[idx] == (' ' as u8) {
|
||||
idx += 1u;
|
||||
}
|
||||
let msg = line.as_slice().slice(idx, len).to_strbuf();
|
||||
|
||||
debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
|
||||
|
||||
return vec!(ExpectedError{line: line_num - adjust_line, kind: kind,
|
||||
msg: msg});
|
||||
return vec!(ExpectedError{
|
||||
line: line_num - adjust_line,
|
||||
kind: kind,
|
||||
msg: msg,
|
||||
});
|
||||
}
|
||||
|
@ -14,20 +14,20 @@ use util;
|
||||
|
||||
pub struct TestProps {
|
||||
// Lines that should be expected, in order, on standard out
|
||||
pub error_patterns: Vec<~str> ,
|
||||
pub error_patterns: Vec<StrBuf> ,
|
||||
// Extra flags to pass to the compiler
|
||||
pub compile_flags: Option<~str>,
|
||||
pub compile_flags: Option<StrBuf>,
|
||||
// Extra flags to pass when the compiled code is run (such as --bench)
|
||||
pub run_flags: Option<~str>,
|
||||
pub run_flags: Option<StrBuf>,
|
||||
// If present, the name of a file that this test should match when
|
||||
// pretty-printed
|
||||
pub pp_exact: Option<Path>,
|
||||
// Modules from aux directory that should be compiled
|
||||
pub aux_builds: Vec<~str> ,
|
||||
pub aux_builds: Vec<StrBuf> ,
|
||||
// Environment settings to use during execution
|
||||
pub exec_env: Vec<(~str,~str)> ,
|
||||
pub exec_env: Vec<(StrBuf,StrBuf)> ,
|
||||
// Lines to check if they appear in the expected debugger output
|
||||
pub check_lines: Vec<~str> ,
|
||||
pub check_lines: Vec<StrBuf> ,
|
||||
// Flag to force a crate to be built with the host architecture
|
||||
pub force_host: bool,
|
||||
// Check stdout for error-pattern output as well as stderr
|
||||
@ -119,22 +119,30 @@ pub fn load_props(testfile: &Path) -> TestProps {
|
||||
}
|
||||
|
||||
pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
|
||||
fn ignore_target(config: &Config) -> ~str {
|
||||
"ignore-".to_owned() + util::get_os(config.target)
|
||||
fn ignore_target(config: &Config) -> StrBuf {
|
||||
format_strbuf!("ignore-{}", util::get_os(config.target.as_slice()))
|
||||
}
|
||||
fn ignore_stage(config: &Config) -> ~str {
|
||||
"ignore-".to_owned() + config.stage_id.split('-').next().unwrap()
|
||||
fn ignore_stage(config: &Config) -> StrBuf {
|
||||
format_strbuf!("ignore-{}",
|
||||
config.stage_id.as_slice().split('-').next().unwrap())
|
||||
}
|
||||
|
||||
let val = iter_header(testfile, |ln| {
|
||||
if parse_name_directive(ln, "ignore-test") { false }
|
||||
else if parse_name_directive(ln, ignore_target(config)) { false }
|
||||
else if parse_name_directive(ln, ignore_stage(config)) { false }
|
||||
else if config.mode == common::Pretty &&
|
||||
parse_name_directive(ln, "ignore-pretty") { false }
|
||||
else if config.target != config.host &&
|
||||
parse_name_directive(ln, "ignore-cross-compile") { false }
|
||||
else { true }
|
||||
if parse_name_directive(ln, "ignore-test") {
|
||||
false
|
||||
} else if parse_name_directive(ln, ignore_target(config).as_slice()) {
|
||||
false
|
||||
} else if parse_name_directive(ln, ignore_stage(config).as_slice()) {
|
||||
false
|
||||
} else if config.mode == common::Pretty &&
|
||||
parse_name_directive(ln, "ignore-pretty") {
|
||||
false
|
||||
} else if config.target != config.host &&
|
||||
parse_name_directive(ln, "ignore-cross-compile") {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
|
||||
!val
|
||||
@ -156,24 +164,24 @@ fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn parse_error_pattern(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, "error-pattern".to_owned())
|
||||
fn parse_error_pattern(line: &str) -> Option<StrBuf> {
|
||||
parse_name_value_directive(line, "error-pattern".to_strbuf())
|
||||
}
|
||||
|
||||
fn parse_aux_build(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, "aux-build".to_owned())
|
||||
fn parse_aux_build(line: &str) -> Option<StrBuf> {
|
||||
parse_name_value_directive(line, "aux-build".to_strbuf())
|
||||
}
|
||||
|
||||
fn parse_compile_flags(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, "compile-flags".to_owned())
|
||||
fn parse_compile_flags(line: &str) -> Option<StrBuf> {
|
||||
parse_name_value_directive(line, "compile-flags".to_strbuf())
|
||||
}
|
||||
|
||||
fn parse_run_flags(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, "run-flags".to_owned())
|
||||
fn parse_run_flags(line: &str) -> Option<StrBuf> {
|
||||
parse_name_value_directive(line, "run-flags".to_strbuf())
|
||||
}
|
||||
|
||||
fn parse_check_line(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, "check".to_owned())
|
||||
fn parse_check_line(line: &str) -> Option<StrBuf> {
|
||||
parse_name_value_directive(line, "check".to_strbuf())
|
||||
}
|
||||
|
||||
fn parse_force_host(line: &str) -> bool {
|
||||
@ -192,13 +200,16 @@ fn parse_no_pretty_expanded(line: &str) -> bool {
|
||||
parse_name_directive(line, "no-pretty-expanded")
|
||||
}
|
||||
|
||||
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
|
||||
parse_name_value_directive(line, "exec-env".to_owned()).map(|nv| {
|
||||
fn parse_exec_env(line: &str) -> Option<(StrBuf, StrBuf)> {
|
||||
parse_name_value_directive(line, "exec-env".to_strbuf()).map(|nv| {
|
||||
// nv is either FOO or FOO=BAR
|
||||
let mut strs: Vec<~str> = nv.splitn('=', 1).map(|s| s.to_owned()).collect();
|
||||
let mut strs: Vec<StrBuf> = nv.as_slice()
|
||||
.splitn('=', 1)
|
||||
.map(|s| s.to_strbuf())
|
||||
.collect();
|
||||
|
||||
match strs.len() {
|
||||
1u => (strs.pop().unwrap(), "".to_owned()),
|
||||
1u => (strs.pop().unwrap(), "".to_strbuf()),
|
||||
2u => {
|
||||
let end = strs.pop().unwrap();
|
||||
(strs.pop().unwrap(), end)
|
||||
@ -209,7 +220,7 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
|
||||
}
|
||||
|
||||
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
|
||||
match parse_name_value_directive(line, "pp-exact".to_owned()) {
|
||||
match parse_name_value_directive(line, "pp-exact".to_strbuf()) {
|
||||
Some(s) => Some(Path::new(s)),
|
||||
None => {
|
||||
if parse_name_directive(line, "pp-exact") {
|
||||
@ -225,14 +236,14 @@ fn parse_name_directive(line: &str, directive: &str) -> bool {
|
||||
line.contains(directive)
|
||||
}
|
||||
|
||||
pub fn parse_name_value_directive(line: &str,
|
||||
directive: ~str) -> Option<~str> {
|
||||
let keycolon = directive + ":";
|
||||
match line.find_str(keycolon) {
|
||||
pub fn parse_name_value_directive(line: &str, directive: StrBuf)
|
||||
-> Option<StrBuf> {
|
||||
let keycolon = format_strbuf!("{}:", directive);
|
||||
match line.find_str(keycolon.as_slice()) {
|
||||
Some(colon) => {
|
||||
let value = line.slice(colon + keycolon.len(),
|
||||
line.len()).to_owned();
|
||||
debug!("{}: {}", directive, value);
|
||||
line.len()).to_strbuf();
|
||||
debug!("{}: {}", directive, value);
|
||||
Some(value)
|
||||
}
|
||||
None => None
|
||||
|
@ -13,7 +13,7 @@ use std::str;
|
||||
use std::io::process::{ProcessExit, Command, Process, ProcessOutput};
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
fn target_env(lib_path: &str, prog: &str) -> Vec<(~str, ~str)> {
|
||||
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf, StrBuf)> {
|
||||
let env = os::env();
|
||||
|
||||
// Make sure we include the aux directory in the path
|
||||
@ -22,14 +22,14 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str, ~str)> {
|
||||
|
||||
let mut new_env: Vec<_> = env.move_iter().map(|(k, v)| {
|
||||
let new_v = if "PATH" == k {
|
||||
format!("{};{};{}", v, lib_path, aux_path)
|
||||
format_strbuf!("{};{};{}", v, lib_path, aux_path)
|
||||
} else {
|
||||
v
|
||||
v.to_strbuf()
|
||||
};
|
||||
(k, new_v)
|
||||
(k.to_strbuf(), new_v)
|
||||
}).collect();
|
||||
if prog.ends_with("rustc.exe") {
|
||||
new_env.push(("RUST_THREADS".to_owned(), "1".to_owned()));
|
||||
new_env.push(("RUST_THREADS".to_strbuf(), "1".to_strbuf()));
|
||||
}
|
||||
return new_env;
|
||||
}
|
||||
@ -37,11 +37,14 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str, ~str)> {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> {
|
||||
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf,StrBuf)> {
|
||||
// Make sure we include the aux directory in the path
|
||||
let aux_path = prog + ".libaux";
|
||||
|
||||
let mut env: Vec<(~str,~str)> = os::env().move_iter().collect();
|
||||
let mut env: Vec<(StrBuf,StrBuf)> =
|
||||
os::env().move_iter()
|
||||
.map(|(ref k, ref v)| (k.to_strbuf(), v.to_strbuf()))
|
||||
.collect();
|
||||
let var = if cfg!(target_os = "macos") {
|
||||
"DYLD_LIBRARY_PATH"
|
||||
} else {
|
||||
@ -49,23 +52,23 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> {
|
||||
};
|
||||
let prev = match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
|
||||
Some(i) => env.remove(i).unwrap().val1(),
|
||||
None => "".to_owned(),
|
||||
None => "".to_strbuf(),
|
||||
};
|
||||
env.push((var.to_owned(), if prev.is_empty() {
|
||||
lib_path + ":" + aux_path
|
||||
env.push((var.to_strbuf(), if prev.is_empty() {
|
||||
format_strbuf!("{}:{}", lib_path, aux_path)
|
||||
} else {
|
||||
lib_path + ":" + aux_path + ":" + prev
|
||||
format_strbuf!("{}:{}:{}", lib_path, aux_path, prev)
|
||||
}));
|
||||
return env;
|
||||
}
|
||||
|
||||
pub struct Result {pub status: ProcessExit, pub out: ~str, pub err: ~str}
|
||||
pub struct Result {pub status: ProcessExit, pub out: StrBuf, pub err: StrBuf}
|
||||
|
||||
pub fn run(lib_path: &str,
|
||||
prog: &str,
|
||||
args: &[~str],
|
||||
env: Vec<(~str, ~str)> ,
|
||||
input: Option<~str>) -> Option<Result> {
|
||||
args: &[StrBuf],
|
||||
env: Vec<(StrBuf, StrBuf)> ,
|
||||
input: Option<StrBuf>) -> Option<Result> {
|
||||
|
||||
let env = env.clone().append(target_env(lib_path, prog).as_slice());
|
||||
match Command::new(prog).args(args).env(env.as_slice()).spawn() {
|
||||
@ -78,8 +81,8 @@ pub fn run(lib_path: &str,
|
||||
|
||||
Some(Result {
|
||||
status: status,
|
||||
out: str::from_utf8(output.as_slice()).unwrap().to_owned(),
|
||||
err: str::from_utf8(error.as_slice()).unwrap().to_owned()
|
||||
out: str::from_utf8(output.as_slice()).unwrap().to_strbuf(),
|
||||
err: str::from_utf8(error.as_slice()).unwrap().to_strbuf()
|
||||
})
|
||||
},
|
||||
Err(..) => None
|
||||
@ -88,9 +91,9 @@ pub fn run(lib_path: &str,
|
||||
|
||||
pub fn run_background(lib_path: &str,
|
||||
prog: &str,
|
||||
args: &[~str],
|
||||
env: Vec<(~str, ~str)> ,
|
||||
input: Option<~str>) -> Option<Process> {
|
||||
args: &[StrBuf],
|
||||
env: Vec<(StrBuf, StrBuf)> ,
|
||||
input: Option<StrBuf>) -> Option<Process> {
|
||||
|
||||
let env = env.clone().append(target_env(lib_path, prog).as_slice());
|
||||
match Command::new(prog).args(args).env(env.as_slice()).spawn() {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -33,25 +33,25 @@ pub fn get_os(triple: &str) -> &'static str {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub fn make_new_path(path: &str) -> ~str {
|
||||
pub fn make_new_path(path: &str) -> StrBuf {
|
||||
|
||||
// Windows just uses PATH as the library search path, so we have to
|
||||
// maintain the current value while adding our own
|
||||
match getenv(lib_path_env_var()) {
|
||||
match getenv(lib_path_env_var().as_slice()) {
|
||||
Some(curr) => {
|
||||
format!("{}{}{}", path, path_div(), curr)
|
||||
format_strbuf!("{}{}{}", path, path_div(), curr)
|
||||
}
|
||||
None => path.to_str()
|
||||
None => path.to_str().to_strbuf()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub fn lib_path_env_var() -> ~str { "PATH".to_owned() }
|
||||
pub fn lib_path_env_var() -> StrBuf { "PATH".to_strbuf() }
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub fn path_div() -> ~str { ";".to_owned() }
|
||||
pub fn path_div() -> StrBuf { ";".to_strbuf() }
|
||||
|
||||
pub fn logv(config: &Config, s: ~str) {
|
||||
pub fn logv(config: &Config, s: StrBuf) {
|
||||
debug!("{}", s);
|
||||
if config.verbose { println!("{}", s); }
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ Use [`ToStr`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr.html
|
||||
|
||||
~~~
|
||||
let x: int = 42;
|
||||
let y: ~str = x.to_str();
|
||||
let y: StrBuf = x.to_str().to_strbuf();
|
||||
~~~
|
||||
|
||||
**String to int**
|
||||
@ -22,14 +22,14 @@ let y: int = x.unwrap();
|
||||
|
||||
**Int to string, in non-base-10**
|
||||
|
||||
Use the `format!` syntax extension.
|
||||
Use the `format_strbuf!` syntax extension.
|
||||
|
||||
~~~
|
||||
let x: int = 42;
|
||||
let y: ~str = format!("{:t}", x); // binary
|
||||
let y: ~str = format!("{:o}", x); // octal
|
||||
let y: ~str = format!("{:x}", x); // lowercase hexadecimal
|
||||
let y: ~str = format!("{:X}", x); // uppercase hexadecimal
|
||||
let y: StrBuf = format_strbuf!("{:t}", x); // binary
|
||||
let y: StrBuf = format_strbuf!("{:o}", x); // octal
|
||||
let y: StrBuf = format_strbuf!("{:x}", x); // lowercase hexadecimal
|
||||
let y: StrBuf = format_strbuf!("{:X}", x); // uppercase hexadecimal
|
||||
~~~
|
||||
|
||||
**String to int, in non-base-10**
|
||||
@ -55,13 +55,14 @@ let x: Option<&str> = str::from_utf8(bytes);
|
||||
let y: &str = x.unwrap();
|
||||
~~~
|
||||
|
||||
To return an Owned String (~str) use the str helper function [`from_utf8_owned`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html).
|
||||
To return an Owned String (StrBuf) use the str helper function [`from_utf8_owned`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html).
|
||||
|
||||
~~~
|
||||
use std::str;
|
||||
|
||||
let x: Result<~str,~[u8]> = str::from_utf8_owned(~[104u8,105u8]);
|
||||
let y: ~str = x.unwrap();
|
||||
let x: Result<StrBuf,~[u8]> =
|
||||
str::from_utf8_owned(~[104u8,105u8]).map(|x| x.to_strbuf());
|
||||
let y: StrBuf = x.unwrap();
|
||||
~~~
|
||||
|
||||
To return a [`MaybeOwned`](http://static.rust-lang.org/doc/master/std/str/enum.MaybeOwned.html) use the str helper function [`from_utf8_lossy`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html). This function also replaces non-valid utf-8 sequences with U+FFFD replacement character.
|
||||
@ -181,7 +182,7 @@ enum Closed {}
|
||||
Phantom types are useful for enforcing state at compile time. For example:
|
||||
|
||||
~~~
|
||||
struct Door<State>(~str);
|
||||
struct Door<State>(StrBuf);
|
||||
|
||||
struct Open;
|
||||
struct Closed;
|
||||
@ -194,13 +195,13 @@ fn open(Door(name): Door<Closed>) -> Door<Open> {
|
||||
Door::<Open>(name)
|
||||
}
|
||||
|
||||
let _ = close(Door::<Open>("front".to_owned()));
|
||||
let _ = close(Door::<Open>("front".to_strbuf()));
|
||||
~~~
|
||||
|
||||
Attempting to close a closed door is prevented statically:
|
||||
|
||||
~~~ {.ignore}
|
||||
let _ = close(Door::<Closed>("front".to_owned())); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
|
||||
let _ = close(Door::<Closed>("front".to_strbuf())); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
|
||||
~~~
|
||||
|
||||
# FFI (Foreign Function Interface)
|
||||
|
@ -85,7 +85,7 @@ To take as an argument a fragment of Rust code, write `$` followed by a name
|
||||
`foo`.)
|
||||
* `expr` (an expression. Examples: `2 + 2`; `if true then { 1 } else { 2 }`;
|
||||
`f(42)`.)
|
||||
* `ty` (a type. Examples: `int`, `~[(char, ~str)]`, `&T`.)
|
||||
* `ty` (a type. Examples: `int`, `~[(char, StrBuf)]`, `&T`.)
|
||||
* `pat` (a pattern, usually appearing in a `match` or on the left-hand side of
|
||||
a declaration. Examples: `Some(t)`; `(17, 'a')`; `_`.)
|
||||
* `block` (a sequence of actions. Example: `{ log(error, "hi"); return 12; }`)
|
||||
|
@ -463,11 +463,11 @@ Here is the function that implements the child task:
|
||||
~~~
|
||||
extern crate sync;
|
||||
# fn main() {
|
||||
fn stringifier(channel: &sync::DuplexStream<~str, uint>) {
|
||||
fn stringifier(channel: &sync::DuplexStream<StrBuf, uint>) {
|
||||
let mut value: uint;
|
||||
loop {
|
||||
value = channel.recv();
|
||||
channel.send(value.to_str());
|
||||
channel.send(value.to_str().to_strbuf());
|
||||
if value == 0 { break; }
|
||||
}
|
||||
}
|
||||
@ -488,11 +488,11 @@ Here is the code for the parent task:
|
||||
extern crate sync;
|
||||
# use std::task::spawn;
|
||||
# use sync::DuplexStream;
|
||||
# fn stringifier(channel: &sync::DuplexStream<~str, uint>) {
|
||||
# fn stringifier(channel: &sync::DuplexStream<StrBuf, uint>) {
|
||||
# let mut value: uint;
|
||||
# loop {
|
||||
# value = channel.recv();
|
||||
# channel.send(value.to_str());
|
||||
# channel.send(value.to_str().to_strbuf());
|
||||
# if value == 0u { break; }
|
||||
# }
|
||||
# }
|
||||
@ -505,13 +505,13 @@ spawn(proc() {
|
||||
});
|
||||
|
||||
from_child.send(22);
|
||||
assert!(from_child.recv() == "22".to_owned());
|
||||
assert!(from_child.recv().as_slice() == "22");
|
||||
|
||||
from_child.send(23);
|
||||
from_child.send(0);
|
||||
|
||||
assert!(from_child.recv() == "23".to_owned());
|
||||
assert!(from_child.recv() == "0".to_owned());
|
||||
assert!(from_child.recv().as_slice() == "23");
|
||||
assert!(from_child.recv().as_slice() == "0");
|
||||
|
||||
# }
|
||||
~~~
|
||||
|
@ -34,7 +34,7 @@ msgstr ""
|
||||
#, fuzzy
|
||||
#| msgid ""
|
||||
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
|
||||
msgid "~~~ let x: int = 42; let y: ~str = x.to_str(); ~~~"
|
||||
msgid "~~~ let x: int = 42; let y: StrBuf = x.to_str(); ~~~"
|
||||
msgstr ""
|
||||
"~~~~\n"
|
||||
"let x: f64 = 4.0;\n"
|
||||
@ -96,7 +96,7 @@ msgstr ""
|
||||
#, fuzzy
|
||||
#| msgid ""
|
||||
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
|
||||
msgid "let x: int = 42; let y: ~str = x.to_str_radix(16); ~~~"
|
||||
msgid "let x: int = 42; let y: StrBuf = x.to_str_radix(16); ~~~"
|
||||
msgstr ""
|
||||
"~~~~\n"
|
||||
"let x: f64 = 4.0;\n"
|
||||
|
@ -1641,7 +1641,7 @@ msgstr "## 最小限の例"
|
||||
msgid ""
|
||||
"~~~~\n"
|
||||
"trait Printable {\n"
|
||||
" fn to_string(&self) -> ~str;\n"
|
||||
" fn to_string(&self) -> StrBuf;\n"
|
||||
"}\n"
|
||||
msgstr ""
|
||||
"~~~~ {.ignore}\n"
|
||||
@ -1656,7 +1656,7 @@ msgstr ""
|
||||
#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
|
||||
msgid ""
|
||||
"impl Printable for int {\n"
|
||||
" fn to_string(&self) -> ~str { self.to_str() }\n"
|
||||
" fn to_string(&self) -> StrBuf { self.to_str() }\n"
|
||||
"}\n"
|
||||
msgstr ""
|
||||
"~~~~ {.ignore}\n"
|
||||
@ -1702,7 +1702,7 @@ msgstr "# クロージャ"
|
||||
msgid ""
|
||||
"~~~~\n"
|
||||
"trait Printable {\n"
|
||||
" fn make_string(&self) -> ~str;\n"
|
||||
" fn make_string(&self) -> StrBuf;\n"
|
||||
"}\n"
|
||||
msgstr ""
|
||||
"~~~~ {.ignore}\n"
|
||||
@ -1716,8 +1716,8 @@ msgstr ""
|
||||
#, fuzzy, no-wrap
|
||||
#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
|
||||
msgid ""
|
||||
"impl Printable for ~str {\n"
|
||||
" fn make_string(&self) -> ~str {\n"
|
||||
"impl Printable for StrBuf {\n"
|
||||
" fn make_string(&self) -> StrBuf {\n"
|
||||
" (*self).clone()\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
|
@ -3755,15 +3755,15 @@ msgstr ""
|
||||
#| msgid ""
|
||||
#| "Traits may be implemented for specific types with [impls]. An impl that "
|
||||
#| "implements a trait includes the name of the trait at the start of the "
|
||||
#| "definition, as in the following impls of `Printable` for `int` and `~str`."
|
||||
#| "definition, as in the following impls of `Printable` for `int` and `StrBuf`."
|
||||
msgid ""
|
||||
"Traits may be implemented for specific types with [impls]. An impl for a "
|
||||
"particular trait gives an implementation of the methods that trait "
|
||||
"provides. For instance, the following impls of `Printable` for `int` and "
|
||||
"`~str` give implementations of the `print` method."
|
||||
"`StrBuf` give implementations of the `print` method."
|
||||
msgstr ""
|
||||
"[impl][impls] により特定の型にトレイトを実装することができます。トレイトを実"
|
||||
"装する impl は、以下の `Printable` の `int` と `~str` に対する実装のように、"
|
||||
"装する impl は、以下の `Printable` の `int` と `StrBuf` に対する実装のように、"
|
||||
"定義の先頭にトレイトの名前を含みます。"
|
||||
|
||||
#. type: Plain text
|
||||
@ -3776,7 +3776,7 @@ msgstr "[impls]: #メソッド"
|
||||
#, fuzzy, no-wrap
|
||||
#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
|
||||
msgid ""
|
||||
"impl Printable for ~str {\n"
|
||||
"impl Printable for StrBuf {\n"
|
||||
" fn print(&self) { println!(\"{}\", *self) }\n"
|
||||
"}\n"
|
||||
msgstr ""
|
||||
|
@ -473,7 +473,7 @@ Two examples of paths with type arguments:
|
||||
# struct HashMap<K, V>;
|
||||
# fn f() {
|
||||
# fn id<T>(t: T) -> T { t }
|
||||
type T = HashMap<int,~str>; // Type arguments used in a type expression
|
||||
type T = HashMap<int,StrBuf>; // Type arguments used in a type expression
|
||||
let x = id::<int>(10); // Type arguments used in a call expression
|
||||
# }
|
||||
~~~~
|
||||
@ -1259,12 +1259,12 @@ Enumeration constructors can have either named or unnamed fields:
|
||||
|
||||
~~~~
|
||||
enum Animal {
|
||||
Dog (~str, f64),
|
||||
Cat { name: ~str, weight: f64 }
|
||||
Dog (StrBuf, f64),
|
||||
Cat { name: StrBuf, weight: f64 }
|
||||
}
|
||||
|
||||
let mut a: Animal = Dog("Cocoa".to_owned(), 37.2);
|
||||
a = Cat{ name: "Spotty".to_owned(), weight: 2.7 };
|
||||
let mut a: Animal = Dog("Cocoa".to_strbuf(), 37.2);
|
||||
a = Cat { name: "Spotty".to_strbuf(), weight: 2.7 };
|
||||
~~~~
|
||||
|
||||
In this example, `Cat` is a _struct-like enum variant_,
|
||||
@ -2081,7 +2081,7 @@ These are functions:
|
||||
* `str_eq`
|
||||
: Compare two strings (`&str`) for equality.
|
||||
* `uniq_str_eq`
|
||||
: Compare two owned strings (`~str`) for equality.
|
||||
: Compare two owned strings (`StrBuf`) for equality.
|
||||
* `strdup_uniq`
|
||||
: Return a new unique string
|
||||
containing a copy of the contents of a unique string.
|
||||
@ -3309,7 +3309,7 @@ A value of type `str` is a Unicode string,
|
||||
represented as a vector of 8-bit unsigned bytes holding a sequence of UTF-8 codepoints.
|
||||
Since `str` is of unknown size, it is not a _first class_ type,
|
||||
but can only be instantiated through a pointer type,
|
||||
such as `&str` or `~str`.
|
||||
such as `&str` or `StrBuf`.
|
||||
|
||||
### Tuple types
|
||||
|
||||
@ -3573,11 +3573,11 @@ An example of an object type:
|
||||
|
||||
~~~~
|
||||
trait Printable {
|
||||
fn to_string(&self) -> ~str;
|
||||
fn to_string(&self) -> StrBuf;
|
||||
}
|
||||
|
||||
impl Printable for int {
|
||||
fn to_string(&self) -> ~str { self.to_str() }
|
||||
fn to_string(&self) -> StrBuf { self.to_str().to_strbuf() }
|
||||
}
|
||||
|
||||
fn print(a: Box<Printable>) {
|
||||
@ -3618,17 +3618,17 @@ example, in:
|
||||
|
||||
~~~~
|
||||
trait Printable {
|
||||
fn make_string(&self) -> ~str;
|
||||
fn make_string(&self) -> StrBuf;
|
||||
}
|
||||
|
||||
impl Printable for ~str {
|
||||
fn make_string(&self) -> ~str {
|
||||
impl Printable for StrBuf {
|
||||
fn make_string(&self) -> StrBuf {
|
||||
(*self).clone()
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
|
||||
`self` refers to the value of type `~str` that is the receiver for a
|
||||
`self` refers to the value of type `StrBuf` that is the receiver for a
|
||||
call to the method `make_string`.
|
||||
|
||||
## Type kinds
|
||||
|
@ -26,7 +26,7 @@ comments":
|
||||
pub struct Widget {
|
||||
/// All widgets have a purpose (this is a doc comment, and will show up
|
||||
/// the field's documentation).
|
||||
purpose: ~str,
|
||||
purpose: StrBuf,
|
||||
/// Humans are not allowed to understand some widgets
|
||||
understandable: bool
|
||||
}
|
||||
|
@ -2213,7 +2213,7 @@ don't provide any methods.
|
||||
Traits may be implemented for specific types with [impls]. An impl for
|
||||
a particular trait gives an implementation of the methods that
|
||||
trait provides. For instance, the following impls of
|
||||
`Printable` for `int` and `~str` give implementations of the `print`
|
||||
`Printable` for `int` and `StrBuf` give implementations of the `print`
|
||||
method.
|
||||
|
||||
[impls]: #methods
|
||||
@ -2224,12 +2224,12 @@ impl Printable for int {
|
||||
fn print(&self) { println!("{:?}", *self) }
|
||||
}
|
||||
|
||||
impl Printable for ~str {
|
||||
impl Printable for StrBuf {
|
||||
fn print(&self) { println!("{}", *self) }
|
||||
}
|
||||
|
||||
# 1.print();
|
||||
# ("foo".to_owned()).print();
|
||||
# ("foo".to_strbuf()).print();
|
||||
~~~~
|
||||
|
||||
Methods defined in an impl for a trait may be called just like
|
||||
@ -2270,7 +2270,7 @@ trait Printable {
|
||||
|
||||
impl Printable for int {}
|
||||
|
||||
impl Printable for ~str {
|
||||
impl Printable for StrBuf {
|
||||
fn print(&self) { println!("{}", *self) }
|
||||
}
|
||||
|
||||
@ -2279,7 +2279,7 @@ impl Printable for bool {}
|
||||
impl Printable for f32 {}
|
||||
|
||||
# 1.print();
|
||||
# ("foo".to_owned()).print();
|
||||
# ("foo".to_strbuf()).print();
|
||||
# true.print();
|
||||
# 3.14159.print();
|
||||
~~~~
|
||||
@ -2291,7 +2291,7 @@ provided in the trait definition. Depending on the trait, default
|
||||
methods can save a great deal of boilerplate code from having to be
|
||||
written in impls. Of course, individual impls can still override the
|
||||
default method for `print`, as is being done above in the impl for
|
||||
`~str`.
|
||||
`StrBuf`.
|
||||
|
||||
## Type-parameterized traits
|
||||
|
||||
|
@ -203,7 +203,7 @@ pub struct Parser<'a> {
|
||||
cur: str::CharOffsets<'a>,
|
||||
depth: uint,
|
||||
/// Error messages accumulated during parsing
|
||||
pub errors: Vec<~str>,
|
||||
pub errors: Vec<StrBuf>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator<Piece<'a>> for Parser<'a> {
|
||||
@ -246,10 +246,10 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
/// Notifies of an error. The message doesn't actually need to be of type
|
||||
/// ~str, but I think it does when this eventually uses conditions so it
|
||||
/// StrBuf, but I think it does when this eventually uses conditions so it
|
||||
/// might as well start using it now.
|
||||
fn err(&mut self, msg: &str) {
|
||||
self.errors.push(msg.to_owned());
|
||||
self.errors.push(msg.to_strbuf());
|
||||
}
|
||||
|
||||
/// Optionally consumes the specified character. If the character is not at
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -319,7 +319,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
|
||||
{
|
||||
let mut cg = basic_codegen_options();
|
||||
for option in matches.opt_strs("C").move_iter() {
|
||||
let mut iter = option.splitn('=', 1);
|
||||
let mut iter = option.as_slice().splitn('=', 1);
|
||||
let key = iter.next().unwrap();
|
||||
let value = iter.next();
|
||||
let option_to_lookup = key.replace("-", "_");
|
||||
@ -563,7 +563,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
let mut crate_types: Vec<CrateType> = Vec::new();
|
||||
let unparsed_crate_types = matches.opt_strs("crate-type");
|
||||
for unparsed_crate_type in unparsed_crate_types.iter() {
|
||||
for part in unparsed_crate_type.split(',') {
|
||||
for part in unparsed_crate_type.as_slice().split(',') {
|
||||
let new_part = match part {
|
||||
"lib" => default_lib_output(),
|
||||
"rlib" => CrateTypeRlib,
|
||||
@ -612,7 +612,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
let mut this_bit = 0;
|
||||
for tuple in debug_map.iter() {
|
||||
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
|
||||
if *name == *debug_flag { this_bit = bit; break; }
|
||||
if *name == debug_flag.as_slice() {
|
||||
this_bit = bit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if this_bit == 0 {
|
||||
early_error(format!("unknown debug flag: {}", *debug_flag))
|
||||
@ -628,7 +631,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
if !parse_only && !no_trans {
|
||||
let unparsed_output_types = matches.opt_strs("emit");
|
||||
for unparsed_output_type in unparsed_output_types.iter() {
|
||||
for part in unparsed_output_type.split(',') {
|
||||
for part in unparsed_output_type.as_slice().split(',') {
|
||||
let output_type = match part.as_slice() {
|
||||
"asm" => link::OutputTypeAssembly,
|
||||
"ir" => link::OutputTypeLlvmAssembly,
|
||||
@ -765,7 +768,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_switch_implies_cfg_test() {
|
||||
let matches =
|
||||
&match getopts(["--test".to_owned()], optgroups().as_slice()) {
|
||||
&match getopts(["--test".to_strbuf()], optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => fail!("test_switch_implies_cfg_test: {}", f.to_err_msg())
|
||||
};
|
||||
@ -780,7 +783,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
||||
let matches =
|
||||
&match getopts(["--test".to_owned(), "--cfg=test".to_owned()],
|
||||
&match getopts(["--test".to_strbuf(), "--cfg=test".to_strbuf()],
|
||||
optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
|
@ -35,7 +35,7 @@ pub mod session;
|
||||
pub mod config;
|
||||
|
||||
|
||||
pub fn main_args(args: &[~str]) -> int {
|
||||
pub fn main_args(args: &[StrBuf]) -> int {
|
||||
let owned_args = args.to_owned();
|
||||
monitor(proc() run_compiler(owned_args));
|
||||
0
|
||||
@ -44,7 +44,7 @@ pub fn main_args(args: &[~str]) -> int {
|
||||
static BUG_REPORT_URL: &'static str =
|
||||
"http://static.rust-lang.org/doc/master/complement-bugreport.html";
|
||||
|
||||
fn run_compiler(args: &[~str]) {
|
||||
fn run_compiler(args: &[StrBuf]) {
|
||||
let matches = match handle_options(Vec::from_slice(args)) {
|
||||
Some(matches) => matches,
|
||||
None => return
|
||||
@ -73,7 +73,7 @@ fn run_compiler(args: &[~str]) {
|
||||
let ofile = matches.opt_str("o").map(|o| Path::new(o));
|
||||
|
||||
let pretty = matches.opt_default("pretty", "normal").map(|a| {
|
||||
parse_pretty(&sess, a)
|
||||
parse_pretty(&sess, a.as_slice())
|
||||
});
|
||||
match pretty {
|
||||
Some::<PpMode>(ppm) => {
|
||||
@ -84,7 +84,7 @@ fn run_compiler(args: &[~str]) {
|
||||
}
|
||||
|
||||
let r = matches.opt_strs("Z");
|
||||
if r.contains(&("ls".to_owned())) {
|
||||
if r.contains(&("ls".to_strbuf())) {
|
||||
match input {
|
||||
FileInput(ref ifile) => {
|
||||
let mut stdout = io::stdout();
|
||||
@ -191,17 +191,20 @@ fn describe_codegen_flags() {
|
||||
/// Process command line options. Emits messages as appropirate.If compilation
|
||||
/// should continue, returns a getopts::Matches object parsed from args, otherwise
|
||||
/// returns None.
|
||||
pub fn handle_options(mut args: Vec<~str>) -> Option<getopts::Matches> {
|
||||
pub fn handle_options(mut args: Vec<StrBuf>) -> Option<getopts::Matches> {
|
||||
// Throw away the first argument, the name of the binary
|
||||
let _binary = args.shift().unwrap();
|
||||
|
||||
if args.is_empty() { usage(); return None; }
|
||||
if args.is_empty() {
|
||||
usage();
|
||||
return None;
|
||||
}
|
||||
|
||||
let matches =
|
||||
match getopts::getopts(args.as_slice(), config::optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
early_error(f.to_err_msg());
|
||||
early_error(f.to_err_msg().as_slice());
|
||||
}
|
||||
};
|
||||
|
||||
@ -212,24 +215,24 @@ pub fn handle_options(mut args: Vec<~str>) -> Option<getopts::Matches> {
|
||||
|
||||
let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append(
|
||||
matches.opt_strs("warn").as_slice());
|
||||
if lint_flags.iter().any(|x| x == &"help".to_owned()) {
|
||||
if lint_flags.iter().any(|x| x.as_slice() == "help") {
|
||||
describe_warnings();
|
||||
return None;
|
||||
}
|
||||
|
||||
let r = matches.opt_strs("Z");
|
||||
if r.iter().any(|x| x == &"help".to_owned()) {
|
||||
if r.iter().any(|x| x.as_slice() == "help") {
|
||||
describe_debug_flags();
|
||||
return None;
|
||||
}
|
||||
|
||||
let cg_flags = matches.opt_strs("C");
|
||||
if cg_flags.iter().any(|x| x == &"help".to_owned()) {
|
||||
if cg_flags.iter().any(|x| x.as_slice() == "help") {
|
||||
describe_codegen_flags();
|
||||
return None;
|
||||
}
|
||||
|
||||
if cg_flags.contains(&"passes=list".to_owned()) {
|
||||
if cg_flags.contains(&"passes=list".to_strbuf()) {
|
||||
unsafe { ::lib::llvm::llvm::LLVMRustPrintPasses(); }
|
||||
return None;
|
||||
}
|
||||
|
@ -121,5 +121,8 @@ pub mod lib {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
std::os::set_exit_status(driver::main_args(std::os::args().as_slice()));
|
||||
let args = std::os::args().iter()
|
||||
.map(|x| x.to_strbuf())
|
||||
.collect::<Vec<_>>();
|
||||
std::os::set_exit_status(driver::main_args(args.as_slice()));
|
||||
}
|
||||
|
@ -137,12 +137,7 @@ pub fn usage(argv0: &str) {
|
||||
}
|
||||
|
||||
pub fn main_args(args: &[StrBuf]) -> int {
|
||||
let matches = match getopts::getopts(args.tail()
|
||||
.iter()
|
||||
.map(|x| (*x).to_owned())
|
||||
.collect::<Vec<_>>()
|
||||
.as_slice(),
|
||||
opts().as_slice()) {
|
||||
let matches = match getopts::getopts(args.tail(), opts().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
println!("{}", err.to_err_msg());
|
||||
@ -170,7 +165,7 @@ pub fn main_args(args: &[StrBuf]) -> int {
|
||||
|
||||
let test_args = matches.opt_strs("test-args");
|
||||
let test_args: Vec<StrBuf> = test_args.iter()
|
||||
.flat_map(|s| s.words())
|
||||
.flat_map(|s| s.as_slice().words())
|
||||
.map(|s| s.to_strbuf())
|
||||
.collect();
|
||||
|
||||
@ -199,7 +194,7 @@ pub fn main_args(args: &[StrBuf]) -> int {
|
||||
(false, false) => {}
|
||||
}
|
||||
|
||||
if matches.opt_strs("passes").as_slice() == &["list".to_owned()] {
|
||||
if matches.opt_strs("passes").as_slice() == &["list".to_strbuf()] {
|
||||
println!("Available passes for running rustdoc:");
|
||||
for &(name, _, description) in PASSES.iter() {
|
||||
println!("{:>20s} - {}", name, description);
|
||||
@ -306,7 +301,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
|
||||
clean::NameValue(ref x, ref value)
|
||||
if "passes" == x.as_slice() => {
|
||||
for pass in value.as_slice().words() {
|
||||
passes.push(pass.to_owned());
|
||||
passes.push(pass.to_strbuf());
|
||||
}
|
||||
}
|
||||
clean::NameValue(ref x, ref value)
|
||||
@ -323,15 +318,19 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
|
||||
}
|
||||
if default_passes {
|
||||
for name in DEFAULT_PASSES.iter().rev() {
|
||||
passes.unshift(name.to_owned());
|
||||
passes.unshift(name.to_strbuf());
|
||||
}
|
||||
}
|
||||
|
||||
// Load all plugins/passes into a PluginManager
|
||||
let path = matches.opt_str("plugin-path").unwrap_or("/tmp/rustdoc/plugins".to_owned());
|
||||
let path = matches.opt_str("plugin-path")
|
||||
.unwrap_or("/tmp/rustdoc/plugins".to_strbuf());
|
||||
let mut pm = plugins::PluginManager::new(Path::new(path));
|
||||
for pass in passes.iter() {
|
||||
let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) {
|
||||
let plugin = match PASSES.iter()
|
||||
.position(|&(p, _, _)| {
|
||||
p == pass.as_slice()
|
||||
}) {
|
||||
Some(i) => PASSES[i].val1(),
|
||||
None => {
|
||||
error!("unknown pass {}, skipping", *pass);
|
||||
@ -364,7 +363,7 @@ fn json_input(input: &str) -> Result<Output, StrBuf> {
|
||||
Ok(json::Object(obj)) => {
|
||||
let mut obj = obj;
|
||||
// Make sure the schema is what we expect
|
||||
match obj.pop(&"schema".to_owned()) {
|
||||
match obj.pop(&"schema".to_strbuf()) {
|
||||
Some(json::String(version)) => {
|
||||
if version.as_slice() != SCHEMA_VERSION {
|
||||
return Err(format_strbuf!(
|
||||
@ -375,7 +374,7 @@ fn json_input(input: &str) -> Result<Output, StrBuf> {
|
||||
Some(..) => return Err("malformed json".to_strbuf()),
|
||||
None => return Err("expected a schema version".to_strbuf()),
|
||||
}
|
||||
let krate = match obj.pop(&"crate".to_str()) {
|
||||
let krate = match obj.pop(&"crate".to_strbuf()) {
|
||||
Some(json) => {
|
||||
let mut d = json::Decoder::new(json);
|
||||
Decodable::decode(&mut d).unwrap()
|
||||
@ -404,13 +403,14 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
|
||||
// "plugins": { output of plugins ... }
|
||||
// }
|
||||
let mut json = box collections::TreeMap::new();
|
||||
json.insert("schema".to_owned(), json::String(SCHEMA_VERSION.to_owned()));
|
||||
json.insert("schema".to_strbuf(),
|
||||
json::String(SCHEMA_VERSION.to_strbuf()));
|
||||
let plugins_json = box res.move_iter()
|
||||
.filter_map(|opt| {
|
||||
match opt {
|
||||
None => None,
|
||||
Some((string, json)) => {
|
||||
Some((string.to_owned(), json))
|
||||
Some((string.to_strbuf(), json))
|
||||
}
|
||||
}
|
||||
}).collect();
|
||||
@ -423,15 +423,15 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
|
||||
let mut encoder = json::Encoder::new(&mut w as &mut io::Writer);
|
||||
krate.encode(&mut encoder).unwrap();
|
||||
}
|
||||
str::from_utf8(w.unwrap().as_slice()).unwrap().to_owned()
|
||||
str::from_utf8(w.unwrap().as_slice()).unwrap().to_strbuf()
|
||||
};
|
||||
let crate_json = match json::from_str(crate_json_str) {
|
||||
let crate_json = match json::from_str(crate_json_str.as_slice()) {
|
||||
Ok(j) => j,
|
||||
Err(e) => fail!("Rust generated JSON is invalid: {:?}", e)
|
||||
};
|
||||
|
||||
json.insert("crate".to_owned(), crate_json);
|
||||
json.insert("plugins".to_owned(), json::Object(plugins_json));
|
||||
json.insert("crate".to_strbuf(), crate_json);
|
||||
json.insert("plugins".to_strbuf(), json::Object(plugins_json));
|
||||
|
||||
let mut file = try!(File::create(&dst));
|
||||
try!(json::Object(json).to_writer(&mut file));
|
||||
|
@ -353,21 +353,21 @@ impl Loop {
|
||||
pub struct UvError(c_int);
|
||||
|
||||
impl UvError {
|
||||
pub fn name(&self) -> ~str {
|
||||
pub fn name(&self) -> StrBuf {
|
||||
unsafe {
|
||||
let inner = match self { &UvError(a) => a };
|
||||
let name_str = uvll::uv_err_name(inner);
|
||||
assert!(name_str.is_not_null());
|
||||
from_c_str(name_str)
|
||||
from_c_str(name_str).to_strbuf()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn desc(&self) -> ~str {
|
||||
pub fn desc(&self) -> StrBuf {
|
||||
unsafe {
|
||||
let inner = match self { &UvError(a) => a };
|
||||
let desc_str = uvll::uv_strerror(inner);
|
||||
assert!(desc_str.is_not_null());
|
||||
from_c_str(desc_str)
|
||||
from_c_str(desc_str).to_strbuf()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -851,7 +851,7 @@ mod test {
|
||||
fn connect_close_ip4() {
|
||||
match TcpWatcher::connect(local_loop(), next_test_ip4(), None) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.name(), "ECONNREFUSED".to_owned()),
|
||||
Err(e) => assert_eq!(e.name(), "ECONNREFUSED".to_strbuf()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -859,7 +859,7 @@ mod test {
|
||||
fn connect_close_ip6() {
|
||||
match TcpWatcher::connect(local_loop(), next_test_ip6(), None) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.name(), "ECONNREFUSED".to_owned()),
|
||||
Err(e) => assert_eq!(e.name(), "ECONNREFUSED".to_strbuf()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ mod tests {
|
||||
fn bind_err() {
|
||||
match PipeListener::bind(local_loop(), &"path/to/nowhere".to_c_str()) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.name(), "EACCES".to_owned()),
|
||||
Err(e) => assert_eq!(e.name(), "EACCES".to_strbuf()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ static URLSAFE_CHARS: &'static[u8] = bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
pub trait ToBase64 {
|
||||
/// Converts the value of `self` to a base64 value following the specified
|
||||
/// format configuration, returning the owned string.
|
||||
fn to_base64(&self, config: Config) -> ~str;
|
||||
fn to_base64(&self, config: Config) -> StrBuf;
|
||||
}
|
||||
|
||||
impl<'a> ToBase64 for &'a [u8] {
|
||||
@ -73,7 +73,7 @@ impl<'a> ToBase64 for &'a [u8] {
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
fn to_base64(&self, config: Config) -> ~str {
|
||||
fn to_base64(&self, config: Config) -> StrBuf {
|
||||
let bytes = match config.char_set {
|
||||
Standard => STANDARD_CHARS,
|
||||
UrlSafe => URLSAFE_CHARS
|
||||
@ -146,7 +146,7 @@ impl<'a> ToBase64 for &'a [u8] {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
str::raw::from_utf8(v.as_slice()).to_owned()
|
||||
str::raw::from_utf8(v.as_slice()).to_strbuf()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -195,7 +195,7 @@ impl<'a> FromBase64 for &'a str {
|
||||
* fn main () {
|
||||
* let hello_str = bytes!("Hello, World").to_base64(STANDARD);
|
||||
* println!("base64 output: {}", hello_str);
|
||||
* let res = hello_str.from_base64();
|
||||
* let res = hello_str.as_slice().from_base64();
|
||||
* if res.is_ok() {
|
||||
* let opt_bytes = StrBuf::from_utf8(res.unwrap());
|
||||
* if opt_bytes.is_ok() {
|
||||
@ -267,34 +267,35 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_to_base64_basic() {
|
||||
assert_eq!("".as_bytes().to_base64(STANDARD), "".to_owned());
|
||||
assert_eq!("f".as_bytes().to_base64(STANDARD), "Zg==".to_owned());
|
||||
assert_eq!("fo".as_bytes().to_base64(STANDARD), "Zm8=".to_owned());
|
||||
assert_eq!("foo".as_bytes().to_base64(STANDARD), "Zm9v".to_owned());
|
||||
assert_eq!("foob".as_bytes().to_base64(STANDARD), "Zm9vYg==".to_owned());
|
||||
assert_eq!("fooba".as_bytes().to_base64(STANDARD), "Zm9vYmE=".to_owned());
|
||||
assert_eq!("foobar".as_bytes().to_base64(STANDARD), "Zm9vYmFy".to_owned());
|
||||
assert_eq!("".as_bytes().to_base64(STANDARD), "".to_strbuf());
|
||||
assert_eq!("f".as_bytes().to_base64(STANDARD), "Zg==".to_strbuf());
|
||||
assert_eq!("fo".as_bytes().to_base64(STANDARD), "Zm8=".to_strbuf());
|
||||
assert_eq!("foo".as_bytes().to_base64(STANDARD), "Zm9v".to_strbuf());
|
||||
assert_eq!("foob".as_bytes().to_base64(STANDARD), "Zm9vYg==".to_strbuf());
|
||||
assert_eq!("fooba".as_bytes().to_base64(STANDARD), "Zm9vYmE=".to_strbuf());
|
||||
assert_eq!("foobar".as_bytes().to_base64(STANDARD), "Zm9vYmFy".to_strbuf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_base64_line_break() {
|
||||
assert!(![0u8, ..1000].to_base64(Config {line_length: None, ..STANDARD})
|
||||
.contains("\r\n"));
|
||||
.as_slice()
|
||||
.contains("\r\n"));
|
||||
assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4),
|
||||
..STANDARD}),
|
||||
"Zm9v\r\nYmFy".to_owned());
|
||||
"Zm9v\r\nYmFy".to_strbuf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_base64_padding() {
|
||||
assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zg".to_owned());
|
||||
assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zm8".to_owned());
|
||||
assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zg".to_strbuf());
|
||||
assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zm8".to_strbuf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_base64_url_safe() {
|
||||
assert_eq!([251, 255].to_base64(URL_SAFE), "-_8".to_owned());
|
||||
assert_eq!([251, 255].to_base64(STANDARD), "+/8=".to_owned());
|
||||
assert_eq!([251, 255].to_base64(URL_SAFE), "-_8".to_strbuf());
|
||||
assert_eq!([251, 255].to_base64(STANDARD), "+/8=".to_strbuf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -339,7 +340,12 @@ mod tests {
|
||||
for _ in range(0, 1000) {
|
||||
let times = task_rng().gen_range(1u, 100);
|
||||
let v = Vec::from_fn(times, |_| random::<u8>());
|
||||
assert_eq!(v.as_slice().to_base64(STANDARD).from_base64().unwrap().as_slice(),
|
||||
assert_eq!(v.as_slice()
|
||||
.to_base64(STANDARD)
|
||||
.as_slice()
|
||||
.from_base64()
|
||||
.unwrap()
|
||||
.as_slice(),
|
||||
v.as_slice());
|
||||
}
|
||||
}
|
||||
@ -360,7 +366,7 @@ mod tests {
|
||||
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
|
||||
let sb = s.as_bytes().to_base64(STANDARD);
|
||||
b.iter(|| {
|
||||
sb.from_base64().unwrap();
|
||||
sb.as_slice().from_base64().unwrap();
|
||||
});
|
||||
b.bytes = sb.len() as u64;
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ impl<'doc> Doc<'doc> {
|
||||
str::from_utf8(self.data.slice(self.start, self.end)).unwrap()
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> ~str {
|
||||
self.as_str_slice().to_owned()
|
||||
pub fn as_str(&self) -> StrBuf {
|
||||
self.as_str_slice().to_strbuf()
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ pub enum EbmlEncoderTag {
|
||||
#[deriving(Show)]
|
||||
pub enum Error {
|
||||
IntTooBig(uint),
|
||||
Expected(~str),
|
||||
Expected(StrBuf),
|
||||
IoError(io::IoError)
|
||||
}
|
||||
// --------------------------------------
|
||||
@ -312,7 +312,10 @@ pub mod reader {
|
||||
self.pos = r_doc.end;
|
||||
let str = r_doc.as_str_slice();
|
||||
if lbl != str {
|
||||
return Err(Expected(format!("Expected label {} but found {}", lbl, str)));
|
||||
return Err(Expected(format_strbuf!("Expected label \
|
||||
{} but found {}",
|
||||
lbl,
|
||||
str)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -322,7 +325,8 @@ pub mod reader {
|
||||
fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<Doc<'doc>> {
|
||||
debug!(". next_doc(exp_tag={:?})", exp_tag);
|
||||
if self.pos >= self.parent.end {
|
||||
return Err(Expected(format!("no more documents in current node!")));
|
||||
return Err(Expected(format_strbuf!("no more documents in \
|
||||
current node!")));
|
||||
}
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
try!(doc_at(self.parent.data, self.pos));
|
||||
@ -334,12 +338,18 @@ pub mod reader {
|
||||
r_doc.start,
|
||||
r_doc.end);
|
||||
if r_tag != (exp_tag as uint) {
|
||||
return Err(Expected(format!("expected EBML doc with tag {:?} but found tag {:?}",
|
||||
exp_tag, r_tag)));
|
||||
return Err(Expected(format_strbuf!("expected EBML doc with \
|
||||
tag {:?} but found tag \
|
||||
{:?}",
|
||||
exp_tag,
|
||||
r_tag)));
|
||||
}
|
||||
if r_doc.end > self.parent.end {
|
||||
return Err(Expected(format!("invalid EBML, child extends to {:#x}, parent to {:#x}",
|
||||
r_doc.end, self.parent.end)));
|
||||
return Err(Expected(format_strbuf!("invalid EBML, child \
|
||||
extends to {:#x}, parent \
|
||||
to {:#x}",
|
||||
r_doc.end,
|
||||
self.parent.end)));
|
||||
}
|
||||
self.pos = r_doc.end;
|
||||
Ok(r_doc)
|
||||
@ -433,7 +443,7 @@ pub mod reader {
|
||||
fn read_char(&mut self) -> DecodeResult<char> {
|
||||
Ok(char::from_u32(doc_as_u32(try!(self.next_doc(EsChar)))).unwrap())
|
||||
}
|
||||
fn read_str(&mut self) -> DecodeResult<~str> {
|
||||
fn read_str(&mut self) -> DecodeResult<StrBuf> {
|
||||
Ok(try!(self.next_doc(EsStr)).as_str())
|
||||
}
|
||||
|
||||
@ -570,7 +580,10 @@ pub mod reader {
|
||||
match idx {
|
||||
0 => f(this, false),
|
||||
1 => f(this, true),
|
||||
_ => Err(Expected(format!("Expected None or Some"))),
|
||||
_ => {
|
||||
Err(Expected(format_strbuf!("Expected None or \
|
||||
Some")))
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -16,7 +16,7 @@ use std::fmt;
|
||||
pub trait ToHex {
|
||||
/// Converts the value of `self` to a hex value, returning the owned
|
||||
/// string.
|
||||
fn to_hex(&self) -> ~str;
|
||||
fn to_hex(&self) -> StrBuf;
|
||||
}
|
||||
|
||||
static CHARS: &'static[u8] = bytes!("0123456789abcdef");
|
||||
@ -37,7 +37,7 @@ impl<'a> ToHex for &'a [u8] {
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
fn to_hex(&self) -> ~str {
|
||||
fn to_hex(&self) -> StrBuf {
|
||||
let mut v = Vec::with_capacity(self.len() * 2);
|
||||
for &byte in self.iter() {
|
||||
v.push(CHARS[(byte >> 4) as uint]);
|
||||
@ -45,7 +45,7 @@ impl<'a> ToHex for &'a [u8] {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
str::raw::from_utf8(v.as_slice()).to_owned()
|
||||
str::raw::from_utf8(v.as_slice()).to_strbuf()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,7 +94,7 @@ impl<'a> FromHex for &'a str {
|
||||
* fn main () {
|
||||
* let hello_str = "Hello, World".as_bytes().to_hex();
|
||||
* println!("{}", hello_str);
|
||||
* let bytes = hello_str.from_hex().unwrap();
|
||||
* let bytes = hello_str.as_slice().from_hex().unwrap();
|
||||
* println!("{:?}", bytes);
|
||||
* let result_str = StrBuf::from_utf8(bytes).unwrap();
|
||||
* println!("{}", result_str);
|
||||
@ -143,7 +143,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
pub fn test_to_hex() {
|
||||
assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172".to_owned());
|
||||
assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172".to_strbuf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -174,7 +174,8 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_to_hex_all_bytes() {
|
||||
for i in range(0, 256) {
|
||||
assert_eq!([i as u8].to_hex(), format!("{:02x}", i as uint));
|
||||
assert_eq!([i as u8].to_hex(),
|
||||
format_strbuf!("{:02x}", i as uint));
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +203,7 @@ mod tests {
|
||||
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
|
||||
let sb = s.as_bytes().to_hex();
|
||||
b.iter(|| {
|
||||
sb.from_hex().unwrap();
|
||||
sb.as_slice().from_hex().unwrap();
|
||||
});
|
||||
b.bytes = sb.len() as u64;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -108,7 +108,7 @@ pub trait Decoder<E> {
|
||||
fn read_f64(&mut self) -> Result<f64, E>;
|
||||
fn read_f32(&mut self) -> Result<f32, E>;
|
||||
fn read_char(&mut self) -> Result<char, E>;
|
||||
fn read_str(&mut self) -> Result<~str, E>;
|
||||
fn read_str(&mut self) -> Result<StrBuf, E>;
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T>(&mut self, name: &str, f: |&mut Self| -> Result<T, E>) -> Result<T, E>;
|
||||
@ -301,18 +301,6 @@ impl<'a, E, S:Encoder<E>> Encodable<S, E> for &'a str {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for ~str {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_str(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for ~str {
|
||||
fn decode(d: &mut D) -> Result<~str, E> {
|
||||
d.read_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for StrBuf {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_str(self.as_slice())
|
||||
@ -321,7 +309,7 @@ impl<E, S:Encoder<E>> Encodable<S, E> for StrBuf {
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for StrBuf {
|
||||
fn decode(d: &mut D) -> Result<StrBuf, E> {
|
||||
Ok(StrBuf::from_str(try!(d.read_str())))
|
||||
Ok(StrBuf::from_str(try!(d.read_str()).as_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ impl<S: Encoder<E>, E> Encodable<S, E> for Ident {
|
||||
|
||||
impl<D:Decoder<E>, E> Decodable<D, E> for Ident {
|
||||
fn decode(d: &mut D) -> Result<Ident, E> {
|
||||
Ok(str_to_ident(try!(d.read_str())))
|
||||
Ok(str_to_ident(try!(d.read_str()).as_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -886,7 +886,9 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
|
||||
}
|
||||
match parser.errors.shift() {
|
||||
Some(error) => {
|
||||
cx.ecx.span_err(efmt.span, "invalid format string: " + error);
|
||||
cx.ecx.span_err(efmt.span,
|
||||
format_strbuf!("invalid format string: {}",
|
||||
error).as_slice());
|
||||
return DummyResult::raw_expr(sp);
|
||||
}
|
||||
None => {}
|
||||
|
@ -606,7 +606,8 @@ impl<'a> Equiv<&'a str> for InternedString {
|
||||
|
||||
impl<D:Decoder<E>, E> Decodable<D, E> for InternedString {
|
||||
fn decode(d: &mut D) -> Result<InternedString, E> {
|
||||
Ok(get_name(get_ident_interner().intern(try!(d.read_str()))))
|
||||
Ok(get_name(get_ident_interner().intern(
|
||||
try!(d.read_str()).as_slice())))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,11 +354,7 @@ Test Attributes:
|
||||
pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
|
||||
let args_ = args.tail();
|
||||
let matches =
|
||||
match getopts::getopts(args_.iter()
|
||||
.map(|x| x.to_owned())
|
||||
.collect::<Vec<_>>()
|
||||
.as_slice(),
|
||||
optgroups().as_slice()) {
|
||||
match getopts::getopts(args_.as_slice(), optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => return Some(Err(f.to_err_msg().to_strbuf()))
|
||||
};
|
||||
@ -388,7 +384,8 @@ pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
|
||||
let ratchet_metrics = ratchet_metrics.map(|s| Path::new(s));
|
||||
|
||||
let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent");
|
||||
let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::<f64>(s).unwrap());
|
||||
let ratchet_noise_percent =
|
||||
ratchet_noise_percent.map(|s| from_str::<f64>(s.as_slice()).unwrap());
|
||||
|
||||
let save_metrics = matches.opt_str("save-metrics");
|
||||
let save_metrics = save_metrics.map(|s| Path::new(s));
|
||||
@ -1068,8 +1065,8 @@ fn calc_result(desc: &TestDesc, task_succeeded: bool) -> TestResult {
|
||||
impl ToJson for Metric {
|
||||
fn to_json(&self) -> json::Json {
|
||||
let mut map = box TreeMap::new();
|
||||
map.insert("value".to_owned(), json::Number(self.value));
|
||||
map.insert("noise".to_owned(), json::Number(self.noise));
|
||||
map.insert("value".to_strbuf(), json::Number(self.value));
|
||||
map.insert("noise".to_strbuf(), json::Number(self.noise));
|
||||
json::Object(map)
|
||||
}
|
||||
}
|
||||
@ -1106,7 +1103,7 @@ impl MetricMap {
|
||||
// FIXME(pcwalton): Yuck.
|
||||
let mut new_map = TreeMap::new();
|
||||
for (ref key, ref value) in map.iter() {
|
||||
new_map.insert(key.to_owned(), (*value).clone());
|
||||
new_map.insert(key.to_strbuf(), (*value).clone());
|
||||
}
|
||||
|
||||
new_map.to_json().to_pretty_writer(&mut file)
|
||||
|
@ -192,7 +192,7 @@ pub fn tzset() {
|
||||
|
||||
/// Holds a calendar date and time broken down into its components (year, month, day, and so on),
|
||||
/// also called a broken-down time value.
|
||||
#[deriving(Clone, Eq, Encodable, Decodable, Show)]
|
||||
#[deriving(Clone, Eq, Show)]
|
||||
pub struct Tm {
|
||||
/// Seconds after the minute – [0, 60]
|
||||
pub tm_sec: i32,
|
||||
|
@ -500,7 +500,7 @@ impl<T: Encoder<E>, E> Encodable<T, E> for Uuid {
|
||||
impl<T: Decoder<E>, E> Decodable<T, E> for Uuid {
|
||||
/// Decode a UUID from a string
|
||||
fn decode(d: &mut T) -> Result<Uuid, E> {
|
||||
Ok(from_str(try!(d.read_str())).unwrap())
|
||||
Ok(from_str(try!(d.read_str()).as_slice()).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ impl Database {
|
||||
// FIXME(pcwalton): Yuck.
|
||||
let mut new_db_cache = TreeMap::new();
|
||||
for (ref k, ref v) in self.db_cache.iter() {
|
||||
new_db_cache.insert((*k).to_owned(), (*v).to_owned());
|
||||
new_db_cache.insert((*k).to_strbuf(), (*v).to_strbuf());
|
||||
}
|
||||
|
||||
new_db_cache.to_json().to_pretty_writer(&mut f)
|
||||
@ -513,10 +513,13 @@ fn test() {
|
||||
let pth = pth.clone();
|
||||
|
||||
let contents = File::open(&pth).read_to_end().unwrap();
|
||||
let file_content = from_utf8(contents.as_slice()).unwrap().to_owned();
|
||||
let file_content = from_utf8(contents.as_slice()).unwrap()
|
||||
.to_strbuf();
|
||||
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
prep.declare_input("file", pth.as_str().unwrap(), file_content);
|
||||
prep.declare_input("file",
|
||||
pth.as_str().unwrap(),
|
||||
file_content.as_slice());
|
||||
prep.exec(proc(_exe) {
|
||||
let out = make_path("foo.o".to_strbuf());
|
||||
let compiler = if cfg!(windows) {"gcc"} else {"cc"};
|
||||
@ -526,7 +529,7 @@ fn test() {
|
||||
// Could run sub-rules inside here.
|
||||
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
out.as_str().unwrap().to_owned()
|
||||
out.as_str().unwrap().to_strbuf()
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -55,7 +55,7 @@ struct Config {
|
||||
fn parse_opts(argv: Vec<StrBuf> ) -> Config {
|
||||
let opts = vec!(getopts::optflag("", "stress", ""));
|
||||
|
||||
let argv = argv.iter().map(|x| x.to_str()).collect::<Vec<_>>();
|
||||
let argv = argv.iter().map(|x| x.to_strbuf()).collect::<Vec<_>>();
|
||||
let opt_args = argv.slice(1, argv.len());
|
||||
|
||||
match getopts::getopts(opt_args, opts.as_slice()) {
|
||||
|
@ -23,7 +23,7 @@ enum object {
|
||||
|
||||
fn lookup(table: Box<json::Object>, key: StrBuf, default: StrBuf) -> StrBuf
|
||||
{
|
||||
match table.find(&key.to_owned()) {
|
||||
match table.find(&key.to_strbuf()) {
|
||||
option::Some(&json::String(ref s)) => {
|
||||
(*s).to_strbuf()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user