auto merge of #14170 : pcwalton/rust/detildestr-misclibs, r=alexcrichton
r? @brson
This commit is contained in:
commit
e10fd31721
|
@ -152,7 +152,8 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
|
|||
"(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"),
|
||||
test_shard: test::opt_shard(matches.opt_str("test-shard")),
|
||||
test_shard: test::opt_shard(matches.opt_str("test-shard")
|
||||
.map(|x| x.to_strbuf())),
|
||||
verbose: matches.opt_present("verbose")
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +236,10 @@ pub fn run_tests(config: &Config) {
|
|||
|
||||
pub fn test_opts(config: &Config) -> test::TestOpts {
|
||||
test::TestOpts {
|
||||
filter: config.filter.clone(),
|
||||
filter: match config.filter {
|
||||
None => None,
|
||||
Some(ref filter) => Some(filter.to_strbuf()),
|
||||
},
|
||||
run_ignored: config.run_ignored,
|
||||
logfile: config.logfile.clone(),
|
||||
run_tests: true,
|
||||
|
@ -314,7 +318,9 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
|
|||
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
|
||||
}
|
||||
|
||||
test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
|
||||
test::DynTestName(format_strbuf!("[{}] {}",
|
||||
config.mode,
|
||||
shorten(testfile)))
|
||||
}
|
||||
|
||||
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
|
||||
|
|
|
@ -530,7 +530,7 @@ mod tests {
|
|||
}
|
||||
|
||||
struct Noncopy {
|
||||
string: ~str,
|
||||
string: StrBuf,
|
||||
array: Vec<int> ,
|
||||
}
|
||||
|
||||
|
@ -539,7 +539,7 @@ mod tests {
|
|||
let arena = TypedArena::new();
|
||||
for _ in range(0, 100000) {
|
||||
arena.alloc(Noncopy {
|
||||
string: "hello world".to_owned(),
|
||||
string: "hello world".to_strbuf(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
});
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ mod tests {
|
|||
let arena = TypedArena::new();
|
||||
b.iter(|| {
|
||||
arena.alloc(Noncopy {
|
||||
string: "hello world".to_owned(),
|
||||
string: "hello world".to_strbuf(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
})
|
||||
})
|
||||
|
@ -560,7 +560,7 @@ mod tests {
|
|||
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
box Noncopy {
|
||||
string: "hello world".to_owned(),
|
||||
string: "hello world".to_strbuf(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
}
|
||||
})
|
||||
|
@ -571,7 +571,7 @@ mod tests {
|
|||
let arena = Arena::new();
|
||||
b.iter(|| {
|
||||
arena.alloc(|| Noncopy {
|
||||
string: "hello world".to_owned(),
|
||||
string: "hello world".to_strbuf(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
})
|
||||
})
|
||||
|
|
|
@ -270,23 +270,23 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_put_update() {
|
||||
let mut cache: LruCache<~str, Vec<u8>> = LruCache::new(1);
|
||||
cache.put("1".to_owned(), vec![10, 10]);
|
||||
cache.put("1".to_owned(), vec![10, 19]);
|
||||
assert_opt_eq(cache.get(&"1".to_owned()), vec![10, 19]);
|
||||
let mut cache: LruCache<StrBuf, Vec<u8>> = LruCache::new(1);
|
||||
cache.put("1".to_strbuf(), vec![10, 10]);
|
||||
cache.put("1".to_strbuf(), vec![10, 19]);
|
||||
assert_opt_eq(cache.get(&"1".to_strbuf()), vec![10, 19]);
|
||||
assert_eq!(cache.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expire_lru() {
|
||||
let mut cache: LruCache<~str, ~str> = LruCache::new(2);
|
||||
cache.put("foo1".to_owned(), "bar1".to_owned());
|
||||
cache.put("foo2".to_owned(), "bar2".to_owned());
|
||||
cache.put("foo3".to_owned(), "bar3".to_owned());
|
||||
assert!(cache.get(&"foo1".to_owned()).is_none());
|
||||
cache.put("foo2".to_owned(), "bar2update".to_owned());
|
||||
cache.put("foo4".to_owned(), "bar4".to_owned());
|
||||
assert!(cache.get(&"foo3".to_owned()).is_none());
|
||||
let mut cache: LruCache<StrBuf, StrBuf> = LruCache::new(2);
|
||||
cache.put("foo1".to_strbuf(), "bar1".to_strbuf());
|
||||
cache.put("foo2".to_strbuf(), "bar2".to_strbuf());
|
||||
cache.put("foo3".to_strbuf(), "bar3".to_strbuf());
|
||||
assert!(cache.get(&"foo1".to_strbuf()).is_none());
|
||||
cache.put("foo2".to_strbuf(), "bar2update".to_strbuf());
|
||||
cache.put("foo4".to_strbuf(), "bar4".to_strbuf());
|
||||
assert!(cache.get(&"foo3".to_strbuf()).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -310,7 +310,7 @@ impl Pattern {
|
|||
* brackets. The resulting string will, when compiled into a `Pattern`,
|
||||
* match the input string and nothing else.
|
||||
*/
|
||||
pub fn escape(s: &str) -> ~str {
|
||||
pub fn escape(s: &str) -> StrBuf {
|
||||
let mut escaped = StrBuf::new();
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
|
@ -325,7 +325,7 @@ impl Pattern {
|
|||
}
|
||||
}
|
||||
}
|
||||
escaped.into_owned()
|
||||
escaped
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -767,8 +767,8 @@ mod test {
|
|||
#[test]
|
||||
fn test_pattern_escape() {
|
||||
let s = "_[_]_?_*_!_";
|
||||
assert_eq!(Pattern::escape(s), "_[[]_[]]_[?]_[*]_!_".to_owned());
|
||||
assert!(Pattern::new(Pattern::escape(s)).matches(s));
|
||||
assert_eq!(Pattern::escape(s), "_[[]_[]]_[?]_[*]_!_".to_strbuf());
|
||||
assert!(Pattern::new(Pattern::escape(s).as_slice()).matches(s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -433,10 +433,10 @@ impl<'a> LabelText<'a> {
|
|||
}
|
||||
|
||||
/// Renders text as string suitable for a label in a .dot file.
|
||||
pub fn escape(&self) -> ~str {
|
||||
pub fn escape(&self) -> StrBuf {
|
||||
match self {
|
||||
&LabelStr(ref s) => s.as_slice().escape_default(),
|
||||
&EscStr(ref s) => LabelText::escape_str(s.as_slice()).into_owned(),
|
||||
&LabelStr(ref s) => s.as_slice().escape_default().to_strbuf(),
|
||||
&EscStr(ref s) => LabelText::escape_str(s.as_slice()).to_strbuf(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -661,11 +661,14 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn test_input(g: LabelledGraph) -> IoResult<~str> {
|
||||
fn test_input(g: LabelledGraph) -> IoResult<StrBuf> {
|
||||
let mut writer = MemWriter::new();
|
||||
render(&g, &mut writer).unwrap();
|
||||
let mut r = BufReader::new(writer.get_ref());
|
||||
r.read_to_str()
|
||||
match r.read_to_str() {
|
||||
Ok(string) => Ok(string.to_strbuf()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
// All of the tests use raw-strings as the format for the expected outputs,
|
||||
|
|
|
@ -70,30 +70,39 @@ pub fn macro_registrar(register: |Name, SyntaxExtension|) {
|
|||
|
||||
//Check if the literal is valid (as LLVM expects),
|
||||
//and return a descriptive error if not.
|
||||
fn hex_float_lit_err(s: &str) -> Option<(uint, ~str)> {
|
||||
fn hex_float_lit_err(s: &str) -> Option<(uint, StrBuf)> {
|
||||
let mut chars = s.chars().peekable();
|
||||
let mut i = 0;
|
||||
if chars.peek() == Some(&'-') { chars.next(); i+= 1 }
|
||||
if chars.next() != Some('0') { return Some((i, "Expected '0'".to_owned())); } i+=1;
|
||||
if chars.next() != Some('x') { return Some((i, "Expected 'x'".to_owned())); } i+=1;
|
||||
if chars.next() != Some('0') {
|
||||
return Some((i, "Expected '0'".to_strbuf()));
|
||||
} i+=1;
|
||||
if chars.next() != Some('x') {
|
||||
return Some((i, "Expected 'x'".to_strbuf()));
|
||||
} i+=1;
|
||||
let mut d_len = 0;
|
||||
for _ in chars.take_while(|c| c.is_digit_radix(16)) { chars.next(); i+=1; d_len += 1;}
|
||||
if chars.next() != Some('.') { return Some((i, "Expected '.'".to_owned())); } i+=1;
|
||||
if chars.next() != Some('.') {
|
||||
return Some((i, "Expected '.'".to_strbuf()));
|
||||
} i+=1;
|
||||
let mut f_len = 0;
|
||||
for _ in chars.take_while(|c| c.is_digit_radix(16)) { chars.next(); i+=1; f_len += 1;}
|
||||
if d_len == 0 && f_len == 0 {
|
||||
return Some((i, "Expected digits before or after decimal point".to_owned()));
|
||||
return Some((i, "Expected digits before or after decimal \
|
||||
point".to_strbuf()));
|
||||
}
|
||||
if chars.next() != Some('p') { return Some((i, "Expected 'p'".to_owned())); } i+=1;
|
||||
if chars.next() != Some('p') {
|
||||
return Some((i, "Expected 'p'".to_strbuf()));
|
||||
} i+=1;
|
||||
if chars.peek() == Some(&'-') { chars.next(); i+= 1 }
|
||||
let mut e_len = 0;
|
||||
for _ in chars.take_while(|c| c.is_digit()) { chars.next(); i+=1; e_len += 1}
|
||||
if e_len == 0 {
|
||||
return Some((i, "Expected exponent digits".to_owned()));
|
||||
return Some((i, "Expected exponent digits".to_strbuf()));
|
||||
}
|
||||
match chars.next() {
|
||||
None => None,
|
||||
Some(_) => Some((i, "Expected end of string".to_owned()))
|
||||
Some(_) => Some((i, "Expected end of string".to_strbuf()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::cmp;
|
|||
|
||||
#[deriving(Show, Clone)]
|
||||
pub struct LogDirective {
|
||||
pub name: Option<~str>,
|
||||
pub name: Option<StrBuf>,
|
||||
pub level: u32,
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ pub fn parse_logging_spec(spec: &str) -> Vec<LogDirective> {
|
|||
}
|
||||
};
|
||||
dirs.push(LogDirective {
|
||||
name: name.map(|s| s.to_owned()),
|
||||
name: name.map(|s| s.to_strbuf()),
|
||||
level: log_level,
|
||||
});
|
||||
}
|
||||
|
@ -80,13 +80,13 @@ mod tests {
|
|||
let dirs = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4");
|
||||
let dirs = dirs.as_slice();
|
||||
assert_eq!(dirs.len(), 3);
|
||||
assert_eq!(dirs[0].name, Some("crate1::mod1".to_owned()));
|
||||
assert_eq!(dirs[0].name, Some("crate1::mod1".to_strbuf()));
|
||||
assert_eq!(dirs[0].level, 1);
|
||||
|
||||
assert_eq!(dirs[1].name, Some("crate1::mod2".to_owned()));
|
||||
assert_eq!(dirs[1].name, Some("crate1::mod2".to_strbuf()));
|
||||
assert_eq!(dirs[1].level, ::MAX_LOG_LEVEL);
|
||||
|
||||
assert_eq!(dirs[2].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[2].name, Some("crate2".to_strbuf()));
|
||||
assert_eq!(dirs[2].level, 4);
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ mod tests {
|
|||
let dirs = parse_logging_spec("crate1::mod1=1=2,crate2=4");
|
||||
let dirs = dirs.as_slice();
|
||||
assert_eq!(dirs.len(), 1);
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_strbuf()));
|
||||
assert_eq!(dirs[0].level, 4);
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ mod tests {
|
|||
let dirs = parse_logging_spec("crate1::mod1=noNumber,crate2=4");
|
||||
let dirs = dirs.as_slice();
|
||||
assert_eq!(dirs.len(), 1);
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_strbuf()));
|
||||
assert_eq!(dirs[0].level, 4);
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ mod tests {
|
|||
let dirs = parse_logging_spec("crate1::mod1=wrong,crate2=warn");
|
||||
let dirs = dirs.as_slice();
|
||||
assert_eq!(dirs.len(), 1);
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_strbuf()));
|
||||
assert_eq!(dirs[0].level, ::WARN);
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ mod tests {
|
|||
assert_eq!(dirs.len(), 2);
|
||||
assert_eq!(dirs[0].name, None);
|
||||
assert_eq!(dirs[0].level, 2);
|
||||
assert_eq!(dirs[1].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[1].name, Some("crate2".to_strbuf()));
|
||||
assert_eq!(dirs[1].level, 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ fn enabled(level: u32, module: &str,
|
|||
// Search for the longest match, the vector is assumed to be pre-sorted.
|
||||
for directive in iter.rev() {
|
||||
match directive.name {
|
||||
Some(ref name) if !module.starts_with(*name) => {},
|
||||
Some(ref name) if !module.starts_with(name.as_slice()) => {},
|
||||
Some(..) | None => {
|
||||
return level <= directive.level
|
||||
}
|
||||
|
@ -362,8 +362,16 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn match_full_path() {
|
||||
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
let dirs = [
|
||||
LogDirective {
|
||||
name: Some("crate2".to_strbuf()),
|
||||
level: 3
|
||||
},
|
||||
LogDirective {
|
||||
name: Some("crate1::mod1".to_strbuf()),
|
||||
level: 2
|
||||
}
|
||||
];
|
||||
assert!(enabled(2, "crate1::mod1", dirs.iter()));
|
||||
assert!(!enabled(3, "crate1::mod1", dirs.iter()));
|
||||
assert!(enabled(3, "crate2", dirs.iter()));
|
||||
|
@ -372,39 +380,49 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn no_match() {
|
||||
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
let dirs = [
|
||||
LogDirective { name: Some("crate2".to_strbuf()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
|
||||
];
|
||||
assert!(!enabled(2, "crate3", dirs.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_beginning() {
|
||||
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
let dirs = [
|
||||
LogDirective { name: Some("crate2".to_strbuf()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
|
||||
];
|
||||
assert!(enabled(3, "crate2::mod1", dirs.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_beginning_longest_match() {
|
||||
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
|
||||
LogDirective { name: Some("crate2::mod".to_owned()), level: 4 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
let dirs = [
|
||||
LogDirective { name: Some("crate2".to_strbuf()), level: 3 },
|
||||
LogDirective { name: Some("crate2::mod".to_strbuf()), level: 4 },
|
||||
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
|
||||
];
|
||||
assert!(enabled(4, "crate2::mod1", dirs.iter()));
|
||||
assert!(!enabled(4, "crate2", dirs.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_default() {
|
||||
let dirs = [LogDirective { name: None, level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
let dirs = [
|
||||
LogDirective { name: None, level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
|
||||
];
|
||||
assert!(enabled(2, "crate1::mod1", dirs.iter()));
|
||||
assert!(enabled(3, "crate2::mod2", dirs.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_level() {
|
||||
let dirs = [LogDirective { name: None, level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 0 }];
|
||||
let dirs = [
|
||||
LogDirective { name: None, level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 0 }
|
||||
];
|
||||
assert!(!enabled(1, "crate1::mod1", dirs.iter()));
|
||||
assert!(enabled(3, "crate2::mod2", dirs.iter()));
|
||||
}
|
||||
|
|
|
@ -1865,60 +1865,60 @@ mod biguint_tests {
|
|||
assert!(((one << 64) + one).is_odd());
|
||||
}
|
||||
|
||||
fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, ~str)>)> {
|
||||
fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, StrBuf)>)> {
|
||||
let bits = BigDigit::bits;
|
||||
vec!(( Zero::zero(), vec!(
|
||||
(2, "0".to_owned()), (3, "0".to_owned())
|
||||
(2, "0".to_strbuf()), (3, "0".to_strbuf())
|
||||
)), ( BigUint::from_slice([ 0xff ]), vec!(
|
||||
(2, "11111111".to_owned()),
|
||||
(3, "100110".to_owned()),
|
||||
(4, "3333".to_owned()),
|
||||
(5, "2010".to_owned()),
|
||||
(6, "1103".to_owned()),
|
||||
(7, "513".to_owned()),
|
||||
(8, "377".to_owned()),
|
||||
(9, "313".to_owned()),
|
||||
(10, "255".to_owned()),
|
||||
(11, "212".to_owned()),
|
||||
(12, "193".to_owned()),
|
||||
(13, "168".to_owned()),
|
||||
(14, "143".to_owned()),
|
||||
(15, "120".to_owned()),
|
||||
(16, "ff".to_owned())
|
||||
(2, "11111111".to_strbuf()),
|
||||
(3, "100110".to_strbuf()),
|
||||
(4, "3333".to_strbuf()),
|
||||
(5, "2010".to_strbuf()),
|
||||
(6, "1103".to_strbuf()),
|
||||
(7, "513".to_strbuf()),
|
||||
(8, "377".to_strbuf()),
|
||||
(9, "313".to_strbuf()),
|
||||
(10, "255".to_strbuf()),
|
||||
(11, "212".to_strbuf()),
|
||||
(12, "193".to_strbuf()),
|
||||
(13, "168".to_strbuf()),
|
||||
(14, "143".to_strbuf()),
|
||||
(15, "120".to_strbuf()),
|
||||
(16, "ff".to_strbuf())
|
||||
)), ( BigUint::from_slice([ 0xfff ]), vec!(
|
||||
(2, "111111111111".to_owned()),
|
||||
(4, "333333".to_owned()),
|
||||
(16, "fff".to_owned())
|
||||
(2, "111111111111".to_strbuf()),
|
||||
(4, "333333".to_strbuf()),
|
||||
(16, "fff".to_strbuf())
|
||||
)), ( BigUint::from_slice([ 1, 2 ]), vec!(
|
||||
(2,
|
||||
"10".to_owned() +
|
||||
"0".repeat(bits - 1) + "1"),
|
||||
format_strbuf!("10{}1", "0".repeat(bits - 1))),
|
||||
(4,
|
||||
"2".to_owned() +
|
||||
"0".repeat(bits / 2 - 1) + "1"),
|
||||
format_strbuf!("2{}1", "0".repeat(bits / 2 - 1))),
|
||||
(10, match bits {
|
||||
32 => "8589934593".to_owned(), 16 => "131073".to_owned(), _ => fail!()
|
||||
}),
|
||||
(16,
|
||||
"2".to_owned() +
|
||||
"0".repeat(bits / 4 - 1) + "1")
|
||||
)), ( BigUint::from_slice([ 1, 2, 3 ]), vec!(
|
||||
(2,
|
||||
"11".to_owned() +
|
||||
"0".repeat(bits - 2) + "10" +
|
||||
"0".repeat(bits - 1) + "1"),
|
||||
(4,
|
||||
"3".to_owned() +
|
||||
"0".repeat(bits / 2 - 1) + "2" +
|
||||
"0".repeat(bits / 2 - 1) + "1"),
|
||||
(10, match bits {
|
||||
32 => "55340232229718589441".to_owned(),
|
||||
16 => "12885032961".to_owned(),
|
||||
32 => "8589934593".to_strbuf(),
|
||||
16 => "131073".to_strbuf(),
|
||||
_ => fail!()
|
||||
}),
|
||||
(16, "3".to_owned() +
|
||||
"0".repeat(bits / 4 - 1) + "2" +
|
||||
"0".repeat(bits / 4 - 1) + "1")
|
||||
(16,
|
||||
format_strbuf!("2{}1", "0".repeat(bits / 4 - 1)))
|
||||
)), ( BigUint::from_slice([ 1, 2, 3 ]), vec!(
|
||||
(2,
|
||||
format_strbuf!("11{}10{}1",
|
||||
"0".repeat(bits - 2),
|
||||
"0".repeat(bits - 1))),
|
||||
(4,
|
||||
format_strbuf!("3{}2{}1",
|
||||
"0".repeat(bits / 2 - 1),
|
||||
"0".repeat(bits / 2 - 1))),
|
||||
(10, match bits {
|
||||
32 => "55340232229718589441".to_strbuf(),
|
||||
16 => "12885032961".to_strbuf(),
|
||||
_ => fail!()
|
||||
}),
|
||||
(16,
|
||||
format_strbuf!("3{}2{}1",
|
||||
"0".repeat(bits / 4 - 1),
|
||||
"0".repeat(bits / 4 - 1)))
|
||||
)) )
|
||||
}
|
||||
|
||||
|
@ -1929,7 +1929,8 @@ mod biguint_tests {
|
|||
let &(ref n, ref rs) = num_pair;
|
||||
for str_pair in rs.iter() {
|
||||
let &(ref radix, ref str) = str_pair;
|
||||
assert_eq!(&n.to_str_radix(*radix), str);
|
||||
assert_eq!(n.to_str_radix(*radix).as_slice(),
|
||||
str.as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1941,7 +1942,9 @@ mod biguint_tests {
|
|||
let &(ref n, ref rs) = num_pair;
|
||||
for str_pair in rs.iter() {
|
||||
let &(ref radix, ref str) = str_pair;
|
||||
assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).unwrap());
|
||||
assert_eq!(n,
|
||||
&FromStrRadix::from_str_radix(str.as_slice(),
|
||||
*radix).unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -348,15 +348,15 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
fn test(c : Complex64, s: ~str) {
|
||||
assert_eq!(c.to_str(), s);
|
||||
fn test(c : Complex64, s: StrBuf) {
|
||||
assert_eq!(c.to_str().to_strbuf(), s);
|
||||
}
|
||||
test(_0_0i, "0+0i".to_owned());
|
||||
test(_1_0i, "1+0i".to_owned());
|
||||
test(_0_1i, "0+1i".to_owned());
|
||||
test(_1_1i, "1+1i".to_owned());
|
||||
test(_neg1_1i, "-1+1i".to_owned());
|
||||
test(-_neg1_1i, "1-1i".to_owned());
|
||||
test(_05_05i, "0.5+0.5i".to_owned());
|
||||
test(_0_0i, "0+0i".to_strbuf());
|
||||
test(_1_0i, "1+0i".to_strbuf());
|
||||
test(_0_1i, "0+1i".to_strbuf());
|
||||
test(_1_1i, "1+1i".to_strbuf());
|
||||
test(_neg1_1i, "-1+1i".to_strbuf());
|
||||
test(-_neg1_1i, "1-1i".to_strbuf());
|
||||
test(_05_05i, "0.5+0.5i".to_strbuf());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -555,16 +555,16 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_to_from_str() {
|
||||
fn test(r: Rational, s: ~str) {
|
||||
assert_eq!(FromStr::from_str(s), Some(r));
|
||||
assert_eq!(r.to_str(), s);
|
||||
fn test(r: Rational, s: StrBuf) {
|
||||
assert_eq!(FromStr::from_str(s.as_slice()), Some(r));
|
||||
assert_eq!(r.to_str().to_strbuf(), s);
|
||||
}
|
||||
test(_1, "1/1".to_owned());
|
||||
test(_0, "0/1".to_owned());
|
||||
test(_1_2, "1/2".to_owned());
|
||||
test(_3_2, "3/2".to_owned());
|
||||
test(_2, "2/1".to_owned());
|
||||
test(_neg1_2, "-1/2".to_owned());
|
||||
test(_1, "1/1".to_strbuf());
|
||||
test(_0, "0/1".to_strbuf());
|
||||
test(_1_2, "1/2".to_strbuf());
|
||||
test(_3_2, "3/2".to_strbuf());
|
||||
test(_2, "2/1".to_strbuf());
|
||||
test(_neg1_2, "-1/2".to_strbuf());
|
||||
}
|
||||
#[test]
|
||||
fn test_from_str_fail() {
|
||||
|
@ -581,30 +581,31 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_to_from_str_radix() {
|
||||
fn test(r: Rational, s: ~str, n: uint) {
|
||||
assert_eq!(FromStrRadix::from_str_radix(s, n), Some(r));
|
||||
assert_eq!(r.to_str_radix(n), s);
|
||||
fn test(r: Rational, s: StrBuf, n: uint) {
|
||||
assert_eq!(FromStrRadix::from_str_radix(s.to_owned(), n),
|
||||
Some(r));
|
||||
assert_eq!(r.to_str_radix(n).to_strbuf(), s);
|
||||
}
|
||||
fn test3(r: Rational, s: ~str) { test(r, s, 3) }
|
||||
fn test16(r: Rational, s: ~str) { test(r, s, 16) }
|
||||
fn test3(r: Rational, s: StrBuf) { test(r, s, 3) }
|
||||
fn test16(r: Rational, s: StrBuf) { test(r, s, 16) }
|
||||
|
||||
test3(_1, "1/1".to_owned());
|
||||
test3(_0, "0/1".to_owned());
|
||||
test3(_1_2, "1/2".to_owned());
|
||||
test3(_3_2, "10/2".to_owned());
|
||||
test3(_2, "2/1".to_owned());
|
||||
test3(_neg1_2, "-1/2".to_owned());
|
||||
test3(_neg1_2 / _2, "-1/11".to_owned());
|
||||
test3(_1, "1/1".to_strbuf());
|
||||
test3(_0, "0/1".to_strbuf());
|
||||
test3(_1_2, "1/2".to_strbuf());
|
||||
test3(_3_2, "10/2".to_strbuf());
|
||||
test3(_2, "2/1".to_strbuf());
|
||||
test3(_neg1_2, "-1/2".to_strbuf());
|
||||
test3(_neg1_2 / _2, "-1/11".to_strbuf());
|
||||
|
||||
test16(_1, "1/1".to_owned());
|
||||
test16(_0, "0/1".to_owned());
|
||||
test16(_1_2, "1/2".to_owned());
|
||||
test16(_3_2, "3/2".to_owned());
|
||||
test16(_2, "2/1".to_owned());
|
||||
test16(_neg1_2, "-1/2".to_owned());
|
||||
test16(_neg1_2 / _2, "-1/4".to_owned());
|
||||
test16(Ratio::new(13,15), "d/f".to_owned());
|
||||
test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_owned());
|
||||
test16(_1, "1/1".to_strbuf());
|
||||
test16(_0, "0/1".to_strbuf());
|
||||
test16(_1_2, "1/2".to_strbuf());
|
||||
test16(_3_2, "3/2".to_strbuf());
|
||||
test16(_2, "2/1".to_strbuf());
|
||||
test16(_neg1_2, "-1/2".to_strbuf());
|
||||
test16(_neg1_2 / _2, "-1/4".to_strbuf());
|
||||
test16(Ratio::new(13,15), "d/f".to_strbuf());
|
||||
test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_strbuf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -260,7 +260,7 @@ pub trait Rng {
|
|||
///
|
||||
/// println!("{}", task_rng().gen_ascii_str(10));
|
||||
/// ```
|
||||
fn gen_ascii_str(&mut self, len: uint) -> ~str {
|
||||
fn gen_ascii_str(&mut self, len: uint) -> StrBuf {
|
||||
static GEN_ASCII_STR_CHARSET: &'static [u8] = bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
||||
abcdefghijklmnopqrstuvwxyz\
|
||||
0123456789");
|
||||
|
@ -268,7 +268,7 @@ pub trait Rng {
|
|||
for _ in range(0, len) {
|
||||
s.push_char(self.choose(GEN_ASCII_STR_CHARSET) as char)
|
||||
}
|
||||
s.into_owned()
|
||||
s
|
||||
}
|
||||
|
||||
/// Choose an item randomly, failing if `values` is empty.
|
||||
|
|
|
@ -83,12 +83,12 @@ pub struct Program {
|
|||
/// If the regular expression requires a literal prefix in order to have a
|
||||
/// match, that prefix is stored here. (It's used in the VM to implement
|
||||
/// an optimization.)
|
||||
pub prefix: ~str,
|
||||
pub prefix: StrBuf,
|
||||
}
|
||||
|
||||
impl Program {
|
||||
/// Compiles a Regex given its AST.
|
||||
pub fn new(ast: parse::Ast) -> (Program, Vec<Option<~str>>) {
|
||||
pub fn new(ast: parse::Ast) -> (Program, Vec<Option<StrBuf>>) {
|
||||
let mut c = Compiler {
|
||||
insts: Vec::with_capacity(100),
|
||||
names: Vec::with_capacity(10),
|
||||
|
@ -113,7 +113,7 @@ impl Program {
|
|||
let Compiler { insts, names } = c;
|
||||
let prog = Program {
|
||||
insts: insts,
|
||||
prefix: pre.into_owned(),
|
||||
prefix: pre,
|
||||
};
|
||||
(prog, names)
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ impl Program {
|
|||
|
||||
struct Compiler<'r> {
|
||||
insts: Vec<Inst>,
|
||||
names: Vec<Option<~str>>,
|
||||
names: Vec<Option<StrBuf>>,
|
||||
}
|
||||
|
||||
// The compiler implemented here is extremely simple. Most of the complexity
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct Error {
|
|||
/// The *approximate* character index of where the error occurred.
|
||||
pub pos: uint,
|
||||
/// A message describing the error.
|
||||
pub msg: ~str,
|
||||
pub msg: StrBuf,
|
||||
}
|
||||
|
||||
impl fmt::Show for Error {
|
||||
|
@ -59,7 +59,7 @@ pub enum Ast {
|
|||
Begin(Flags),
|
||||
End(Flags),
|
||||
WordBoundary(Flags),
|
||||
Capture(uint, Option<~str>, Box<Ast>),
|
||||
Capture(uint, Option<StrBuf>, Box<Ast>),
|
||||
// Represent concatenation as a flat vector to avoid blowing the
|
||||
// stack in the compiler.
|
||||
Cat(Vec<Ast>),
|
||||
|
@ -104,7 +104,7 @@ impl Greed {
|
|||
#[deriving(Show)]
|
||||
enum BuildAst {
|
||||
Ast(Ast),
|
||||
Paren(Flags, uint, ~str), // '('
|
||||
Paren(Flags, uint, StrBuf), // '('
|
||||
Bar, // '|'
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ impl BuildAst {
|
|||
}
|
||||
}
|
||||
|
||||
fn capture_name(&self) -> Option<~str> {
|
||||
fn capture_name(&self) -> Option<StrBuf> {
|
||||
match *self {
|
||||
Paren(_, 0, _) => None,
|
||||
Paren(_, _, ref name) => {
|
||||
|
@ -185,7 +185,7 @@ struct Parser<'a> {
|
|||
// opening a capture group).
|
||||
caps: uint,
|
||||
// A set of all capture group names used only to detect duplicates.
|
||||
names: Vec<~str>,
|
||||
names: Vec<StrBuf>,
|
||||
}
|
||||
|
||||
pub fn parse(s: &str) -> Result<Ast, Error> {
|
||||
|
@ -222,7 +222,7 @@ impl<'a> Parser<'a> {
|
|||
self.caps += 1;
|
||||
self.stack.push(Paren(self.flags,
|
||||
self.caps,
|
||||
"".to_owned()))
|
||||
"".to_strbuf()))
|
||||
}
|
||||
}
|
||||
')' => {
|
||||
|
@ -470,7 +470,7 @@ impl<'a> Parser<'a> {
|
|||
FLAG_EMPTY
|
||||
};
|
||||
let name = self.slice(name_start, closer - 1);
|
||||
match find_class(ASCII_CLASSES, name) {
|
||||
match find_class(ASCII_CLASSES, name.as_slice()) {
|
||||
None => None,
|
||||
Some(ranges) => {
|
||||
self.chari = closer;
|
||||
|
@ -611,7 +611,7 @@ impl<'a> Parser<'a> {
|
|||
// character).
|
||||
fn parse_unicode_name(&mut self) -> Result<Ast, Error> {
|
||||
let negated = if self.cur() == 'P' { FLAG_NEGATED } else { FLAG_EMPTY };
|
||||
let mut name: ~str;
|
||||
let mut name: StrBuf;
|
||||
if self.peek_is(1, '{') {
|
||||
try!(self.expect('{'))
|
||||
let closer =
|
||||
|
@ -633,7 +633,7 @@ impl<'a> Parser<'a> {
|
|||
name = self.slice(self.chari + 1, self.chari + 2);
|
||||
self.chari += 1;
|
||||
}
|
||||
match find_class(UNICODE_CLASSES, name) {
|
||||
match find_class(UNICODE_CLASSES, name.as_slice()) {
|
||||
None => return self.err(format!(
|
||||
"Could not find Unicode class '{}'", name)),
|
||||
Some(ranges) => {
|
||||
|
@ -657,7 +657,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
let s = self.slice(start, end);
|
||||
match num::from_str_radix::<u32>(s, 8) {
|
||||
match num::from_str_radix::<u32>(s.as_slice(), 8) {
|
||||
Some(n) => Ok(Literal(try!(self.char_from_u32(n)), FLAG_EMPTY)),
|
||||
None => self.err(format!(
|
||||
"Could not parse '{}' as octal number.", s)),
|
||||
|
@ -679,7 +679,7 @@ impl<'a> Parser<'a> {
|
|||
Some(i) => i,
|
||||
};
|
||||
self.chari = closer;
|
||||
self.parse_hex_digits(self.slice(start, closer))
|
||||
self.parse_hex_digits(self.slice(start, closer).as_slice())
|
||||
}
|
||||
|
||||
// Parses a two-digit hex number.
|
||||
|
@ -690,7 +690,7 @@ impl<'a> Parser<'a> {
|
|||
let (start, end) = (self.chari, self.chari + 2);
|
||||
let bad = self.slice(start - 2, self.chars.len());
|
||||
try!(self.noteof(format!("Invalid hex escape sequence '{}'", bad)))
|
||||
self.parse_hex_digits(self.slice(start, end))
|
||||
self.parse_hex_digits(self.slice(start, end).as_slice())
|
||||
}
|
||||
|
||||
// Parses `s` as a hexadecimal number.
|
||||
|
@ -717,7 +717,7 @@ impl<'a> Parser<'a> {
|
|||
return self.err("Capture names must have at least 1 character.")
|
||||
}
|
||||
let name = self.slice(self.chari, closer);
|
||||
if !name.chars().all(is_valid_cap) {
|
||||
if !name.as_slice().chars().all(is_valid_cap) {
|
||||
return self.err(
|
||||
"Capture names can only have underscores, letters and digits.")
|
||||
}
|
||||
|
@ -771,7 +771,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
if self.cur() == ':' {
|
||||
// Save the old flags with the opening paren.
|
||||
self.stack.push(Paren(self.flags, 0, "".to_owned()));
|
||||
self.stack.push(Paren(self.flags, 0, "".to_strbuf()));
|
||||
}
|
||||
self.flags = flags;
|
||||
return Ok(())
|
||||
|
@ -892,7 +892,7 @@ impl<'a> Parser<'a> {
|
|||
fn err<T>(&self, msg: &str) -> Result<T, Error> {
|
||||
Err(Error {
|
||||
pos: self.chari,
|
||||
msg: msg.to_owned(),
|
||||
msg: msg.to_strbuf(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -911,8 +911,8 @@ impl<'a> Parser<'a> {
|
|||
*self.chars.get(self.chari)
|
||||
}
|
||||
|
||||
fn slice(&self, start: uint, end: uint) -> ~str {
|
||||
str::from_chars(self.chars.as_slice().slice(start, end))
|
||||
fn slice(&self, start: uint, end: uint) -> StrBuf {
|
||||
str::from_chars(self.chars.as_slice().slice(start, end)).to_strbuf()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use vm::{CaptureLocs, MatchKind, Exists, Location, Submatches};
|
|||
|
||||
/// Escapes all regular expression meta characters in `text` so that it may be
|
||||
/// safely used in a regular expression as a literal string.
|
||||
pub fn quote(text: &str) -> ~str {
|
||||
pub fn quote(text: &str) -> StrBuf {
|
||||
let mut quoted = StrBuf::with_capacity(text.len());
|
||||
for c in text.chars() {
|
||||
if parse::is_punct(c) {
|
||||
|
@ -28,7 +28,7 @@ pub fn quote(text: &str) -> ~str {
|
|||
}
|
||||
quoted.push_char(c);
|
||||
}
|
||||
quoted.into_owned()
|
||||
quoted
|
||||
}
|
||||
|
||||
/// Tests if the given regular expression matches somewhere in the text given.
|
||||
|
@ -107,9 +107,9 @@ pub struct Regex {
|
|||
/// See the comments for the `program` module in `lib.rs` for a more
|
||||
/// detailed explanation for what `regex!` requires.
|
||||
#[doc(hidden)]
|
||||
pub original: ~str,
|
||||
pub original: StrBuf,
|
||||
#[doc(hidden)]
|
||||
pub names: Vec<Option<~str>>,
|
||||
pub names: Vec<Option<StrBuf>>,
|
||||
#[doc(hidden)]
|
||||
pub p: MaybeNative,
|
||||
}
|
||||
|
@ -146,7 +146,10 @@ impl Regex {
|
|||
pub fn new(re: &str) -> Result<Regex, parse::Error> {
|
||||
let ast = try!(parse::parse(re));
|
||||
let (prog, names) = Program::new(ast);
|
||||
Ok(Regex { original: re.to_owned(), names: names, p: Dynamic(prog) })
|
||||
Ok(Regex {
|
||||
original: re.to_strbuf(),
|
||||
names: names, p: Dynamic(prog),
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns true if and only if the regex matches the string given.
|
||||
|
@ -404,7 +407,7 @@ impl Regex {
|
|||
/// ```
|
||||
///
|
||||
/// But anything satisfying the `Replacer` trait will work. For example,
|
||||
/// a closure of type `|&Captures| -> ~str` provides direct access to the
|
||||
/// a closure of type `|&Captures| -> StrBuf` provides direct access to the
|
||||
/// captures corresponding to a match. This allows one to access
|
||||
/// submatches easily:
|
||||
///
|
||||
|
@ -414,7 +417,7 @@ impl Regex {
|
|||
/// # use regex::Captures; fn main() {
|
||||
/// let re = regex!(r"([^,\s]+),\s+(\S+)");
|
||||
/// let result = re.replace("Springsteen, Bruce", |caps: &Captures| {
|
||||
/// format!("{} {}", caps.at(2), caps.at(1))
|
||||
/// format_strbuf!("{} {}", caps.at(2), caps.at(1))
|
||||
/// });
|
||||
/// assert_eq!(result.as_slice(), "Bruce Springsteen");
|
||||
/// # }
|
||||
|
@ -526,7 +529,7 @@ impl<'t> Replacer for &'t str {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Replacer for |&Captures|: 'a -> ~str {
|
||||
impl<'a> Replacer for |&Captures|: 'a -> StrBuf {
|
||||
fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
|
||||
Owned((*self)(caps).into_owned())
|
||||
}
|
||||
|
@ -605,7 +608,7 @@ impl<'r, 't> Iterator<&'t str> for RegexSplitsN<'r, 't> {
|
|||
pub struct Captures<'t> {
|
||||
text: &'t str,
|
||||
locs: CaptureLocs,
|
||||
named: Option<HashMap<~str, uint>>,
|
||||
named: Option<HashMap<StrBuf, uint>>,
|
||||
}
|
||||
|
||||
impl<'t> Captures<'t> {
|
||||
|
@ -624,7 +627,7 @@ impl<'t> Captures<'t> {
|
|||
match name {
|
||||
&None => {},
|
||||
&Some(ref name) => {
|
||||
named.insert(name.to_owned(), i);
|
||||
named.insert(name.to_strbuf(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -707,12 +710,14 @@ impl<'t> Captures<'t> {
|
|||
// How evil can you get?
|
||||
// FIXME: Don't use regexes for this. It's completely unnecessary.
|
||||
let re = Regex::new(r"(^|[^$]|\b)\$(\w+)").unwrap();
|
||||
let text = re.replace_all(text, |refs: &Captures| -> ~str {
|
||||
let text = re.replace_all(text, |refs: &Captures| -> StrBuf {
|
||||
let (pre, name) = (refs.at(1), refs.at(2));
|
||||
pre + match from_str::<uint>(name) {
|
||||
None => self.name(name).to_owned(),
|
||||
Some(i) => self.at(i).to_owned(),
|
||||
}
|
||||
format_strbuf!("{}{}",
|
||||
pre,
|
||||
match from_str::<uint>(name.as_slice()) {
|
||||
None => self.name(name).to_strbuf(),
|
||||
Some(i) => self.at(i).to_strbuf(),
|
||||
})
|
||||
});
|
||||
let re = Regex::new(r"\$\$").unwrap();
|
||||
re.replace_all(text.as_slice(), NoExpand("$"))
|
||||
|
|
|
@ -140,7 +140,7 @@ macro_rules! throughput(
|
|||
fn $name(b: &mut Bencher) {
|
||||
let text = gen_text($size);
|
||||
b.bytes = $size;
|
||||
b.iter(|| if $regex.is_match(text) { fail!("match") });
|
||||
b.iter(|| if $regex.is_match(text.as_slice()) { fail!("match") });
|
||||
}
|
||||
);
|
||||
)
|
||||
|
@ -151,7 +151,7 @@ fn medium() -> Regex { regex!("[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
|
|||
fn hard() -> Regex { regex!("[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
|
||||
|
||||
#[allow(deprecated_owned_vector)]
|
||||
fn gen_text(n: uint) -> ~str {
|
||||
fn gen_text(n: uint) -> StrBuf {
|
||||
let mut rng = task_rng();
|
||||
let mut bytes = rng.gen_ascii_str(n).into_bytes();
|
||||
for (i, b) in bytes.mut_iter().enumerate() {
|
||||
|
@ -159,7 +159,7 @@ fn gen_text(n: uint) -> ~str {
|
|||
*b = '\n' as u8
|
||||
}
|
||||
}
|
||||
str::from_utf8(bytes).unwrap().to_owned()
|
||||
str::from_utf8(bytes.as_slice()).unwrap().to_strbuf()
|
||||
}
|
||||
|
||||
throughput!(easy0_32, easy0(), 32)
|
||||
|
|
|
@ -105,8 +105,8 @@ struct NfaGen<'a> {
|
|||
cx: &'a ExtCtxt<'a>,
|
||||
sp: codemap::Span,
|
||||
prog: Program,
|
||||
names: Vec<Option<~str>>,
|
||||
original: ~str,
|
||||
names: Vec<Option<StrBuf>>,
|
||||
original: StrBuf,
|
||||
}
|
||||
|
||||
impl<'a> NfaGen<'a> {
|
||||
|
@ -119,7 +119,7 @@ impl<'a> NfaGen<'a> {
|
|||
|cx, name| match *name {
|
||||
Some(ref name) => {
|
||||
let name = name.as_slice();
|
||||
quote_expr!(cx, Some($name.to_owned()))
|
||||
quote_expr!(cx, Some($name.to_strbuf()))
|
||||
}
|
||||
None => cx.expr_none(self.sp),
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
|
|||
}
|
||||
|
||||
::regex::Regex {
|
||||
original: $regex.to_owned(),
|
||||
original: $regex.to_strbuf(),
|
||||
names: vec!$cap_names,
|
||||
p: ::regex::native::Native(exec),
|
||||
}
|
||||
|
@ -601,14 +601,14 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
|
|||
|
||||
/// Looks for a single string literal and returns it.
|
||||
/// Otherwise, logs an error with cx.span_err and returns None.
|
||||
fn parse(cx: &mut ExtCtxt, tts: &[ast::TokenTree]) -> Option<~str> {
|
||||
fn parse(cx: &mut ExtCtxt, tts: &[ast::TokenTree]) -> Option<StrBuf> {
|
||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(),
|
||||
Vec::from_slice(tts));
|
||||
let entry = cx.expand_expr(parser.parse_expr());
|
||||
let regex = match entry.node {
|
||||
ast::ExprLit(lit) => {
|
||||
match lit.node {
|
||||
ast::LitStr(ref s, _) => s.to_str(),
|
||||
ast::LitStr(ref s, _) => s.to_str().to_strbuf(),
|
||||
_ => {
|
||||
cx.span_err(entry.span, format!(
|
||||
"expected string literal but got `{}`",
|
||||
|
|
|
@ -327,7 +327,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::Item {
|
|||
pub fn main() {
|
||||
#![main]
|
||||
use std::slice::Vector;
|
||||
test::test_main_static(::std::os::args().as_slice(), TESTS);
|
||||
test::test_main_static_x(::std::os::args().as_slice(), TESTS);
|
||||
}
|
||||
)).unwrap();
|
||||
|
||||
|
|
|
@ -176,10 +176,6 @@ pub fn test(input: &str, libs: HashSet<Path>, mut test_args: Vec<StrBuf>) -> int
|
|||
let mut collector = Collector::new(input.to_strbuf(), libs, true, true);
|
||||
find_testable_code(input_str.as_slice(), &mut collector);
|
||||
test_args.unshift("rustdoctest".to_strbuf());
|
||||
testing::test_main(test_args.move_iter()
|
||||
.map(|x| x.to_str())
|
||||
.collect::<Vec<_>>()
|
||||
.as_slice(),
|
||||
collector.tests);
|
||||
testing::test_main(test_args.as_slice(), collector.tests);
|
||||
0
|
||||
}
|
||||
|
|
|
@ -92,10 +92,7 @@ pub fn run(input: &str,
|
|||
|
||||
test_args.unshift("rustdoctest".to_strbuf());
|
||||
|
||||
testing::test_main(test_args.move_iter()
|
||||
.map(|x| x.to_str())
|
||||
.collect::<Vec<_>>()
|
||||
.as_slice(),
|
||||
testing::test_main(test_args.as_slice(),
|
||||
collector.tests.move_iter().collect());
|
||||
0
|
||||
}
|
||||
|
@ -235,9 +232,9 @@ impl Collector {
|
|||
pub fn add_test(&mut self, test: StrBuf, should_fail: bool, no_run: bool, should_ignore: bool) {
|
||||
let name = if self.use_headers {
|
||||
let s = self.current_header.as_ref().map(|s| s.as_slice()).unwrap_or("");
|
||||
format!("{}_{}", s, self.cnt)
|
||||
format_strbuf!("{}_{}", s, self.cnt)
|
||||
} else {
|
||||
format!("{}_{}", self.names.connect("::"), self.cnt)
|
||||
format_strbuf!("{}_{}", self.names.connect("::"), self.cnt)
|
||||
};
|
||||
self.cnt += 1;
|
||||
let libs = self.libs.clone();
|
||||
|
|
|
@ -50,7 +50,7 @@ use std::strbuf::StrBuf;
|
|||
#[allow(missing_doc)]
|
||||
pub enum Identifier {
|
||||
Numeric(uint),
|
||||
AlphaNumeric(~str)
|
||||
AlphaNumeric(StrBuf)
|
||||
}
|
||||
|
||||
impl cmp::Ord for Identifier {
|
||||
|
@ -158,7 +158,7 @@ impl cmp::Ord for Version {
|
|||
}
|
||||
|
||||
fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
|
||||
-> (~str, Option<char>) {
|
||||
-> (StrBuf, Option<char>) {
|
||||
let mut buf = StrBuf::new();
|
||||
let mut ch = rdr.next();
|
||||
loop {
|
||||
|
@ -171,12 +171,12 @@ fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
|
|||
}
|
||||
}
|
||||
}
|
||||
(buf.into_owned(), ch)
|
||||
(buf, ch)
|
||||
}
|
||||
|
||||
fn take_num<T: Iterator<char>>(rdr: &mut T) -> Option<(uint, Option<char>)> {
|
||||
let (s, ch) = take_nonempty_prefix(rdr, char::is_digit);
|
||||
match from_str::<uint>(s) {
|
||||
match from_str::<uint>(s.as_slice()) {
|
||||
None => None,
|
||||
Some(i) => Some((i, ch))
|
||||
}
|
||||
|
@ -184,8 +184,8 @@ fn take_num<T: Iterator<char>>(rdr: &mut T) -> Option<(uint, Option<char>)> {
|
|||
|
||||
fn take_ident<T: Iterator<char>>(rdr: &mut T) -> Option<(Identifier, Option<char>)> {
|
||||
let (s,ch) = take_nonempty_prefix(rdr, char::is_alphanumeric);
|
||||
if s.chars().all(char::is_digit) {
|
||||
match from_str::<uint>(s) {
|
||||
if s.as_slice().chars().all(char::is_digit) {
|
||||
match from_str::<uint>(s.as_slice()) {
|
||||
None => None,
|
||||
Some(i) => Some((Numeric(i), ch))
|
||||
}
|
||||
|
@ -308,14 +308,14 @@ fn test_parse() {
|
|||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
|
||||
build: vec!(),
|
||||
}));
|
||||
assert!(parse(" 1.2.3-alpha1 ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
|
||||
build: vec!()
|
||||
}));
|
||||
assert!(parse("1.2.3+build5") == Some(Version {
|
||||
|
@ -323,37 +323,37 @@ fn test_parse() {
|
|||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
build: vec!(AlphaNumeric("build5".to_strbuf()))
|
||||
}));
|
||||
assert!(parse(" 1.2.3+build5 ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
build: vec!(AlphaNumeric("build5".to_strbuf()))
|
||||
}));
|
||||
assert!(parse("1.2.3-alpha1+build5") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
|
||||
build: vec!(AlphaNumeric("build5".to_strbuf()))
|
||||
}));
|
||||
assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
|
||||
build: vec!(AlphaNumeric("build5".to_strbuf()))
|
||||
}));
|
||||
assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(Numeric(1),AlphaNumeric("alpha1".to_owned()),Numeric(9)),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()),
|
||||
pre: vec!(Numeric(1),AlphaNumeric("alpha1".to_strbuf()),Numeric(9)),
|
||||
build: vec!(AlphaNumeric("build5".to_strbuf()),
|
||||
Numeric(7),
|
||||
AlphaNumeric("3aedf".to_owned()))
|
||||
AlphaNumeric("3aedf".to_strbuf()))
|
||||
}));
|
||||
|
||||
}
|
||||
|
@ -377,10 +377,14 @@ fn test_ne() {
|
|||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
assert_eq!(format!("{}", parse("1.2.3").unwrap()), "1.2.3".to_owned());
|
||||
assert_eq!(format!("{}", parse("1.2.3-alpha1").unwrap()), "1.2.3-alpha1".to_owned());
|
||||
assert_eq!(format!("{}", parse("1.2.3+build.42").unwrap()), "1.2.3+build.42".to_owned());
|
||||
assert_eq!(format!("{}", parse("1.2.3-alpha1+42").unwrap()), "1.2.3-alpha1+42".to_owned());
|
||||
assert_eq!(format_strbuf!("{}", parse("1.2.3").unwrap()),
|
||||
"1.2.3".to_strbuf());
|
||||
assert_eq!(format_strbuf!("{}", parse("1.2.3-alpha1").unwrap()),
|
||||
"1.2.3-alpha1".to_strbuf());
|
||||
assert_eq!(format_strbuf!("{}", parse("1.2.3+build.42").unwrap()),
|
||||
"1.2.3+build.42".to_strbuf());
|
||||
assert_eq!(format_strbuf!("{}", parse("1.2.3-alpha1+42").unwrap()),
|
||||
"1.2.3-alpha1+42".to_strbuf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1511,9 +1511,9 @@ mod tests {
|
|||
|
||||
fn make_rand_name() -> ~str {
|
||||
let mut rng = rand::task_rng();
|
||||
let n = "TEST".to_owned() + rng.gen_ascii_str(10u);
|
||||
assert!(getenv(n).is_none());
|
||||
n
|
||||
let n = format_strbuf!("TEST{}", rng.gen_ascii_str(10u).as_slice());
|
||||
assert!(getenv(n.as_slice()).is_none());
|
||||
n.into_owned()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -189,7 +189,7 @@ mod test {
|
|||
#[should_fail]
|
||||
fn test_futurefail() {
|
||||
let mut f = Future::spawn(proc() fail!());
|
||||
let _x: ~str = f.get();
|
||||
let _x: StrBuf = f.get();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -126,10 +126,12 @@ impl<T: Writer> Terminal<T> {
|
|||
/// Returns `Err()` on failure to open the terminfo database correctly.
|
||||
/// Also, in the event that the individual terminfo database entry can not
|
||||
/// be parsed.
|
||||
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
|
||||
pub fn new(out: T) -> Result<Terminal<T>, StrBuf> {
|
||||
let term = match os::getenv("TERM") {
|
||||
Some(t) => t,
|
||||
None => return Err("TERM environment variable undefined".to_owned())
|
||||
None => {
|
||||
return Err("TERM environment variable undefined".to_strbuf())
|
||||
}
|
||||
};
|
||||
|
||||
let mut file = match open(term) {
|
||||
|
@ -251,7 +253,8 @@ impl<T: Writer> Terminal<T> {
|
|||
cap = self.ti.strings.find_equiv(&("op"));
|
||||
}
|
||||
}
|
||||
let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()), |op| {
|
||||
let s = cap.map_or(Err("can't find terminfo capability \
|
||||
`sgr0`".to_strbuf()), |op| {
|
||||
expand(op.as_slice(), [], &mut Variables::new())
|
||||
});
|
||||
if s.is_ok() {
|
||||
|
|
|
@ -15,13 +15,13 @@ use collections::HashMap;
|
|||
/// A parsed terminfo database entry.
|
||||
pub struct TermInfo {
|
||||
/// Names for the terminal
|
||||
pub names: Vec<~str> ,
|
||||
pub names: Vec<StrBuf> ,
|
||||
/// Map of capability name to boolean value
|
||||
pub bools: HashMap<~str, bool>,
|
||||
pub bools: HashMap<StrBuf, bool>,
|
||||
/// Map of capability name to numeric value
|
||||
pub numbers: HashMap<~str, u16>,
|
||||
pub numbers: HashMap<StrBuf, u16>,
|
||||
/// Map of capability name to raw (unexpanded) string
|
||||
pub strings: HashMap<~str, Vec<u8> >
|
||||
pub strings: HashMap<StrBuf, Vec<u8> >
|
||||
}
|
||||
|
||||
pub mod searcher;
|
||||
|
|
|
@ -41,7 +41,7 @@ enum FormatState {
|
|||
#[allow(missing_doc)]
|
||||
#[deriving(Clone)]
|
||||
pub enum Param {
|
||||
String(~str),
|
||||
String(StrBuf),
|
||||
Number(int)
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl Variables {
|
|||
multiple capabilities for the same terminal.
|
||||
*/
|
||||
pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
||||
-> Result<Vec<u8> , ~str> {
|
||||
-> Result<Vec<u8> , StrBuf> {
|
||||
let mut state = Nothing;
|
||||
|
||||
// expanded cap will only rarely be larger than the cap itself
|
||||
|
@ -124,9 +124,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
match stack.pop().unwrap() {
|
||||
// if c is 0, use 0200 (128) for ncurses compatibility
|
||||
Number(c) => output.push(if c == 0 { 128 } else { c } as u8),
|
||||
_ => return Err("a non-char was used with %c".to_owned())
|
||||
_ => return Err("a non-char was used with %c".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'p' => state = PushParam,
|
||||
'P' => state = SetVar,
|
||||
'g' => state = GetVar,
|
||||
|
@ -135,112 +135,112 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
'l' => if stack.len() > 0 {
|
||||
match stack.pop().unwrap() {
|
||||
String(s) => stack.push(Number(s.len() as int)),
|
||||
_ => return Err("a non-str was used with %l".to_owned())
|
||||
_ => return Err("a non-str was used with %l".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'+' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x + y)),
|
||||
_ => return Err("non-numbers on stack with +".to_owned())
|
||||
_ => return Err("non-numbers on stack with +".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'-' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x - y)),
|
||||
_ => return Err("non-numbers on stack with -".to_owned())
|
||||
_ => return Err("non-numbers on stack with -".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'*' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x * y)),
|
||||
_ => return Err("non-numbers on stack with *".to_owned())
|
||||
_ => return Err("non-numbers on stack with *".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'/' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x / y)),
|
||||
_ => return Err("non-numbers on stack with /".to_owned())
|
||||
_ => return Err("non-numbers on stack with /".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'm' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x % y)),
|
||||
_ => return Err("non-numbers on stack with %".to_owned())
|
||||
_ => return Err("non-numbers on stack with %".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'&' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x & y)),
|
||||
_ => return Err("non-numbers on stack with &".to_owned())
|
||||
_ => return Err("non-numbers on stack with &".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'|' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x | y)),
|
||||
_ => return Err("non-numbers on stack with |".to_owned())
|
||||
_ => return Err("non-numbers on stack with |".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'^' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(x ^ y)),
|
||||
_ => return Err("non-numbers on stack with ^".to_owned())
|
||||
_ => return Err("non-numbers on stack with ^".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'=' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(if x == y { 1 }
|
||||
else { 0 })),
|
||||
_ => return Err("non-numbers on stack with =".to_owned())
|
||||
_ => return Err("non-numbers on stack with =".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'>' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(if x > y { 1 }
|
||||
else { 0 })),
|
||||
_ => return Err("non-numbers on stack with >".to_owned())
|
||||
_ => return Err("non-numbers on stack with >".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'<' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(y), Number(x)) => stack.push(Number(if x < y { 1 }
|
||||
else { 0 })),
|
||||
_ => return Err("non-numbers on stack with <".to_owned())
|
||||
_ => return Err("non-numbers on stack with <".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'A' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(0), Number(_)) => stack.push(Number(0)),
|
||||
(Number(_), Number(0)) => stack.push(Number(0)),
|
||||
(Number(_), Number(_)) => stack.push(Number(1)),
|
||||
_ => return Err("non-numbers on stack with logical and".to_owned())
|
||||
_ => return Err("non-numbers on stack with logical and".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'O' => if stack.len() > 1 {
|
||||
match (stack.pop().unwrap(), stack.pop().unwrap()) {
|
||||
(Number(0), Number(0)) => stack.push(Number(0)),
|
||||
(Number(_), Number(_)) => stack.push(Number(1)),
|
||||
_ => return Err("non-numbers on stack with logical or".to_owned())
|
||||
_ => return Err("non-numbers on stack with logical or".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'!' => if stack.len() > 0 {
|
||||
match stack.pop().unwrap() {
|
||||
Number(0) => stack.push(Number(1)),
|
||||
Number(_) => stack.push(Number(0)),
|
||||
_ => return Err("non-number on stack with logical not".to_owned())
|
||||
_ => return Err("non-number on stack with logical not".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'~' => if stack.len() > 0 {
|
||||
match stack.pop().unwrap() {
|
||||
Number(x) => stack.push(Number(!x)),
|
||||
_ => return Err("non-number on stack with %~".to_owned())
|
||||
_ => return Err("non-number on stack with %~".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'i' => match (mparams[0].clone(), mparams[1].clone()) {
|
||||
(Number(x), Number(y)) => {
|
||||
mparams[0] = Number(x+1);
|
||||
mparams[1] = Number(y+1);
|
||||
},
|
||||
(_, _) => return Err("first two params not numbers with %i".to_owned())
|
||||
(_, _) => return Err("first two params not numbers with %i".to_strbuf())
|
||||
},
|
||||
|
||||
// printf-style support for %doxXs
|
||||
|
@ -249,7 +249,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), flags);
|
||||
if res.is_err() { return res }
|
||||
output.push_all(res.unwrap().as_slice())
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
':'|'#'|' '|'.'|'0'..'9' => {
|
||||
let mut flags = Flags::new();
|
||||
let mut fstate = FormatStateFlags;
|
||||
|
@ -274,20 +274,24 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
Number(0) => state = SeekIfElse(0),
|
||||
Number(_) => (),
|
||||
_ => return Err("non-number on stack \
|
||||
with conditional".to_owned())
|
||||
with conditional".to_strbuf())
|
||||
}
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
'e' => state = SeekIfEnd(0),
|
||||
';' => (),
|
||||
|
||||
_ => return Err(format!("unrecognized format option {}", cur))
|
||||
_ => {
|
||||
return Err(format_strbuf!("unrecognized format \
|
||||
option {}",
|
||||
cur))
|
||||
}
|
||||
}
|
||||
},
|
||||
PushParam => {
|
||||
// params are 1-indexed
|
||||
stack.push(mparams[match char::to_digit(cur, 10) {
|
||||
Some(d) => d - 1,
|
||||
None => return Err("bad param number".to_owned())
|
||||
None => return Err("bad param number".to_strbuf())
|
||||
}].clone());
|
||||
},
|
||||
SetVar => {
|
||||
|
@ -295,14 +299,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
if stack.len() > 0 {
|
||||
let idx = (cur as u8) - ('A' as u8);
|
||||
vars.sta[idx as uint] = stack.pop().unwrap();
|
||||
} else { return Err("stack is empty".to_owned()) }
|
||||
} else { return Err("stack is empty".to_strbuf()) }
|
||||
} else if cur >= 'a' && cur <= 'z' {
|
||||
if stack.len() > 0 {
|
||||
let idx = (cur as u8) - ('a' as u8);
|
||||
vars.dyn[idx as uint] = stack.pop().unwrap();
|
||||
} else { return Err("stack is empty".to_owned()) }
|
||||
} else { return Err("stack is empty".to_strbuf()) }
|
||||
} else {
|
||||
return Err("bad variable name in %P".to_owned());
|
||||
return Err("bad variable name in %P".to_strbuf());
|
||||
}
|
||||
},
|
||||
GetVar => {
|
||||
|
@ -313,7 +317,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
let idx = (cur as u8) - ('a' as u8);
|
||||
stack.push(vars.dyn[idx as uint].clone());
|
||||
} else {
|
||||
return Err("bad variable name in %g".to_owned());
|
||||
return Err("bad variable name in %g".to_strbuf());
|
||||
}
|
||||
},
|
||||
CharConstant => {
|
||||
|
@ -322,7 +326,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
},
|
||||
CharClose => {
|
||||
if cur != '\'' {
|
||||
return Err("malformed character constant".to_owned());
|
||||
return Err("malformed character constant".to_strbuf());
|
||||
}
|
||||
},
|
||||
IntConstant(i) => {
|
||||
|
@ -335,7 +339,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
state = IntConstant(i*10 + (cur as int - '0' as int));
|
||||
old_state = Nothing;
|
||||
}
|
||||
_ => return Err("bad int constant".to_owned())
|
||||
_ => return Err("bad int constant".to_strbuf())
|
||||
}
|
||||
}
|
||||
FormatPattern(ref mut flags, ref mut fstate) => {
|
||||
|
@ -346,7 +350,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
if res.is_err() { return res }
|
||||
output.push_all(res.unwrap().as_slice());
|
||||
old_state = state; // will cause state to go to Nothing
|
||||
} else { return Err("stack is empty".to_owned()) },
|
||||
} else { return Err("stack is empty".to_strbuf()) },
|
||||
(FormatStateFlags,'#') => {
|
||||
flags.alternate = true;
|
||||
}
|
||||
|
@ -369,7 +373,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
(FormatStateWidth,'0'..'9') => {
|
||||
let old = flags.width;
|
||||
flags.width = flags.width * 10 + (cur as uint - '0' as uint);
|
||||
if flags.width < old { return Err("format width overflow".to_owned()) }
|
||||
if flags.width < old { return Err("format width overflow".to_strbuf()) }
|
||||
}
|
||||
(FormatStateWidth,'.') => {
|
||||
*fstate = FormatStatePrecision;
|
||||
|
@ -378,10 +382,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
|
|||
let old = flags.precision;
|
||||
flags.precision = flags.precision * 10 + (cur as uint - '0' as uint);
|
||||
if flags.precision < old {
|
||||
return Err("format precision overflow".to_owned())
|
||||
return Err("format precision overflow".to_strbuf())
|
||||
}
|
||||
}
|
||||
_ => return Err("invalid format specifier".to_owned())
|
||||
_ => return Err("invalid format specifier".to_strbuf())
|
||||
}
|
||||
}
|
||||
SeekIfElse(level) => {
|
||||
|
@ -479,7 +483,7 @@ impl FormatOp {
|
|||
}
|
||||
}
|
||||
|
||||
fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,~str> {
|
||||
fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,StrBuf> {
|
||||
let mut s = match val {
|
||||
Number(d) => {
|
||||
let s = match (op, flags.sign) {
|
||||
|
@ -488,7 +492,9 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,~str> {
|
|||
(FormatOctal, _) => format!("{:o}", d).into_bytes(),
|
||||
(FormatHex, _) => format!("{:x}", d).into_bytes(),
|
||||
(FormatHEX, _) => format!("{:X}", d).into_bytes(),
|
||||
(FormatString, _) => return Err("non-number on stack with %s".to_owned()),
|
||||
(FormatString, _) => {
|
||||
return Err("non-number on stack with %s".to_strbuf())
|
||||
}
|
||||
};
|
||||
let mut s: Vec<u8> = s.move_iter().collect();
|
||||
if flags.precision > s.len() {
|
||||
|
@ -543,7 +549,8 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,~str> {
|
|||
s
|
||||
}
|
||||
_ => {
|
||||
return Err(format!("non-string on stack with %{}", op.to_char()))
|
||||
return Err(format_strbuf!("non-string on stack with %{}",
|
||||
op.to_char()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -600,7 +607,7 @@ mod test {
|
|||
assert!(res.is_err(),
|
||||
"Op {} succeeded incorrectly with 0 stack entries", *cap);
|
||||
let p = if *cap == "%s" || *cap == "%l" {
|
||||
String("foo".to_owned())
|
||||
String("foo".to_strbuf())
|
||||
} else {
|
||||
Number(97)
|
||||
};
|
||||
|
@ -678,10 +685,12 @@ mod test {
|
|||
let mut varstruct = Variables::new();
|
||||
let vars = &mut varstruct;
|
||||
assert_eq!(expand(bytes!("%p1%s%p2%2s%p3%2s%p4%.2s"),
|
||||
[String("foo".to_owned()), String("foo".to_owned()),
|
||||
String("f".to_owned()), String("foo".to_owned())], vars),
|
||||
[String("foo".to_strbuf()),
|
||||
String("foo".to_strbuf()),
|
||||
String("f".to_strbuf()),
|
||||
String("foo".to_strbuf())], vars),
|
||||
Ok(bytes!("foofoo ffo").iter().map(|x| *x).collect()));
|
||||
assert_eq!(expand(bytes!("%p1%:-4.2s"), [String("foo".to_owned())], vars),
|
||||
assert_eq!(expand(bytes!("%p1%:-4.2s"), [String("foo".to_strbuf())], vars),
|
||||
Ok(bytes!("fo ").iter().map(|x| *x).collect()));
|
||||
|
||||
assert_eq!(expand(bytes!("%p1%d%p1%.3d%p1%5d%p1%:+d"), [Number(1)], vars),
|
||||
|
|
|
@ -160,9 +160,12 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs
|
|||
|
||||
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
|
||||
pub fn parse(file: &mut io::Reader, longnames: bool)
|
||||
-> Result<Box<TermInfo>, ~str> {
|
||||
-> Result<Box<TermInfo>, StrBuf> {
|
||||
macro_rules! try( ($e:expr) => (
|
||||
match $e { Ok(e) => e, Err(e) => return Err(format!("{}", e)) }
|
||||
match $e {
|
||||
Ok(e) => e,
|
||||
Err(e) => return Err(format_strbuf!("{}", e))
|
||||
}
|
||||
) )
|
||||
|
||||
let bnames;
|
||||
|
@ -182,8 +185,10 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
// Check magic number
|
||||
let magic = try!(file.read_le_u16());
|
||||
if magic != 0x011A {
|
||||
return Err(format!("invalid magic number: expected {:x} but found {:x}",
|
||||
0x011A, magic as uint));
|
||||
return Err(format_strbuf!("invalid magic number: expected {:x} but \
|
||||
found {:x}",
|
||||
0x011A,
|
||||
magic as uint));
|
||||
}
|
||||
|
||||
let names_bytes = try!(file.read_le_i16()) as int;
|
||||
|
@ -195,24 +200,30 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
assert!(names_bytes > 0);
|
||||
|
||||
if (bools_bytes as uint) > boolnames.len() {
|
||||
return Err("incompatible file: more booleans than expected".to_owned());
|
||||
return Err("incompatible file: more booleans than \
|
||||
expected".to_strbuf());
|
||||
}
|
||||
|
||||
if (numbers_count as uint) > numnames.len() {
|
||||
return Err("incompatible file: more numbers than expected".to_owned());
|
||||
return Err("incompatible file: more numbers than \
|
||||
expected".to_strbuf());
|
||||
}
|
||||
|
||||
if (string_offsets_count as uint) > stringnames.len() {
|
||||
return Err("incompatible file: more string offsets than expected".to_owned());
|
||||
return Err("incompatible file: more string offsets than \
|
||||
expected".to_strbuf());
|
||||
}
|
||||
|
||||
// don't read NUL
|
||||
let bytes = try!(file.read_exact(names_bytes as uint - 1));
|
||||
let names_str = match str::from_utf8(bytes.as_slice()) {
|
||||
Some(s) => s.to_owned(), None => return Err("input not utf-8".to_owned()),
|
||||
Some(s) => s.to_owned(),
|
||||
None => return Err("input not utf-8".to_strbuf()),
|
||||
};
|
||||
|
||||
let term_names: Vec<~str> = names_str.split('|').map(|s| s.to_owned()).collect();
|
||||
let term_names: Vec<StrBuf> = names_str.split('|')
|
||||
.map(|s| s.to_strbuf())
|
||||
.collect();
|
||||
|
||||
try!(file.read_byte()); // consume NUL
|
||||
|
||||
|
@ -221,7 +232,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
for i in range(0, bools_bytes) {
|
||||
let b = try!(file.read_byte());
|
||||
if b == 1 {
|
||||
bools_map.insert(bnames[i as uint].to_owned(), true);
|
||||
bools_map.insert(bnames[i as uint].to_strbuf(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +246,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
for i in range(0, numbers_count) {
|
||||
let n = try!(file.read_le_u16());
|
||||
if n != 0xFFFF {
|
||||
numbers_map.insert(nnames[i as uint].to_owned(), n);
|
||||
numbers_map.insert(nnames[i as uint].to_strbuf(), n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +262,8 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
let string_table = try!(file.read_exact(string_table_bytes as uint));
|
||||
|
||||
if string_table.len() != string_table_bytes as uint {
|
||||
return Err("error: hit EOF before end of string table".to_owned());
|
||||
return Err("error: hit EOF before end of string \
|
||||
table".to_strbuf());
|
||||
}
|
||||
|
||||
for (i, v) in string_offsets.iter().enumerate() {
|
||||
|
@ -269,7 +281,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
if offset == 0xFFFE {
|
||||
// undocumented: FFFE indicates cap@, which means the capability is not present
|
||||
// unsure if the handling for this is correct
|
||||
string_map.insert(name.to_owned(), Vec::new());
|
||||
string_map.insert(name.to_strbuf(), Vec::new());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -279,13 +291,14 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
.iter().position(|&b| b == 0);
|
||||
match nulpos {
|
||||
Some(len) => {
|
||||
string_map.insert(name.to_owned(),
|
||||
string_map.insert(name.to_strbuf(),
|
||||
Vec::from_slice(
|
||||
string_table.slice(offset as uint,
|
||||
offset as uint + len)))
|
||||
},
|
||||
None => {
|
||||
return Err("invalid file: missing NUL in string_table".to_owned());
|
||||
return Err("invalid file: missing NUL in \
|
||||
string_table".to_strbuf());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -303,12 +316,12 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
|
|||
/// Create a dummy TermInfo struct for msys terminals
|
||||
pub fn msys_terminfo() -> Box<TermInfo> {
|
||||
let mut strings = HashMap::new();
|
||||
strings.insert("sgr0".to_owned(), Vec::from_slice(bytes!("\x1b[0m")));
|
||||
strings.insert("bold".to_owned(), Vec::from_slice(bytes!("\x1b[1m")));
|
||||
strings.insert("setaf".to_owned(), Vec::from_slice(bytes!("\x1b[3%p1%dm")));
|
||||
strings.insert("setab".to_owned(), Vec::from_slice(bytes!("\x1b[4%p1%dm")));
|
||||
strings.insert("sgr0".to_strbuf(), Vec::from_slice(bytes!("\x1b[0m")));
|
||||
strings.insert("bold".to_strbuf(), Vec::from_slice(bytes!("\x1b[1m")));
|
||||
strings.insert("setaf".to_strbuf(), Vec::from_slice(bytes!("\x1b[3%p1%dm")));
|
||||
strings.insert("setab".to_strbuf(), Vec::from_slice(bytes!("\x1b[4%p1%dm")));
|
||||
box TermInfo {
|
||||
names: vec!("cygwin".to_owned()), // msys is a fork of an older cygwin version
|
||||
names: vec!("cygwin".to_strbuf()), // msys is a fork of an older cygwin version
|
||||
bools: HashMap::new(),
|
||||
numbers: HashMap::new(),
|
||||
strings: strings
|
||||
|
|
|
@ -76,15 +76,17 @@ pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> {
|
|||
}
|
||||
|
||||
/// Return open file for `term`
|
||||
pub fn open(term: &str) -> Result<File, ~str> {
|
||||
pub fn open(term: &str) -> Result<File, StrBuf> {
|
||||
match get_dbpath_for_term(term) {
|
||||
Some(x) => {
|
||||
match File::open(x) {
|
||||
Ok(file) => Ok(file),
|
||||
Err(e) => Err(format!("error opening file: {}", e)),
|
||||
Err(e) => Err(format_strbuf!("error opening file: {}", e)),
|
||||
}
|
||||
}
|
||||
None => Err(format!("could not find terminfo entry for {}", term))
|
||||
None => {
|
||||
Err(format_strbuf!("could not find terminfo entry for {}", term))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,14 +97,14 @@ fn test_get_dbpath_for_term() {
|
|||
// note: current tests won't work with non-standard terminfo hierarchies (e.g. OS X's)
|
||||
use std::os::{setenv, unsetenv};
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
fn x(t: &str) -> ~str {
|
||||
fn x(t: &str) -> StrBuf {
|
||||
let p = get_dbpath_for_term(t).expect("no terminfo entry found");
|
||||
p.as_str().unwrap().to_owned()
|
||||
p.as_str().unwrap().to_strbuf()
|
||||
};
|
||||
assert!(x("screen") == "/usr/share/terminfo/s/screen".to_owned());
|
||||
assert!(x("screen") == "/usr/share/terminfo/s/screen".to_strbuf());
|
||||
assert!(get_dbpath_for_term("") == None);
|
||||
setenv("TERMINFO_DIRS", ":");
|
||||
assert!(x("screen") == "/usr/share/terminfo/s/screen".to_owned());
|
||||
assert!(x("screen") == "/usr/share/terminfo/s/screen".to_strbuf());
|
||||
unsetenv("TERMINFO_DIRS");
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ pub mod test {
|
|||
MetricChange, Improvement, Regression, LikelyNoise,
|
||||
StaticTestFn, StaticTestName, DynTestName, DynTestFn,
|
||||
run_test, test_main, test_main_static, filter_tests,
|
||||
parse_opts, StaticBenchFn};
|
||||
parse_opts, StaticBenchFn, test_main_static_x};
|
||||
}
|
||||
|
||||
pub mod stats;
|
||||
|
@ -83,7 +83,7 @@ pub mod stats;
|
|||
#[deriving(Clone)]
|
||||
pub enum TestName {
|
||||
StaticTestName(&'static str),
|
||||
DynTestName(~str)
|
||||
DynTestName(StrBuf)
|
||||
}
|
||||
impl fmt::Show for TestName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -98,20 +98,20 @@ impl fmt::Show for TestName {
|
|||
enum NamePadding { PadNone, PadOnLeft, PadOnRight }
|
||||
|
||||
impl TestDesc {
|
||||
fn padded_name(&self, column_count: uint, align: NamePadding) -> ~str {
|
||||
fn padded_name(&self, column_count: uint, align: NamePadding) -> StrBuf {
|
||||
use std::num::Saturating;
|
||||
let mut name = StrBuf::from_str(self.name.to_str());
|
||||
let fill = column_count.saturating_sub(name.len());
|
||||
let mut pad = StrBuf::from_owned_str(" ".repeat(fill));
|
||||
match align {
|
||||
PadNone => name.into_owned(),
|
||||
PadNone => name,
|
||||
PadOnLeft => {
|
||||
pad.push_str(name.as_slice());
|
||||
pad.into_owned()
|
||||
pad
|
||||
}
|
||||
PadOnRight => {
|
||||
name.push_str(pad.as_slice());
|
||||
name.into_owned()
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ impl Metric {
|
|||
}
|
||||
|
||||
#[deriving(Eq)]
|
||||
pub struct MetricMap(TreeMap<~str,Metric>);
|
||||
pub struct MetricMap(TreeMap<StrBuf,Metric>);
|
||||
|
||||
impl Clone for MetricMap {
|
||||
fn clone(&self) -> MetricMap {
|
||||
|
@ -206,11 +206,11 @@ pub enum MetricChange {
|
|||
Regression(f64)
|
||||
}
|
||||
|
||||
pub type MetricDiff = TreeMap<~str,MetricChange>;
|
||||
pub type MetricDiff = TreeMap<StrBuf,MetricChange>;
|
||||
|
||||
// The default console test runner. It accepts the command line
|
||||
// arguments and a vector of test_descs.
|
||||
pub fn test_main(args: &[~str], tests: Vec<TestDescAndFn> ) {
|
||||
pub fn test_main(args: &[StrBuf], tests: Vec<TestDescAndFn> ) {
|
||||
let opts =
|
||||
match parse_opts(args) {
|
||||
Some(Ok(o)) => o,
|
||||
|
@ -231,7 +231,7 @@ pub fn test_main(args: &[~str], tests: Vec<TestDescAndFn> ) {
|
|||
// a ~[TestDescAndFn] is used in order to effect ownership-transfer
|
||||
// semantics into parallel test runners, which in turn requires a ~[]
|
||||
// rather than a &[].
|
||||
pub fn test_main_static(args: &[~str], tests: &[TestDescAndFn]) {
|
||||
pub fn test_main_static(args: &[StrBuf], tests: &[TestDescAndFn]) {
|
||||
let owned_tests = tests.iter().map(|t| {
|
||||
match t.testfn {
|
||||
StaticTestFn(f) =>
|
||||
|
@ -248,8 +248,16 @@ pub fn test_main_static(args: &[~str], tests: &[TestDescAndFn]) {
|
|||
test_main(args, owned_tests)
|
||||
}
|
||||
|
||||
pub fn test_main_static_x(args: &[~str], tests: &[TestDescAndFn]) {
|
||||
test_main_static(args.iter()
|
||||
.map(|x| x.to_strbuf())
|
||||
.collect::<Vec<_>>()
|
||||
.as_slice(),
|
||||
tests)
|
||||
}
|
||||
|
||||
pub struct TestOpts {
|
||||
pub filter: Option<~str>,
|
||||
pub filter: Option<StrBuf>,
|
||||
pub run_ignored: bool,
|
||||
pub run_tests: bool,
|
||||
pub run_benchmarks: bool,
|
||||
|
@ -280,7 +288,7 @@ impl TestOpts {
|
|||
}
|
||||
|
||||
/// Result of parsing the options.
|
||||
pub type OptRes = Result<TestOpts, ~str>;
|
||||
pub type OptRes = Result<TestOpts, StrBuf>;
|
||||
|
||||
fn optgroups() -> Vec<getopts::OptGroup> {
|
||||
vec!(getopts::optflag("", "ignored", "Run ignored tests"),
|
||||
|
@ -337,20 +345,30 @@ Test Attributes:
|
|||
}
|
||||
|
||||
// Parses command line arguments into test options
|
||||
pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
|
||||
pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
|
||||
let args_ = args.tail();
|
||||
let matches =
|
||||
match getopts::getopts(args_, optgroups().as_slice()) {
|
||||
match getopts::getopts(args_.iter()
|
||||
.map(|x| x.to_owned())
|
||||
.collect::<Vec<_>>()
|
||||
.as_slice(),
|
||||
optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => return Some(Err(f.to_err_msg()))
|
||||
Err(f) => return Some(Err(f.to_err_msg().to_strbuf()))
|
||||
};
|
||||
|
||||
if matches.opt_present("h") { usage(args[0], "h"); return None; }
|
||||
if matches.opt_present("help") { usage(args[0], "help"); return None; }
|
||||
if matches.opt_present("h") {
|
||||
usage(args[0].as_slice(), "h");
|
||||
return None;
|
||||
}
|
||||
if matches.opt_present("help") {
|
||||
usage(args[0].as_slice(), "help");
|
||||
return None;
|
||||
}
|
||||
|
||||
let filter =
|
||||
if matches.free.len() > 0 {
|
||||
Some((*matches.free.get(0)).clone())
|
||||
Some((*matches.free.get(0)).to_strbuf())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -374,7 +392,7 @@ pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
|
|||
let save_metrics = save_metrics.map(|s| Path::new(s));
|
||||
|
||||
let test_shard = matches.opt_str("test-shard");
|
||||
let test_shard = opt_shard(test_shard);
|
||||
let test_shard = opt_shard(test_shard.map(|x| x.to_strbuf()));
|
||||
|
||||
let mut nocapture = matches.opt_present("nocapture");
|
||||
if !nocapture {
|
||||
|
@ -397,11 +415,11 @@ pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
|
|||
Some(Ok(test_opts))
|
||||
}
|
||||
|
||||
pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
|
||||
pub fn opt_shard(maybestr: Option<StrBuf>) -> Option<(uint,uint)> {
|
||||
match maybestr {
|
||||
None => None,
|
||||
Some(s) => {
|
||||
let mut it = s.split('.');
|
||||
let mut it = s.as_slice().split('.');
|
||||
match (it.next().and_then(from_str), it.next().and_then(from_str), it.next()) {
|
||||
(Some(a), Some(b), None) => Some((a, b)),
|
||||
_ => None,
|
||||
|
@ -567,9 +585,9 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
None => Ok(()),
|
||||
Some(ref mut o) => {
|
||||
let s = format!("{} {}\n", match *result {
|
||||
TrOk => "ok".to_owned(),
|
||||
TrFailed => "failed".to_owned(),
|
||||
TrIgnored => "ignored".to_owned(),
|
||||
TrOk => "ok".to_strbuf(),
|
||||
TrFailed => "failed".to_strbuf(),
|
||||
TrIgnored => "ignored".to_strbuf(),
|
||||
TrMetrics(ref mm) => fmt_metrics(mm),
|
||||
TrBench(ref bs) => fmt_bench_samples(bs)
|
||||
}, test.name.to_str());
|
||||
|
@ -696,25 +714,25 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fmt_metrics(mm: &MetricMap) -> ~str {
|
||||
pub fn fmt_metrics(mm: &MetricMap) -> StrBuf {
|
||||
let MetricMap(ref mm) = *mm;
|
||||
let v : Vec<~str> = mm.iter()
|
||||
.map(|(k,v)| format!("{}: {} (+/- {})",
|
||||
let v : Vec<StrBuf> = mm.iter()
|
||||
.map(|(k,v)| format_strbuf!("{}: {} (+/- {})",
|
||||
*k,
|
||||
v.value as f64,
|
||||
v.noise as f64))
|
||||
.collect();
|
||||
v.connect(", ")
|
||||
v.connect(", ").to_strbuf()
|
||||
}
|
||||
|
||||
pub fn fmt_bench_samples(bs: &BenchSamples) -> ~str {
|
||||
pub fn fmt_bench_samples(bs: &BenchSamples) -> StrBuf {
|
||||
if bs.mb_s != 0 {
|
||||
format!("{:>9} ns/iter (+/- {}) = {} MB/s",
|
||||
format_strbuf!("{:>9} ns/iter (+/- {}) = {} MB/s",
|
||||
bs.ns_iter_summ.median as uint,
|
||||
(bs.ns_iter_summ.max - bs.ns_iter_summ.min) as uint,
|
||||
bs.mb_s)
|
||||
} else {
|
||||
format!("{:>9} ns/iter (+/- {})",
|
||||
format_strbuf!("{:>9} ns/iter (+/- {})",
|
||||
bs.ns_iter_summ.median as uint,
|
||||
(bs.ns_iter_summ.max - bs.ns_iter_summ.min) as uint)
|
||||
}
|
||||
|
@ -738,8 +756,10 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
let tname = test.name.to_str();
|
||||
let MetricMap(mm) = mm;
|
||||
for (k,v) in mm.iter() {
|
||||
st.metrics.insert_metric(tname + "." + *k,
|
||||
v.value, v.noise);
|
||||
st.metrics
|
||||
.insert_metric(tname + "." + k.as_slice(),
|
||||
v.value,
|
||||
v.noise);
|
||||
}
|
||||
st.measured += 1
|
||||
}
|
||||
|
@ -924,7 +944,7 @@ pub fn filter_tests(
|
|||
} else {
|
||||
let filter_str = match opts.filter {
|
||||
Some(ref f) => (*f).clone(),
|
||||
None => "".to_owned()
|
||||
None => "".to_strbuf()
|
||||
};
|
||||
|
||||
fn filter_fn(test: TestDescAndFn, filter_str: &str) ->
|
||||
|
@ -936,7 +956,9 @@ pub fn filter_tests(
|
|||
}
|
||||
}
|
||||
|
||||
filtered.move_iter().filter_map(|x| filter_fn(x, filter_str)).collect()
|
||||
filtered.move_iter()
|
||||
.filter_map(|x| filter_fn(x, filter_str.as_slice()))
|
||||
.collect()
|
||||
};
|
||||
|
||||
// Maybe pull out the ignored test and unignore them
|
||||
|
@ -995,8 +1017,8 @@ pub fn run_test(opts: &TestOpts,
|
|||
let stdout = ChanWriter::new(tx.clone());
|
||||
let stderr = ChanWriter::new(tx);
|
||||
let mut task = TaskBuilder::new().named(match desc.name {
|
||||
DynTestName(ref name) => name.clone().into_maybe_owned(),
|
||||
StaticTestName(name) => name.into_maybe_owned(),
|
||||
DynTestName(ref name) => name.clone().to_owned(),
|
||||
StaticTestName(name) => name.to_owned(),
|
||||
});
|
||||
if nocapture {
|
||||
drop((stdout, stderr));
|
||||
|
@ -1091,7 +1113,14 @@ impl MetricMap {
|
|||
pub fn save(&self, p: &Path) -> io::IoResult<()> {
|
||||
let mut file = try!(File::create(p));
|
||||
let MetricMap(ref map) = *self;
|
||||
map.to_json().to_pretty_writer(&mut file)
|
||||
|
||||
// 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.to_json().to_pretty_writer(&mut file)
|
||||
}
|
||||
|
||||
/// Compare against another MetricMap. Optionally compare all
|
||||
|
@ -1170,7 +1199,7 @@ impl MetricMap {
|
|||
noise: noise
|
||||
};
|
||||
let MetricMap(ref mut map) = *self;
|
||||
map.insert(name.to_owned(), m);
|
||||
map.insert(name.to_strbuf(), m);
|
||||
}
|
||||
|
||||
/// Attempt to "ratchet" an external metric file. This involves loading
|
||||
|
@ -1416,17 +1445,19 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn first_free_arg_should_be_a_filter() {
|
||||
let args = vec!("progname".to_owned(), "filter".to_owned());
|
||||
let args = vec!("progname".to_strbuf(), "filter".to_strbuf());
|
||||
let opts = match parse_opts(args.as_slice()) {
|
||||
Some(Ok(o)) => o,
|
||||
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
|
||||
};
|
||||
assert!("filter" == opts.filter.clone().unwrap());
|
||||
assert!("filter" == opts.filter.clone().unwrap().as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_ignored_flag() {
|
||||
let args = vec!("progname".to_owned(), "filter".to_owned(), "--ignored".to_owned());
|
||||
let args = vec!("progname".to_strbuf(),
|
||||
"filter".to_strbuf(),
|
||||
"--ignored".to_strbuf());
|
||||
let opts = match parse_opts(args.as_slice()) {
|
||||
Some(Ok(o)) => o,
|
||||
_ => fail!("Malformed arg in parse_ignored_flag")
|
||||
|
@ -1463,7 +1494,8 @@ mod tests {
|
|||
let filtered = filter_tests(&opts, tests);
|
||||
|
||||
assert_eq!(filtered.len(), 1);
|
||||
assert_eq!(filtered.get(0).desc.name.to_str(), "1".to_owned());
|
||||
assert_eq!(filtered.get(0).desc.name.to_str().to_strbuf(),
|
||||
"1".to_strbuf());
|
||||
assert!(filtered.get(0).desc.ignore == false);
|
||||
}
|
||||
|
||||
|
@ -1473,12 +1505,15 @@ mod tests {
|
|||
opts.run_tests = true;
|
||||
|
||||
let names =
|
||||
vec!("sha1::test".to_owned(), "int::test_to_str".to_owned(), "int::test_pow".to_owned(),
|
||||
"test::do_not_run_ignored_tests".to_owned(),
|
||||
"test::ignored_tests_result_in_ignored".to_owned(),
|
||||
"test::first_free_arg_should_be_a_filter".to_owned(),
|
||||
"test::parse_ignored_flag".to_owned(), "test::filter_for_ignored_option".to_owned(),
|
||||
"test::sort_tests".to_owned());
|
||||
vec!("sha1::test".to_strbuf(),
|
||||
"int::test_to_str".to_strbuf(),
|
||||
"int::test_pow".to_strbuf(),
|
||||
"test::do_not_run_ignored_tests".to_strbuf(),
|
||||
"test::ignored_tests_result_in_ignored".to_strbuf(),
|
||||
"test::first_free_arg_should_be_a_filter".to_strbuf(),
|
||||
"test::parse_ignored_flag".to_strbuf(),
|
||||
"test::filter_for_ignored_option".to_strbuf(),
|
||||
"test::sort_tests".to_strbuf());
|
||||
let tests =
|
||||
{
|
||||
fn testfn() { }
|
||||
|
@ -1499,16 +1534,18 @@ mod tests {
|
|||
let filtered = filter_tests(&opts, tests);
|
||||
|
||||
let expected =
|
||||
vec!("int::test_pow".to_owned(), "int::test_to_str".to_owned(), "sha1::test".to_owned(),
|
||||
"test::do_not_run_ignored_tests".to_owned(),
|
||||
"test::filter_for_ignored_option".to_owned(),
|
||||
"test::first_free_arg_should_be_a_filter".to_owned(),
|
||||
"test::ignored_tests_result_in_ignored".to_owned(),
|
||||
"test::parse_ignored_flag".to_owned(),
|
||||
"test::sort_tests".to_owned());
|
||||
vec!("int::test_pow".to_strbuf(),
|
||||
"int::test_to_str".to_strbuf(),
|
||||
"sha1::test".to_strbuf(),
|
||||
"test::do_not_run_ignored_tests".to_strbuf(),
|
||||
"test::filter_for_ignored_option".to_strbuf(),
|
||||
"test::first_free_arg_should_be_a_filter".to_strbuf(),
|
||||
"test::ignored_tests_result_in_ignored".to_strbuf(),
|
||||
"test::parse_ignored_flag".to_strbuf(),
|
||||
"test::sort_tests".to_strbuf());
|
||||
|
||||
for (a, b) in expected.iter().zip(filtered.iter()) {
|
||||
assert!(*a == b.desc.name.to_str());
|
||||
assert!(*a == b.desc.name.to_str().to_strbuf());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1536,31 +1573,31 @@ mod tests {
|
|||
|
||||
let diff1 = m2.compare_to_old(&m1, None);
|
||||
|
||||
assert_eq!(*(diff1.find(&"in-both-noise".to_owned()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff1.find(&"in-first-noise".to_owned()).unwrap()), MetricRemoved);
|
||||
assert_eq!(*(diff1.find(&"in-second-noise".to_owned()).unwrap()), MetricAdded);
|
||||
assert_eq!(*(diff1.find(&"in-both-want-downwards-but-regressed".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff1.find(&"in-both-noise".to_strbuf()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff1.find(&"in-first-noise".to_strbuf()).unwrap()), MetricRemoved);
|
||||
assert_eq!(*(diff1.find(&"in-second-noise".to_strbuf()).unwrap()), MetricAdded);
|
||||
assert_eq!(*(diff1.find(&"in-both-want-downwards-but-regressed".to_strbuf()).unwrap()),
|
||||
Regression(100.0));
|
||||
assert_eq!(*(diff1.find(&"in-both-want-downwards-and-improved".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff1.find(&"in-both-want-downwards-and-improved".to_strbuf()).unwrap()),
|
||||
Improvement(50.0));
|
||||
assert_eq!(*(diff1.find(&"in-both-want-upwards-but-regressed".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff1.find(&"in-both-want-upwards-but-regressed".to_strbuf()).unwrap()),
|
||||
Regression(50.0));
|
||||
assert_eq!(*(diff1.find(&"in-both-want-upwards-and-improved".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff1.find(&"in-both-want-upwards-and-improved".to_strbuf()).unwrap()),
|
||||
Improvement(100.0));
|
||||
assert_eq!(diff1.len(), 7);
|
||||
|
||||
let diff2 = m2.compare_to_old(&m1, Some(200.0));
|
||||
|
||||
assert_eq!(*(diff2.find(&"in-both-noise".to_owned()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"in-first-noise".to_owned()).unwrap()), MetricRemoved);
|
||||
assert_eq!(*(diff2.find(&"in-second-noise".to_owned()).unwrap()), MetricAdded);
|
||||
assert_eq!(*(diff2.find(&"in-both-want-downwards-but-regressed".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff2.find(&"in-both-noise".to_strbuf()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"in-first-noise".to_strbuf()).unwrap()), MetricRemoved);
|
||||
assert_eq!(*(diff2.find(&"in-second-noise".to_strbuf()).unwrap()), MetricAdded);
|
||||
assert_eq!(*(diff2.find(&"in-both-want-downwards-but-regressed".to_strbuf()).unwrap()),
|
||||
LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"in-both-want-downwards-and-improved".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff2.find(&"in-both-want-downwards-and-improved".to_strbuf()).unwrap()),
|
||||
LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"in-both-want-upwards-but-regressed".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff2.find(&"in-both-want-upwards-but-regressed".to_strbuf()).unwrap()),
|
||||
LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"in-both-want-upwards-and-improved".to_owned()).unwrap()),
|
||||
assert_eq!(*(diff2.find(&"in-both-want-upwards-and-improved".to_strbuf()).unwrap()),
|
||||
LikelyNoise);
|
||||
assert_eq!(diff2.len(), 7);
|
||||
}
|
||||
|
@ -1585,29 +1622,29 @@ mod tests {
|
|||
let (diff1, ok1) = m2.ratchet(&pth, None);
|
||||
assert_eq!(ok1, false);
|
||||
assert_eq!(diff1.len(), 2);
|
||||
assert_eq!(*(diff1.find(&"runtime".to_owned()).unwrap()), Regression(10.0));
|
||||
assert_eq!(*(diff1.find(&"throughput".to_owned()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff1.find(&"runtime".to_strbuf()).unwrap()), Regression(10.0));
|
||||
assert_eq!(*(diff1.find(&"throughput".to_strbuf()).unwrap()), LikelyNoise);
|
||||
|
||||
// Check that it was not rewritten.
|
||||
let m3 = MetricMap::load(&pth);
|
||||
let MetricMap(m3) = m3;
|
||||
assert_eq!(m3.len(), 2);
|
||||
assert_eq!(*(m3.find(&"runtime".to_owned()).unwrap()), Metric::new(1000.0, 2.0));
|
||||
assert_eq!(*(m3.find(&"throughput".to_owned()).unwrap()), Metric::new(50.0, 2.0));
|
||||
assert_eq!(*(m3.find(&"runtime".to_strbuf()).unwrap()), Metric::new(1000.0, 2.0));
|
||||
assert_eq!(*(m3.find(&"throughput".to_strbuf()).unwrap()), Metric::new(50.0, 2.0));
|
||||
|
||||
// Ask for a ratchet with an explicit noise-percentage override,
|
||||
// that should advance.
|
||||
let (diff2, ok2) = m2.ratchet(&pth, Some(10.0));
|
||||
assert_eq!(ok2, true);
|
||||
assert_eq!(diff2.len(), 2);
|
||||
assert_eq!(*(diff2.find(&"runtime".to_owned()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"throughput".to_owned()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"runtime".to_strbuf()).unwrap()), LikelyNoise);
|
||||
assert_eq!(*(diff2.find(&"throughput".to_strbuf()).unwrap()), LikelyNoise);
|
||||
|
||||
// Check that it was rewritten.
|
||||
let m4 = MetricMap::load(&pth);
|
||||
let MetricMap(m4) = m4;
|
||||
assert_eq!(m4.len(), 2);
|
||||
assert_eq!(*(m4.find(&"runtime".to_owned()).unwrap()), Metric::new(1100.0, 2.0));
|
||||
assert_eq!(*(m4.find(&"throughput".to_owned()).unwrap()), Metric::new(50.0, 2.0));
|
||||
assert_eq!(*(m4.find(&"runtime".to_strbuf()).unwrap()), Metric::new(1100.0, 2.0));
|
||||
assert_eq!(*(m4.find(&"throughput".to_strbuf()).unwrap()), Metric::new(50.0, 2.0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1028,17 +1028,20 @@ mod tests {
|
|||
#[test]
|
||||
fn test_boxplot_nonpositive() {
|
||||
#[allow(deprecated_owned_vector)]
|
||||
fn t(s: &Summary<f64>, expected: ~str) {
|
||||
fn t(s: &Summary<f64>, expected: StrBuf) {
|
||||
use std::io::MemWriter;
|
||||
let mut m = MemWriter::new();
|
||||
write_boxplot(&mut m as &mut io::Writer, s, 30).unwrap();
|
||||
let out = str::from_utf8(m.unwrap().as_slice()).unwrap().to_owned();
|
||||
let out = str::from_utf8(m.unwrap().as_slice()).unwrap().to_strbuf();
|
||||
assert_eq!(out, expected);
|
||||
}
|
||||
|
||||
t(&Summary::new([-2.0, -1.0]), "-2 |[------******#*****---]| -1".to_owned());
|
||||
t(&Summary::new([0.0, 2.0]), "0 |[-------*****#*******---]| 2".to_owned());
|
||||
t(&Summary::new([-2.0, 0.0]), "-2 |[------******#******---]| 0".to_owned());
|
||||
t(&Summary::new([-2.0, -1.0]),
|
||||
"-2 |[------******#*****---]| -1".to_strbuf());
|
||||
t(&Summary::new([0.0, 2.0]),
|
||||
"0 |[-------*****#*******---]| 2".to_strbuf());
|
||||
t(&Summary::new([-2.0, 0.0]),
|
||||
"-2 |[------******#******---]| 0".to_strbuf());
|
||||
|
||||
}
|
||||
#[test]
|
||||
|
|
|
@ -315,10 +315,10 @@ impl Tm {
|
|||
* Return a string of the current time in the form
|
||||
* "Thu Jan 1 00:00:00 1970".
|
||||
*/
|
||||
pub fn ctime(&self) -> ~str { self.strftime("%c") }
|
||||
pub fn ctime(&self) -> StrBuf { self.strftime("%c") }
|
||||
|
||||
/// Formats the time according to the format string.
|
||||
pub fn strftime(&self, format: &str) -> ~str {
|
||||
pub fn strftime(&self, format: &str) -> StrBuf {
|
||||
strftime(format, self)
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,7 @@ impl Tm {
|
|||
* local: "Thu, 22 Mar 2012 07:53:18 PST"
|
||||
* utc: "Thu, 22 Mar 2012 14:53:18 UTC"
|
||||
*/
|
||||
pub fn rfc822(&self) -> ~str {
|
||||
pub fn rfc822(&self) -> StrBuf {
|
||||
if self.tm_gmtoff == 0_i32 {
|
||||
self.strftime("%a, %d %b %Y %T GMT")
|
||||
} else {
|
||||
|
@ -342,7 +342,7 @@ impl Tm {
|
|||
* local: "Thu, 22 Mar 2012 07:53:18 -0700"
|
||||
* utc: "Thu, 22 Mar 2012 14:53:18 -0000"
|
||||
*/
|
||||
pub fn rfc822z(&self) -> ~str {
|
||||
pub fn rfc822z(&self) -> StrBuf {
|
||||
self.strftime("%a, %d %b %Y %T %z")
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ impl Tm {
|
|||
* local: "2012-02-22T07:53:18-07:00"
|
||||
* utc: "2012-02-22T14:53:18Z"
|
||||
*/
|
||||
pub fn rfc3339(&self) -> ~str {
|
||||
pub fn rfc3339(&self) -> StrBuf {
|
||||
if self.tm_gmtoff == 0_i32 {
|
||||
self.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
} else {
|
||||
|
@ -361,13 +361,13 @@ impl Tm {
|
|||
let mut m = num::abs(self.tm_gmtoff) / 60_i32;
|
||||
let h = m / 60_i32;
|
||||
m -= h * 60_i32;
|
||||
s + format!("{}{:02d}:{:02d}", sign, h as int, m as int)
|
||||
format_strbuf!("{}{}{:02d}:{:02d}", s, sign, h as int, m as int)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses the time from the string according to the format string.
|
||||
pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
||||
pub fn strptime(s: &str, format: &str) -> Result<Tm, StrBuf> {
|
||||
fn match_str(s: &str, pos: uint, needle: &str) -> bool {
|
||||
let mut i = pos;
|
||||
for ch in needle.bytes() {
|
||||
|
@ -379,14 +379,14 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
return true;
|
||||
}
|
||||
|
||||
fn match_strs(ss: &str, pos: uint, strs: &[(~str, i32)])
|
||||
fn match_strs(ss: &str, pos: uint, strs: &[(StrBuf, i32)])
|
||||
-> Option<(i32, uint)> {
|
||||
let mut i = 0u;
|
||||
let len = strs.len();
|
||||
while i < len {
|
||||
match strs[i] { // can't use let due to let-pattern bugs
|
||||
(ref needle, value) => {
|
||||
if match_str(ss, pos, *needle) {
|
||||
if match_str(ss, pos, needle.as_slice()) {
|
||||
return Some((value, pos + needle.len()));
|
||||
}
|
||||
}
|
||||
|
@ -461,78 +461,78 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_char(s: &str, pos: uint, c: char) -> Result<uint, ~str> {
|
||||
fn parse_char(s: &str, pos: uint, c: char) -> Result<uint, StrBuf> {
|
||||
let range = s.char_range_at(pos);
|
||||
|
||||
if c == range.ch {
|
||||
Ok(range.next)
|
||||
} else {
|
||||
Err(format!("Expected {}, found {}",
|
||||
Err(format_strbuf!("Expected {}, found {}",
|
||||
str::from_char(c),
|
||||
str::from_char(range.ch)))
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_type(s: &str, pos: uint, ch: char, tm: &mut Tm)
|
||||
-> Result<uint, ~str> {
|
||||
-> Result<uint, StrBuf> {
|
||||
match ch {
|
||||
'A' => match match_strs(s, pos, [
|
||||
("Sunday".to_owned(), 0_i32),
|
||||
("Monday".to_owned(), 1_i32),
|
||||
("Tuesday".to_owned(), 2_i32),
|
||||
("Wednesday".to_owned(), 3_i32),
|
||||
("Thursday".to_owned(), 4_i32),
|
||||
("Friday".to_owned(), 5_i32),
|
||||
("Saturday".to_owned(), 6_i32)
|
||||
("Sunday".to_strbuf(), 0_i32),
|
||||
("Monday".to_strbuf(), 1_i32),
|
||||
("Tuesday".to_strbuf(), 2_i32),
|
||||
("Wednesday".to_strbuf(), 3_i32),
|
||||
("Thursday".to_strbuf(), 4_i32),
|
||||
("Friday".to_strbuf(), 5_i32),
|
||||
("Saturday".to_strbuf(), 6_i32)
|
||||
]) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_wday = v; Ok(pos) }
|
||||
None => Err("Invalid day".to_owned())
|
||||
None => Err("Invalid day".to_strbuf())
|
||||
},
|
||||
'a' => match match_strs(s, pos, [
|
||||
("Sun".to_owned(), 0_i32),
|
||||
("Mon".to_owned(), 1_i32),
|
||||
("Tue".to_owned(), 2_i32),
|
||||
("Wed".to_owned(), 3_i32),
|
||||
("Thu".to_owned(), 4_i32),
|
||||
("Fri".to_owned(), 5_i32),
|
||||
("Sat".to_owned(), 6_i32)
|
||||
("Sun".to_strbuf(), 0_i32),
|
||||
("Mon".to_strbuf(), 1_i32),
|
||||
("Tue".to_strbuf(), 2_i32),
|
||||
("Wed".to_strbuf(), 3_i32),
|
||||
("Thu".to_strbuf(), 4_i32),
|
||||
("Fri".to_strbuf(), 5_i32),
|
||||
("Sat".to_strbuf(), 6_i32)
|
||||
]) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_wday = v; Ok(pos) }
|
||||
None => Err("Invalid day".to_owned())
|
||||
None => Err("Invalid day".to_strbuf())
|
||||
},
|
||||
'B' => match match_strs(s, pos, [
|
||||
("January".to_owned(), 0_i32),
|
||||
("February".to_owned(), 1_i32),
|
||||
("March".to_owned(), 2_i32),
|
||||
("April".to_owned(), 3_i32),
|
||||
("May".to_owned(), 4_i32),
|
||||
("June".to_owned(), 5_i32),
|
||||
("July".to_owned(), 6_i32),
|
||||
("August".to_owned(), 7_i32),
|
||||
("September".to_owned(), 8_i32),
|
||||
("October".to_owned(), 9_i32),
|
||||
("November".to_owned(), 10_i32),
|
||||
("December".to_owned(), 11_i32)
|
||||
("January".to_strbuf(), 0_i32),
|
||||
("February".to_strbuf(), 1_i32),
|
||||
("March".to_strbuf(), 2_i32),
|
||||
("April".to_strbuf(), 3_i32),
|
||||
("May".to_strbuf(), 4_i32),
|
||||
("June".to_strbuf(), 5_i32),
|
||||
("July".to_strbuf(), 6_i32),
|
||||
("August".to_strbuf(), 7_i32),
|
||||
("September".to_strbuf(), 8_i32),
|
||||
("October".to_strbuf(), 9_i32),
|
||||
("November".to_strbuf(), 10_i32),
|
||||
("December".to_strbuf(), 11_i32)
|
||||
]) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mon = v; Ok(pos) }
|
||||
None => Err("Invalid month".to_owned())
|
||||
None => Err("Invalid month".to_strbuf())
|
||||
},
|
||||
'b' | 'h' => match match_strs(s, pos, [
|
||||
("Jan".to_owned(), 0_i32),
|
||||
("Feb".to_owned(), 1_i32),
|
||||
("Mar".to_owned(), 2_i32),
|
||||
("Apr".to_owned(), 3_i32),
|
||||
("May".to_owned(), 4_i32),
|
||||
("Jun".to_owned(), 5_i32),
|
||||
("Jul".to_owned(), 6_i32),
|
||||
("Aug".to_owned(), 7_i32),
|
||||
("Sep".to_owned(), 8_i32),
|
||||
("Oct".to_owned(), 9_i32),
|
||||
("Nov".to_owned(), 10_i32),
|
||||
("Dec".to_owned(), 11_i32)
|
||||
("Jan".to_strbuf(), 0_i32),
|
||||
("Feb".to_strbuf(), 1_i32),
|
||||
("Mar".to_strbuf(), 2_i32),
|
||||
("Apr".to_strbuf(), 3_i32),
|
||||
("May".to_strbuf(), 4_i32),
|
||||
("Jun".to_strbuf(), 5_i32),
|
||||
("Jul".to_strbuf(), 6_i32),
|
||||
("Aug".to_strbuf(), 7_i32),
|
||||
("Sep".to_strbuf(), 8_i32),
|
||||
("Oct".to_strbuf(), 9_i32),
|
||||
("Nov".to_strbuf(), 10_i32),
|
||||
("Dec".to_strbuf(), 11_i32)
|
||||
]) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mon = v; Ok(pos) }
|
||||
None => Err("Invalid month".to_owned())
|
||||
None => Err("Invalid month".to_strbuf())
|
||||
},
|
||||
'C' => match match_digits_in_range(s, pos, 2u, false, 0_i32,
|
||||
99_i32) {
|
||||
|
@ -541,7 +541,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_year += (v * 100_i32) - 1900_i32;
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid year".to_owned())
|
||||
None => Err("Invalid year".to_strbuf())
|
||||
},
|
||||
'c' => {
|
||||
parse_type(s, pos, 'a', &mut *tm)
|
||||
|
@ -564,12 +564,12 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
'd' => match match_digits_in_range(s, pos, 2u, false, 1_i32,
|
||||
31_i32) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mday = v; Ok(pos) }
|
||||
None => Err("Invalid day of the month".to_owned())
|
||||
None => Err("Invalid day of the month".to_strbuf())
|
||||
},
|
||||
'e' => match match_digits_in_range(s, pos, 2u, true, 1_i32,
|
||||
31_i32) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mday = v; Ok(pos) }
|
||||
None => Err("Invalid day of the month".to_owned())
|
||||
None => Err("Invalid day of the month".to_strbuf())
|
||||
},
|
||||
'f' => {
|
||||
let (val, pos) = match_fractional_seconds(s, pos);
|
||||
|
@ -586,7 +586,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
'H' => {
|
||||
match match_digits_in_range(s, pos, 2u, false, 0_i32, 23_i32) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_hour = v; Ok(pos) }
|
||||
None => Err("Invalid hour".to_owned())
|
||||
None => Err("Invalid hour".to_strbuf())
|
||||
}
|
||||
}
|
||||
'I' => {
|
||||
|
@ -596,7 +596,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid hour".to_owned())
|
||||
None => Err("Invalid hour".to_strbuf())
|
||||
}
|
||||
}
|
||||
'j' => {
|
||||
|
@ -606,13 +606,13 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_yday = v - 1_i32;
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid day of year".to_owned())
|
||||
None => Err("Invalid day of year".to_strbuf())
|
||||
}
|
||||
}
|
||||
'k' => {
|
||||
match match_digits_in_range(s, pos, 2u, true, 0_i32, 23_i32) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_hour = v; Ok(pos) }
|
||||
None => Err("Invalid hour".to_owned())
|
||||
None => Err("Invalid hour".to_strbuf())
|
||||
}
|
||||
}
|
||||
'l' => {
|
||||
|
@ -622,13 +622,13 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid hour".to_owned())
|
||||
None => Err("Invalid hour".to_strbuf())
|
||||
}
|
||||
}
|
||||
'M' => {
|
||||
match match_digits_in_range(s, pos, 2u, false, 0_i32, 59_i32) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_min = v; Ok(pos) }
|
||||
None => Err("Invalid minute".to_owned())
|
||||
None => Err("Invalid minute".to_strbuf())
|
||||
}
|
||||
}
|
||||
'm' => {
|
||||
|
@ -638,21 +638,21 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_mon = v - 1_i32;
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid month".to_owned())
|
||||
None => Err("Invalid month".to_strbuf())
|
||||
}
|
||||
}
|
||||
'n' => parse_char(s, pos, '\n'),
|
||||
'P' => match match_strs(s, pos,
|
||||
[("am".to_owned(), 0_i32), ("pm".to_owned(), 12_i32)]) {
|
||||
[("am".to_strbuf(), 0_i32), ("pm".to_strbuf(), 12_i32)]) {
|
||||
|
||||
Some(item) => { let (v, pos) = item; tm.tm_hour += v; Ok(pos) }
|
||||
None => Err("Invalid hour".to_owned())
|
||||
None => Err("Invalid hour".to_strbuf())
|
||||
},
|
||||
'p' => match match_strs(s, pos,
|
||||
[("AM".to_owned(), 0_i32), ("PM".to_owned(), 12_i32)]) {
|
||||
[("AM".to_strbuf(), 0_i32), ("PM".to_strbuf(), 12_i32)]) {
|
||||
|
||||
Some(item) => { let (v, pos) = item; tm.tm_hour += v; Ok(pos) }
|
||||
None => Err("Invalid hour".to_owned())
|
||||
None => Err("Invalid hour".to_strbuf())
|
||||
},
|
||||
'R' => {
|
||||
parse_type(s, pos, 'H', &mut *tm)
|
||||
|
@ -675,7 +675,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_sec = v;
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid second".to_owned())
|
||||
None => Err("Invalid second".to_strbuf())
|
||||
}
|
||||
}
|
||||
//'s' {}
|
||||
|
@ -694,7 +694,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_wday = if v == 7 { 0 } else { v };
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid day of week".to_owned())
|
||||
None => Err("Invalid day of week".to_strbuf())
|
||||
}
|
||||
}
|
||||
'v' => {
|
||||
|
@ -708,7 +708,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
'w' => {
|
||||
match match_digits_in_range(s, pos, 1u, false, 0_i32, 6_i32) {
|
||||
Some(item) => { let (v, pos) = item; tm.tm_wday = v; Ok(pos) }
|
||||
None => Err("Invalid day of week".to_owned())
|
||||
None => Err("Invalid day of week".to_strbuf())
|
||||
}
|
||||
}
|
||||
'Y' => {
|
||||
|
@ -718,7 +718,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_year = v - 1900_i32;
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid year".to_owned())
|
||||
None => Err("Invalid year".to_strbuf())
|
||||
}
|
||||
}
|
||||
'y' => {
|
||||
|
@ -728,7 +728,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
tm.tm_year = v;
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid year".to_owned())
|
||||
None => Err("Invalid year".to_strbuf())
|
||||
}
|
||||
}
|
||||
'Z' => {
|
||||
|
@ -764,15 +764,16 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
|
||||
Ok(pos)
|
||||
}
|
||||
None => Err("Invalid zone offset".to_owned())
|
||||
None => Err("Invalid zone offset".to_strbuf())
|
||||
}
|
||||
} else {
|
||||
Err("Invalid zone offset".to_owned())
|
||||
Err("Invalid zone offset".to_strbuf())
|
||||
}
|
||||
}
|
||||
'%' => parse_char(s, pos, '%'),
|
||||
ch => {
|
||||
Err(format!("unknown formatting type: {}", str::from_char(ch)))
|
||||
Err(format_strbuf!("unknown formatting type: {}",
|
||||
str::from_char(ch)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -794,7 +795,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
};
|
||||
let mut pos = 0u;
|
||||
let len = s.len();
|
||||
let mut result = Err("Invalid time".to_owned());
|
||||
let mut result = Err("Invalid time".to_strbuf());
|
||||
|
||||
while pos < len {
|
||||
let range = s.char_range_at(pos);
|
||||
|
@ -843,7 +844,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
}
|
||||
|
||||
/// Formats the time according to the format string.
|
||||
pub fn strftime(format: &str, tm: &Tm) -> ~str {
|
||||
pub fn strftime(format: &str, tm: &Tm) -> StrBuf {
|
||||
fn days_in_year(year: int) -> i32 {
|
||||
if (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) {
|
||||
366 /* Days in a leap year */
|
||||
|
@ -871,7 +872,7 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str {
|
|||
+ iso_week1_wday - iso_week_start_wday
|
||||
}
|
||||
|
||||
fn iso_week(ch:char, tm: &Tm) -> ~str {
|
||||
fn iso_week(ch:char, tm: &Tm) -> StrBuf {
|
||||
let mut year: int = tm.tm_year as int + 1900;
|
||||
let mut days: int = iso_week_days (tm.tm_yday, tm.tm_wday);
|
||||
|
||||
|
@ -890,69 +891,71 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str {
|
|||
}
|
||||
|
||||
match ch {
|
||||
'G' => format!("{}", year),
|
||||
'g' => format!("{:02d}", (year % 100 + 100) % 100),
|
||||
'V' => format!("{:02d}", days / 7 + 1),
|
||||
_ => "".to_owned()
|
||||
'G' => format_strbuf!("{}", year),
|
||||
'g' => format_strbuf!("{:02d}", (year % 100 + 100) % 100),
|
||||
'V' => format_strbuf!("{:02d}", days / 7 + 1),
|
||||
_ => "".to_strbuf()
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_type(ch: char, tm: &Tm) -> ~str {
|
||||
let die = || format!("strftime: can't understand this format {} ", ch);
|
||||
fn parse_type(ch: char, tm: &Tm) -> StrBuf {
|
||||
let die = || {
|
||||
format_strbuf!("strftime: can't understand this format {} ", ch)
|
||||
};
|
||||
match ch {
|
||||
'A' => match tm.tm_wday as int {
|
||||
0 => "Sunday".to_owned(),
|
||||
1 => "Monday".to_owned(),
|
||||
2 => "Tuesday".to_owned(),
|
||||
3 => "Wednesday".to_owned(),
|
||||
4 => "Thursday".to_owned(),
|
||||
5 => "Friday".to_owned(),
|
||||
6 => "Saturday".to_owned(),
|
||||
0 => "Sunday".to_strbuf(),
|
||||
1 => "Monday".to_strbuf(),
|
||||
2 => "Tuesday".to_strbuf(),
|
||||
3 => "Wednesday".to_strbuf(),
|
||||
4 => "Thursday".to_strbuf(),
|
||||
5 => "Friday".to_strbuf(),
|
||||
6 => "Saturday".to_strbuf(),
|
||||
_ => die()
|
||||
},
|
||||
'a' => match tm.tm_wday as int {
|
||||
0 => "Sun".to_owned(),
|
||||
1 => "Mon".to_owned(),
|
||||
2 => "Tue".to_owned(),
|
||||
3 => "Wed".to_owned(),
|
||||
4 => "Thu".to_owned(),
|
||||
5 => "Fri".to_owned(),
|
||||
6 => "Sat".to_owned(),
|
||||
0 => "Sun".to_strbuf(),
|
||||
1 => "Mon".to_strbuf(),
|
||||
2 => "Tue".to_strbuf(),
|
||||
3 => "Wed".to_strbuf(),
|
||||
4 => "Thu".to_strbuf(),
|
||||
5 => "Fri".to_strbuf(),
|
||||
6 => "Sat".to_strbuf(),
|
||||
_ => die()
|
||||
},
|
||||
'B' => match tm.tm_mon as int {
|
||||
0 => "January".to_owned(),
|
||||
1 => "February".to_owned(),
|
||||
2 => "March".to_owned(),
|
||||
3 => "April".to_owned(),
|
||||
4 => "May".to_owned(),
|
||||
5 => "June".to_owned(),
|
||||
6 => "July".to_owned(),
|
||||
7 => "August".to_owned(),
|
||||
8 => "September".to_owned(),
|
||||
9 => "October".to_owned(),
|
||||
10 => "November".to_owned(),
|
||||
11 => "December".to_owned(),
|
||||
0 => "January".to_strbuf(),
|
||||
1 => "February".to_strbuf(),
|
||||
2 => "March".to_strbuf(),
|
||||
3 => "April".to_strbuf(),
|
||||
4 => "May".to_strbuf(),
|
||||
5 => "June".to_strbuf(),
|
||||
6 => "July".to_strbuf(),
|
||||
7 => "August".to_strbuf(),
|
||||
8 => "September".to_strbuf(),
|
||||
9 => "October".to_strbuf(),
|
||||
10 => "November".to_strbuf(),
|
||||
11 => "December".to_strbuf(),
|
||||
_ => die()
|
||||
},
|
||||
'b' | 'h' => match tm.tm_mon as int {
|
||||
0 => "Jan".to_owned(),
|
||||
1 => "Feb".to_owned(),
|
||||
2 => "Mar".to_owned(),
|
||||
3 => "Apr".to_owned(),
|
||||
4 => "May".to_owned(),
|
||||
5 => "Jun".to_owned(),
|
||||
6 => "Jul".to_owned(),
|
||||
7 => "Aug".to_owned(),
|
||||
8 => "Sep".to_owned(),
|
||||
9 => "Oct".to_owned(),
|
||||
10 => "Nov".to_owned(),
|
||||
11 => "Dec".to_owned(),
|
||||
0 => "Jan".to_strbuf(),
|
||||
1 => "Feb".to_strbuf(),
|
||||
2 => "Mar".to_strbuf(),
|
||||
3 => "Apr".to_strbuf(),
|
||||
4 => "May".to_strbuf(),
|
||||
5 => "Jun".to_strbuf(),
|
||||
6 => "Jul".to_strbuf(),
|
||||
7 => "Aug".to_strbuf(),
|
||||
8 => "Sep".to_strbuf(),
|
||||
9 => "Oct".to_strbuf(),
|
||||
10 => "Nov".to_strbuf(),
|
||||
11 => "Dec".to_strbuf(),
|
||||
_ => die()
|
||||
},
|
||||
'C' => format!("{:02d}", (tm.tm_year as int + 1900) / 100),
|
||||
'C' => format_strbuf!("{:02d}", (tm.tm_year as int + 1900) / 100),
|
||||
'c' => {
|
||||
format!("{} {} {} {} {}",
|
||||
format_strbuf!("{} {} {} {} {}",
|
||||
parse_type('a', tm),
|
||||
parse_type('b', tm),
|
||||
parse_type('e', tm),
|
||||
|
@ -960,90 +963,92 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str {
|
|||
parse_type('Y', tm))
|
||||
}
|
||||
'D' | 'x' => {
|
||||
format!("{}/{}/{}",
|
||||
format_strbuf!("{}/{}/{}",
|
||||
parse_type('m', tm),
|
||||
parse_type('d', tm),
|
||||
parse_type('y', tm))
|
||||
}
|
||||
'd' => format!("{:02d}", tm.tm_mday),
|
||||
'e' => format!("{:2d}", tm.tm_mday),
|
||||
'f' => format!("{:09d}", tm.tm_nsec),
|
||||
'd' => format_strbuf!("{:02d}", tm.tm_mday),
|
||||
'e' => format_strbuf!("{:2d}", tm.tm_mday),
|
||||
'f' => format_strbuf!("{:09d}", tm.tm_nsec),
|
||||
'F' => {
|
||||
format!("{}-{}-{}",
|
||||
format_strbuf!("{}-{}-{}",
|
||||
parse_type('Y', tm),
|
||||
parse_type('m', tm),
|
||||
parse_type('d', tm))
|
||||
}
|
||||
'G' => iso_week('G', tm),
|
||||
'g' => iso_week('g', tm),
|
||||
'H' => format!("{:02d}", tm.tm_hour),
|
||||
'H' => format_strbuf!("{:02d}", tm.tm_hour),
|
||||
'I' => {
|
||||
let mut h = tm.tm_hour;
|
||||
if h == 0 { h = 12 }
|
||||
if h > 12 { h -= 12 }
|
||||
format!("{:02d}", h)
|
||||
format_strbuf!("{:02d}", h)
|
||||
}
|
||||
'j' => format!("{:03d}", tm.tm_yday + 1),
|
||||
'k' => format!("{:2d}", tm.tm_hour),
|
||||
'j' => format_strbuf!("{:03d}", tm.tm_yday + 1),
|
||||
'k' => format_strbuf!("{:2d}", tm.tm_hour),
|
||||
'l' => {
|
||||
let mut h = tm.tm_hour;
|
||||
if h == 0 { h = 12 }
|
||||
if h > 12 { h -= 12 }
|
||||
format!("{:2d}", h)
|
||||
format_strbuf!("{:2d}", h)
|
||||
}
|
||||
'M' => format!("{:02d}", tm.tm_min),
|
||||
'm' => format!("{:02d}", tm.tm_mon + 1),
|
||||
'n' => "\n".to_owned(),
|
||||
'P' => if (tm.tm_hour as int) < 12 { "am".to_owned() } else { "pm".to_owned() },
|
||||
'p' => if (tm.tm_hour as int) < 12 { "AM".to_owned() } else { "PM".to_owned() },
|
||||
'M' => format_strbuf!("{:02d}", tm.tm_min),
|
||||
'm' => format_strbuf!("{:02d}", tm.tm_mon + 1),
|
||||
'n' => "\n".to_strbuf(),
|
||||
'P' => if (tm.tm_hour as int) < 12 { "am".to_strbuf() } else { "pm".to_strbuf() },
|
||||
'p' => if (tm.tm_hour as int) < 12 { "AM".to_strbuf() } else { "PM".to_strbuf() },
|
||||
'R' => {
|
||||
format!("{}:{}",
|
||||
format_strbuf!("{}:{}",
|
||||
parse_type('H', tm),
|
||||
parse_type('M', tm))
|
||||
}
|
||||
'r' => {
|
||||
format!("{}:{}:{} {}",
|
||||
format_strbuf!("{}:{}:{} {}",
|
||||
parse_type('I', tm),
|
||||
parse_type('M', tm),
|
||||
parse_type('S', tm),
|
||||
parse_type('p', tm))
|
||||
}
|
||||
'S' => format!("{:02d}", tm.tm_sec),
|
||||
's' => format!("{}", tm.to_timespec().sec),
|
||||
'S' => format_strbuf!("{:02d}", tm.tm_sec),
|
||||
's' => format_strbuf!("{}", tm.to_timespec().sec),
|
||||
'T' | 'X' => {
|
||||
format!("{}:{}:{}",
|
||||
format_strbuf!("{}:{}:{}",
|
||||
parse_type('H', tm),
|
||||
parse_type('M', tm),
|
||||
parse_type('S', tm))
|
||||
}
|
||||
't' => "\t".to_owned(),
|
||||
'U' => format!("{:02d}", (tm.tm_yday - tm.tm_wday + 7) / 7),
|
||||
't' => "\t".to_strbuf(),
|
||||
'U' => format_strbuf!("{:02d}", (tm.tm_yday - tm.tm_wday + 7) / 7),
|
||||
'u' => {
|
||||
let i = tm.tm_wday as int;
|
||||
(if i == 0 { 7 } else { i }).to_str()
|
||||
(if i == 0 { 7 } else { i }).to_str().to_strbuf()
|
||||
}
|
||||
'V' => iso_week('V', tm),
|
||||
'v' => {
|
||||
format!("{}-{}-{}",
|
||||
format_strbuf!("{}-{}-{}",
|
||||
parse_type('e', tm),
|
||||
parse_type('b', tm),
|
||||
parse_type('Y', tm))
|
||||
}
|
||||
'W' => format!("{:02d}", (tm.tm_yday - (tm.tm_wday - 1 + 7) % 7 + 7)
|
||||
/ 7),
|
||||
'w' => (tm.tm_wday as int).to_str(),
|
||||
'Y' => (tm.tm_year as int + 1900).to_str(),
|
||||
'y' => format!("{:02d}", (tm.tm_year as int + 1900) % 100),
|
||||
'Z' => tm.tm_zone.clone(),
|
||||
'W' => {
|
||||
format_strbuf!("{:02d}",
|
||||
(tm.tm_yday - (tm.tm_wday - 1 + 7) % 7 + 7) / 7)
|
||||
}
|
||||
'w' => (tm.tm_wday as int).to_str().to_strbuf(),
|
||||
'Y' => (tm.tm_year as int + 1900).to_str().to_strbuf(),
|
||||
'y' => format_strbuf!("{:02d}", (tm.tm_year as int + 1900) % 100),
|
||||
'Z' => tm.tm_zone.to_strbuf(),
|
||||
'z' => {
|
||||
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
|
||||
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
|
||||
let h = m / 60_i32;
|
||||
m -= h * 60_i32;
|
||||
format!("{}{:02d}{:02d}", sign, h, m)
|
||||
format_strbuf!("{}{:02d}{:02d}", sign, h, m)
|
||||
}
|
||||
'+' => tm.rfc3339(),
|
||||
'%' => "%".to_owned(),
|
||||
'%' => "%".to_strbuf(),
|
||||
_ => die()
|
||||
}
|
||||
}
|
||||
|
@ -1067,7 +1072,7 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str {
|
|||
}
|
||||
}
|
||||
|
||||
str::from_utf8(buf.as_slice()).unwrap().to_str()
|
||||
str::from_utf8(buf.as_slice()).unwrap().to_strbuf()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1235,9 +1240,9 @@ mod tests {
|
|||
}
|
||||
|
||||
let format = "%a %b %e %T.%f %Y";
|
||||
assert_eq!(strptime("", format), Err("Invalid time".to_owned()));
|
||||
assert_eq!(strptime("", format), Err("Invalid time".to_strbuf()));
|
||||
assert!(strptime("Fri Feb 13 15:31:30", format)
|
||||
== Err("Invalid time".to_owned()));
|
||||
== Err("Invalid time".to_strbuf()));
|
||||
|
||||
match strptime("Fri Feb 13 15:31:30.01234 2009", format) {
|
||||
Err(e) => fail!(e),
|
||||
|
@ -1259,71 +1264,71 @@ mod tests {
|
|||
|
||||
fn test(s: &str, format: &str) -> bool {
|
||||
match strptime(s, format) {
|
||||
Ok(ref tm) => tm.strftime(format) == s.to_owned(),
|
||||
Ok(ref tm) => tm.strftime(format) == s.to_strbuf(),
|
||||
Err(e) => fail!(e)
|
||||
}
|
||||
}
|
||||
|
||||
let days = [
|
||||
"Sunday".to_owned(),
|
||||
"Monday".to_owned(),
|
||||
"Tuesday".to_owned(),
|
||||
"Wednesday".to_owned(),
|
||||
"Thursday".to_owned(),
|
||||
"Friday".to_owned(),
|
||||
"Saturday".to_owned()
|
||||
"Sunday".to_strbuf(),
|
||||
"Monday".to_strbuf(),
|
||||
"Tuesday".to_strbuf(),
|
||||
"Wednesday".to_strbuf(),
|
||||
"Thursday".to_strbuf(),
|
||||
"Friday".to_strbuf(),
|
||||
"Saturday".to_strbuf()
|
||||
];
|
||||
for day in days.iter() {
|
||||
assert!(test(*day, "%A"));
|
||||
assert!(test(day.as_slice(), "%A"));
|
||||
}
|
||||
|
||||
let days = [
|
||||
"Sun".to_owned(),
|
||||
"Mon".to_owned(),
|
||||
"Tue".to_owned(),
|
||||
"Wed".to_owned(),
|
||||
"Thu".to_owned(),
|
||||
"Fri".to_owned(),
|
||||
"Sat".to_owned()
|
||||
"Sun".to_strbuf(),
|
||||
"Mon".to_strbuf(),
|
||||
"Tue".to_strbuf(),
|
||||
"Wed".to_strbuf(),
|
||||
"Thu".to_strbuf(),
|
||||
"Fri".to_strbuf(),
|
||||
"Sat".to_strbuf()
|
||||
];
|
||||
for day in days.iter() {
|
||||
assert!(test(*day, "%a"));
|
||||
assert!(test(day.as_slice(), "%a"));
|
||||
}
|
||||
|
||||
let months = [
|
||||
"January".to_owned(),
|
||||
"February".to_owned(),
|
||||
"March".to_owned(),
|
||||
"April".to_owned(),
|
||||
"May".to_owned(),
|
||||
"June".to_owned(),
|
||||
"July".to_owned(),
|
||||
"August".to_owned(),
|
||||
"September".to_owned(),
|
||||
"October".to_owned(),
|
||||
"November".to_owned(),
|
||||
"December".to_owned()
|
||||
"January".to_strbuf(),
|
||||
"February".to_strbuf(),
|
||||
"March".to_strbuf(),
|
||||
"April".to_strbuf(),
|
||||
"May".to_strbuf(),
|
||||
"June".to_strbuf(),
|
||||
"July".to_strbuf(),
|
||||
"August".to_strbuf(),
|
||||
"September".to_strbuf(),
|
||||
"October".to_strbuf(),
|
||||
"November".to_strbuf(),
|
||||
"December".to_strbuf()
|
||||
];
|
||||
for day in months.iter() {
|
||||
assert!(test(*day, "%B"));
|
||||
assert!(test(day.as_slice(), "%B"));
|
||||
}
|
||||
|
||||
let months = [
|
||||
"Jan".to_owned(),
|
||||
"Feb".to_owned(),
|
||||
"Mar".to_owned(),
|
||||
"Apr".to_owned(),
|
||||
"May".to_owned(),
|
||||
"Jun".to_owned(),
|
||||
"Jul".to_owned(),
|
||||
"Aug".to_owned(),
|
||||
"Sep".to_owned(),
|
||||
"Oct".to_owned(),
|
||||
"Nov".to_owned(),
|
||||
"Dec".to_owned()
|
||||
"Jan".to_strbuf(),
|
||||
"Feb".to_strbuf(),
|
||||
"Mar".to_strbuf(),
|
||||
"Apr".to_strbuf(),
|
||||
"May".to_strbuf(),
|
||||
"Jun".to_strbuf(),
|
||||
"Jul".to_strbuf(),
|
||||
"Aug".to_strbuf(),
|
||||
"Sep".to_strbuf(),
|
||||
"Oct".to_strbuf(),
|
||||
"Nov".to_strbuf(),
|
||||
"Dec".to_strbuf()
|
||||
];
|
||||
for day in months.iter() {
|
||||
assert!(test(*day, "%b"));
|
||||
assert!(test(day.as_slice(), "%b"));
|
||||
}
|
||||
|
||||
assert!(test("19", "%C"));
|
||||
|
@ -1375,7 +1380,7 @@ mod tests {
|
|||
assert!(test("%", "%%"));
|
||||
|
||||
// Test for #7256
|
||||
assert_eq!(strptime("360", "%Y-%m-%d"), Err("Invalid year".to_owned()))
|
||||
assert_eq!(strptime("360", "%Y-%m-%d"), Err("Invalid year".to_strbuf()))
|
||||
}
|
||||
|
||||
fn test_ctime() {
|
||||
|
@ -1387,8 +1392,8 @@ mod tests {
|
|||
|
||||
debug!("test_ctime: {:?} {:?}", utc.ctime(), local.ctime());
|
||||
|
||||
assert_eq!(utc.ctime(), "Fri Feb 13 23:31:30 2009".to_owned());
|
||||
assert_eq!(local.ctime(), "Fri Feb 13 15:31:30 2009".to_owned());
|
||||
assert_eq!(utc.ctime(), "Fri Feb 13 23:31:30 2009".to_strbuf());
|
||||
assert_eq!(local.ctime(), "Fri Feb 13 15:31:30 2009".to_strbuf());
|
||||
}
|
||||
|
||||
fn test_strftime() {
|
||||
|
@ -1398,70 +1403,71 @@ mod tests {
|
|||
let utc = at_utc(time);
|
||||
let local = at(time);
|
||||
|
||||
assert_eq!(local.strftime(""), "".to_owned());
|
||||
assert_eq!(local.strftime("%A"), "Friday".to_owned());
|
||||
assert_eq!(local.strftime("%a"), "Fri".to_owned());
|
||||
assert_eq!(local.strftime("%B"), "February".to_owned());
|
||||
assert_eq!(local.strftime("%b"), "Feb".to_owned());
|
||||
assert_eq!(local.strftime("%C"), "20".to_owned());
|
||||
assert_eq!(local.strftime("%c"), "Fri Feb 13 15:31:30 2009".to_owned());
|
||||
assert_eq!(local.strftime("%D"), "02/13/09".to_owned());
|
||||
assert_eq!(local.strftime("%d"), "13".to_owned());
|
||||
assert_eq!(local.strftime("%e"), "13".to_owned());
|
||||
assert_eq!(local.strftime("%f"), "000054321".to_owned());
|
||||
assert_eq!(local.strftime("%F"), "2009-02-13".to_owned());
|
||||
assert_eq!(local.strftime("%G"), "2009".to_owned());
|
||||
assert_eq!(local.strftime("%g"), "09".to_owned());
|
||||
assert_eq!(local.strftime("%H"), "15".to_owned());
|
||||
assert_eq!(local.strftime("%I"), "03".to_owned());
|
||||
assert_eq!(local.strftime("%j"), "044".to_owned());
|
||||
assert_eq!(local.strftime("%k"), "15".to_owned());
|
||||
assert_eq!(local.strftime("%l"), " 3".to_owned());
|
||||
assert_eq!(local.strftime("%M"), "31".to_owned());
|
||||
assert_eq!(local.strftime("%m"), "02".to_owned());
|
||||
assert_eq!(local.strftime("%n"), "\n".to_owned());
|
||||
assert_eq!(local.strftime("%P"), "pm".to_owned());
|
||||
assert_eq!(local.strftime("%p"), "PM".to_owned());
|
||||
assert_eq!(local.strftime("%R"), "15:31".to_owned());
|
||||
assert_eq!(local.strftime("%r"), "03:31:30 PM".to_owned());
|
||||
assert_eq!(local.strftime("%S"), "30".to_owned());
|
||||
assert_eq!(local.strftime("%s"), "1234567890".to_owned());
|
||||
assert_eq!(local.strftime("%T"), "15:31:30".to_owned());
|
||||
assert_eq!(local.strftime("%t"), "\t".to_owned());
|
||||
assert_eq!(local.strftime("%U"), "06".to_owned());
|
||||
assert_eq!(local.strftime("%u"), "5".to_owned());
|
||||
assert_eq!(local.strftime("%V"), "07".to_owned());
|
||||
assert_eq!(local.strftime("%v"), "13-Feb-2009".to_owned());
|
||||
assert_eq!(local.strftime("%W"), "06".to_owned());
|
||||
assert_eq!(local.strftime("%w"), "5".to_owned());
|
||||
assert_eq!(local.strftime("%X"), "15:31:30".to_owned()); // FIXME (#2350): support locale
|
||||
assert_eq!(local.strftime("%x"), "02/13/09".to_owned()); // FIXME (#2350): support locale
|
||||
assert_eq!(local.strftime("%Y"), "2009".to_owned());
|
||||
assert_eq!(local.strftime("%y"), "09".to_owned());
|
||||
assert_eq!(local.strftime("%+"), "2009-02-13T15:31:30-08:00".to_owned());
|
||||
assert_eq!(local.strftime(""), "".to_strbuf());
|
||||
assert_eq!(local.strftime("%A"), "Friday".to_strbuf());
|
||||
assert_eq!(local.strftime("%a"), "Fri".to_strbuf());
|
||||
assert_eq!(local.strftime("%B"), "February".to_strbuf());
|
||||
assert_eq!(local.strftime("%b"), "Feb".to_strbuf());
|
||||
assert_eq!(local.strftime("%C"), "20".to_strbuf());
|
||||
assert_eq!(local.strftime("%c"), "Fri Feb 13 15:31:30 2009".to_strbuf());
|
||||
assert_eq!(local.strftime("%D"), "02/13/09".to_strbuf());
|
||||
assert_eq!(local.strftime("%d"), "13".to_strbuf());
|
||||
assert_eq!(local.strftime("%e"), "13".to_strbuf());
|
||||
assert_eq!(local.strftime("%f"), "000054321".to_strbuf());
|
||||
assert_eq!(local.strftime("%F"), "2009-02-13".to_strbuf());
|
||||
assert_eq!(local.strftime("%G"), "2009".to_strbuf());
|
||||
assert_eq!(local.strftime("%g"), "09".to_strbuf());
|
||||
assert_eq!(local.strftime("%H"), "15".to_strbuf());
|
||||
assert_eq!(local.strftime("%I"), "03".to_strbuf());
|
||||
assert_eq!(local.strftime("%j"), "044".to_strbuf());
|
||||
assert_eq!(local.strftime("%k"), "15".to_strbuf());
|
||||
assert_eq!(local.strftime("%l"), " 3".to_strbuf());
|
||||
assert_eq!(local.strftime("%M"), "31".to_strbuf());
|
||||
assert_eq!(local.strftime("%m"), "02".to_strbuf());
|
||||
assert_eq!(local.strftime("%n"), "\n".to_strbuf());
|
||||
assert_eq!(local.strftime("%P"), "pm".to_strbuf());
|
||||
assert_eq!(local.strftime("%p"), "PM".to_strbuf());
|
||||
assert_eq!(local.strftime("%R"), "15:31".to_strbuf());
|
||||
assert_eq!(local.strftime("%r"), "03:31:30 PM".to_strbuf());
|
||||
assert_eq!(local.strftime("%S"), "30".to_strbuf());
|
||||
assert_eq!(local.strftime("%s"), "1234567890".to_strbuf());
|
||||
assert_eq!(local.strftime("%T"), "15:31:30".to_strbuf());
|
||||
assert_eq!(local.strftime("%t"), "\t".to_strbuf());
|
||||
assert_eq!(local.strftime("%U"), "06".to_strbuf());
|
||||
assert_eq!(local.strftime("%u"), "5".to_strbuf());
|
||||
assert_eq!(local.strftime("%V"), "07".to_strbuf());
|
||||
assert_eq!(local.strftime("%v"), "13-Feb-2009".to_strbuf());
|
||||
assert_eq!(local.strftime("%W"), "06".to_strbuf());
|
||||
assert_eq!(local.strftime("%w"), "5".to_strbuf());
|
||||
assert_eq!(local.strftime("%X"), "15:31:30".to_strbuf()); // FIXME (#2350): support locale
|
||||
assert_eq!(local.strftime("%x"), "02/13/09".to_strbuf()); // FIXME (#2350): support locale
|
||||
assert_eq!(local.strftime("%Y"), "2009".to_strbuf());
|
||||
assert_eq!(local.strftime("%y"), "09".to_strbuf());
|
||||
assert_eq!(local.strftime("%+"), "2009-02-13T15:31:30-08:00".to_strbuf());
|
||||
|
||||
// FIXME (#2350): We should probably standardize on the timezone
|
||||
// abbreviation.
|
||||
let zone = local.strftime("%Z");
|
||||
assert!(zone == "PST".to_owned() || zone == "Pacific Standard Time".to_owned());
|
||||
assert!(zone == "PST".to_strbuf() || zone == "Pacific Standard Time".to_strbuf());
|
||||
|
||||
assert_eq!(local.strftime("%z"), "-0800".to_owned());
|
||||
assert_eq!(local.strftime("%%"), "%".to_owned());
|
||||
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_owned();
|
||||
assert!(rfc822 == prefix + "PST" || rfc822 == prefix + "Pacific Standard Time");
|
||||
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_owned());
|
||||
assert_eq!(local.rfc822z(), "Fri, 13 Feb 2009 15:31:30 -0800".to_owned());
|
||||
assert_eq!(local.rfc3339(), "2009-02-13T15:31:30-08:00".to_owned());
|
||||
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());
|
||||
|
||||
assert_eq!(utc.ctime(), "Fri Feb 13 23:31:30 2009".to_owned());
|
||||
assert_eq!(utc.rfc822(), "Fri, 13 Feb 2009 23:31:30 GMT".to_owned());
|
||||
assert_eq!(utc.rfc822z(), "Fri, 13 Feb 2009 23:31:30 -0000".to_owned());
|
||||
assert_eq!(utc.rfc3339(), "2009-02-13T23:31:30Z".to_owned());
|
||||
assert_eq!(utc.ctime(), "Fri Feb 13 23:31:30 2009".to_strbuf());
|
||||
assert_eq!(utc.rfc822(), "Fri, 13 Feb 2009 23:31:30 GMT".to_strbuf());
|
||||
assert_eq!(utc.rfc822z(), "Fri, 13 Feb 2009 23:31:30 -0000".to_strbuf());
|
||||
assert_eq!(utc.rfc3339(), "2009-02-13T23:31:30Z".to_strbuf());
|
||||
}
|
||||
|
||||
fn test_timespec_eq_ord() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -322,20 +322,20 @@ impl Uuid {
|
|||
/// Returns the UUID as a string of 16 hexadecimal digits
|
||||
///
|
||||
/// Example: `936DA01F9ABD4d9d80C702AF85C822A8`
|
||||
pub fn to_simple_str(&self) -> ~str {
|
||||
pub fn to_simple_str(&self) -> StrBuf {
|
||||
let mut s: Vec<u8> = Vec::from_elem(32, 0u8);
|
||||
for i in range(0u, 16u) {
|
||||
let digit = format!("{:02x}", self.bytes[i] as uint);
|
||||
*s.get_mut(i*2+0) = digit[0];
|
||||
*s.get_mut(i*2+1) = digit[1];
|
||||
}
|
||||
str::from_utf8(s.as_slice()).unwrap().to_str()
|
||||
str::from_utf8(s.as_slice()).unwrap().to_strbuf()
|
||||
}
|
||||
|
||||
/// Returns a string of hexadecimal digits, separated into groups with a hyphen.
|
||||
///
|
||||
/// Example: `550e8400-e29b-41d4-a716-446655440000`
|
||||
pub fn to_hyphenated_str(&self) -> ~str {
|
||||
pub fn to_hyphenated_str(&self) -> StrBuf {
|
||||
use std::mem::{to_be16, to_be32};
|
||||
// Convert to field-based struct as it matches groups in output.
|
||||
// Ensure fields are in network byte order, as per RFC.
|
||||
|
@ -346,8 +346,8 @@ impl Uuid {
|
|||
uf.data1 = to_be32(uf.data1);
|
||||
uf.data2 = to_be16(uf.data2);
|
||||
uf.data3 = to_be16(uf.data3);
|
||||
let s = format!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
|
||||
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
|
||||
let s = format_strbuf!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
|
||||
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
|
||||
uf.data1,
|
||||
uf.data2, uf.data3,
|
||||
uf.data4[0], uf.data4[1],
|
||||
|
@ -361,8 +361,8 @@ impl Uuid {
|
|||
/// This is the same as the hyphenated format, but with the "urn:uuid:" prefix.
|
||||
///
|
||||
/// Example: `urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4`
|
||||
pub fn to_urn_str(&self) -> ~str {
|
||||
"urn:uuid:" + self.to_hyphenated_str()
|
||||
pub fn to_urn_str(&self) -> StrBuf {
|
||||
format_strbuf!("urn:uuid:{}", self.to_hyphenated_str())
|
||||
}
|
||||
|
||||
/// Parses a UUID from a string of hexadecimal digits with optional hyphens
|
||||
|
@ -493,7 +493,7 @@ impl TotalEq for Uuid {}
|
|||
impl<T: Encoder<E>, E> Encodable<T, E> for Uuid {
|
||||
/// Encode a UUID as a hypenated string
|
||||
fn encode(&self, e: &mut T) -> Result<(), E> {
|
||||
e.emit_str(self.to_hyphenated_str())
|
||||
e.emit_str(self.to_hyphenated_str().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ mod test {
|
|||
let s = uuid1.to_simple_str();
|
||||
|
||||
assert!(s.len() == 32);
|
||||
assert!(s.chars().all(|c| c.is_digit_radix(16)));
|
||||
assert!(s.as_slice().chars().all(|c| c.is_digit_radix(16)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -656,7 +656,7 @@ mod test {
|
|||
let s = uuid1.to_str();
|
||||
|
||||
assert!(s.len() == 32);
|
||||
assert!(s.chars().all(|c| c.is_digit_radix(16)));
|
||||
assert!(s.as_slice().chars().all(|c| c.is_digit_radix(16)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -665,18 +665,20 @@ mod test {
|
|||
let s = uuid1.to_hyphenated_str();
|
||||
|
||||
assert!(s.len() == 36);
|
||||
assert!(s.chars().all(|c| c.is_digit_radix(16) || c == '-'));
|
||||
assert!(s.as_slice().chars().all(|c| c.is_digit_radix(16) || c == '-'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_urn_str() {
|
||||
let uuid1 = Uuid::new_v4();
|
||||
let ss = uuid1.to_urn_str();
|
||||
let s = ss.slice(9, ss.len());
|
||||
let s = ss.as_slice().slice(9, ss.len());
|
||||
|
||||
assert!(ss.starts_with("urn:uuid:"));
|
||||
assert!(ss.as_slice().starts_with("urn:uuid:"));
|
||||
assert!(s.len() == 36);
|
||||
assert!(s.chars().all(|c| c.is_digit_radix(16) || c == '-'));
|
||||
assert!(s.as_slice()
|
||||
.chars()
|
||||
.all(|c| c.is_digit_radix(16) || c == '-'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -686,7 +688,8 @@ mod test {
|
|||
let hs = uuid1.to_hyphenated_str();
|
||||
let ss = uuid1.to_str();
|
||||
|
||||
let hsn = str::from_chars(hs.chars()
|
||||
let hsn = str::from_chars(hs.as_slice()
|
||||
.chars()
|
||||
.filter(|&c| c != '-')
|
||||
.collect::<Vec<char>>()
|
||||
.as_slice());
|
||||
|
@ -699,7 +702,7 @@ mod test {
|
|||
let uuid = Uuid::new_v4();
|
||||
|
||||
let hs = uuid.to_hyphenated_str();
|
||||
let uuid_hs = Uuid::parse_string(hs).unwrap();
|
||||
let uuid_hs = Uuid::parse_string(hs.as_slice()).unwrap();
|
||||
assert!(uuid_hs == uuid);
|
||||
|
||||
let ss = uuid.to_str();
|
||||
|
@ -727,7 +730,7 @@ mod test {
|
|||
|
||||
let u = Uuid::from_fields(d1, d2, d3, d4.as_slice());
|
||||
|
||||
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_owned();
|
||||
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_strbuf();
|
||||
let result = u.to_simple_str();
|
||||
assert!(result == expected);
|
||||
}
|
||||
|
@ -738,7 +741,7 @@ mod test {
|
|||
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 );
|
||||
|
||||
let u = Uuid::from_bytes(b.as_slice()).unwrap();
|
||||
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_owned();
|
||||
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_strbuf();
|
||||
|
||||
assert!(u.to_simple_str() == expected);
|
||||
}
|
||||
|
|
|
@ -103,31 +103,31 @@ use std::io::{File, MemWriter};
|
|||
|
||||
#[deriving(Clone, Eq, Encodable, Decodable, Ord, TotalOrd, TotalEq)]
|
||||
struct WorkKey {
|
||||
kind: ~str,
|
||||
name: ~str
|
||||
kind: StrBuf,
|
||||
name: StrBuf
|
||||
}
|
||||
|
||||
impl WorkKey {
|
||||
pub fn new(kind: &str, name: &str) -> WorkKey {
|
||||
WorkKey {
|
||||
kind: kind.to_owned(),
|
||||
name: name.to_owned(),
|
||||
kind: kind.to_strbuf(),
|
||||
name: name.to_strbuf(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME #8883: The key should be a WorkKey and not a ~str.
|
||||
// FIXME #8883: The key should be a WorkKey and not a StrBuf.
|
||||
// This is working around some JSON weirdness.
|
||||
#[deriving(Clone, Eq, Encodable, Decodable)]
|
||||
struct WorkMap(TreeMap<~str, KindMap>);
|
||||
struct WorkMap(TreeMap<StrBuf, KindMap>);
|
||||
|
||||
#[deriving(Clone, Eq, Encodable, Decodable)]
|
||||
struct KindMap(TreeMap<~str, ~str>);
|
||||
struct KindMap(TreeMap<StrBuf, StrBuf>);
|
||||
|
||||
impl WorkMap {
|
||||
fn new() -> WorkMap { WorkMap(TreeMap::new()) }
|
||||
|
||||
fn insert_work_key(&mut self, k: WorkKey, val: ~str) {
|
||||
fn insert_work_key(&mut self, k: WorkKey, val: StrBuf) {
|
||||
let WorkKey { kind, name } = k;
|
||||
let WorkMap(ref mut map) = *self;
|
||||
match map.find_mut(&name) {
|
||||
|
@ -142,7 +142,7 @@ impl WorkMap {
|
|||
|
||||
pub struct Database {
|
||||
db_filename: Path,
|
||||
db_cache: TreeMap<~str, ~str>,
|
||||
db_cache: TreeMap<StrBuf, StrBuf>,
|
||||
pub db_dirty: bool,
|
||||
}
|
||||
|
||||
|
@ -163,11 +163,11 @@ impl Database {
|
|||
pub fn prepare(&self,
|
||||
fn_name: &str,
|
||||
declared_inputs: &WorkMap)
|
||||
-> Option<(WorkMap, WorkMap, ~str)> {
|
||||
-> Option<(WorkMap, WorkMap, StrBuf)> {
|
||||
let k = json_encode(&(fn_name, declared_inputs));
|
||||
match self.db_cache.find(&k) {
|
||||
None => None,
|
||||
Some(v) => Some(json_decode(*v))
|
||||
Some(v) => Some(json_decode(v.as_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,14 @@ impl Database {
|
|||
// FIXME #4330: This should have &mut self and should set self.db_dirty to false.
|
||||
fn save(&self) -> io::IoResult<()> {
|
||||
let mut f = File::create(&self.db_filename);
|
||||
self.db_cache.to_json().to_pretty_writer(&mut f)
|
||||
|
||||
// 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.to_json().to_pretty_writer(&mut f)
|
||||
}
|
||||
|
||||
fn load(&mut self) {
|
||||
|
@ -222,7 +229,7 @@ impl Drop for Database {
|
|||
}
|
||||
}
|
||||
|
||||
pub type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>;
|
||||
pub type FreshnessMap = TreeMap<StrBuf,extern fn(&str,&str)->bool>;
|
||||
|
||||
#[deriving(Clone)]
|
||||
pub struct Context {
|
||||
|
@ -253,11 +260,11 @@ enum Work<'a, T> {
|
|||
WorkFromTask(&'a Prep<'a>, Receiver<(Exec, T)>),
|
||||
}
|
||||
|
||||
fn json_encode<'a, T:Encodable<json::Encoder<'a>, io::IoError>>(t: &T) -> ~str {
|
||||
fn json_encode<'a, T:Encodable<json::Encoder<'a>, io::IoError>>(t: &T) -> StrBuf {
|
||||
let mut writer = MemWriter::new();
|
||||
let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer);
|
||||
let _ = t.encode(&mut encoder);
|
||||
str::from_utf8(writer.unwrap().as_slice()).unwrap().to_owned()
|
||||
str::from_utf8(writer.unwrap().as_slice()).unwrap().to_strbuf()
|
||||
}
|
||||
|
||||
// FIXME(#5121)
|
||||
|
@ -308,7 +315,7 @@ impl Exec {
|
|||
dependency_val: &str) {
|
||||
debug!("Discovering input {} {} {}", dependency_kind, dependency_name, dependency_val);
|
||||
self.discovered_inputs.insert_work_key(WorkKey::new(dependency_kind, dependency_name),
|
||||
dependency_val.to_owned());
|
||||
dependency_val.to_strbuf());
|
||||
}
|
||||
pub fn discover_output(&mut self,
|
||||
dependency_kind: &str,
|
||||
|
@ -316,11 +323,11 @@ impl Exec {
|
|||
dependency_val: &str) {
|
||||
debug!("Discovering output {} {} {}", dependency_kind, dependency_name, dependency_val);
|
||||
self.discovered_outputs.insert_work_key(WorkKey::new(dependency_kind, dependency_name),
|
||||
dependency_val.to_owned());
|
||||
dependency_val.to_strbuf());
|
||||
}
|
||||
|
||||
// returns pairs of (kind, name)
|
||||
pub fn lookup_discovered_inputs(&self) -> Vec<(~str, ~str)> {
|
||||
pub fn lookup_discovered_inputs(&self) -> Vec<(StrBuf, StrBuf)> {
|
||||
let mut rs = vec![];
|
||||
let WorkMap(ref discovered_inputs) = self.discovered_inputs;
|
||||
for (k, v) in discovered_inputs.iter() {
|
||||
|
@ -342,7 +349,7 @@ impl<'a> Prep<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn lookup_declared_inputs(&self) -> Vec<~str> {
|
||||
pub fn lookup_declared_inputs(&self) -> Vec<StrBuf> {
|
||||
let mut rs = vec![];
|
||||
let WorkMap(ref declared_inputs) = self.declared_inputs;
|
||||
for (_, v) in declared_inputs.iter() {
|
||||
|
@ -359,12 +366,11 @@ impl<'a> Prep<'a> {
|
|||
pub fn declare_input(&mut self, kind: &str, name: &str, val: &str) {
|
||||
debug!("Declaring input {} {} {}", kind, name, val);
|
||||
self.declared_inputs.insert_work_key(WorkKey::new(kind, name),
|
||||
val.to_owned());
|
||||
val.to_strbuf());
|
||||
}
|
||||
|
||||
fn is_fresh(&self, cat: &str, kind: &str,
|
||||
name: &str, val: &str) -> bool {
|
||||
let k = kind.to_owned();
|
||||
fn is_fresh(&self, cat: &str, kind: &str, name: &str, val: &str) -> bool {
|
||||
let k = kind.to_strbuf();
|
||||
let f = self.ctxt.freshness.deref().find(&k);
|
||||
debug!("freshness for: {}/{}/{}/{}", cat, kind, name, val)
|
||||
let fresh = match f {
|
||||
|
@ -384,7 +390,10 @@ impl<'a> Prep<'a> {
|
|||
for (k_name, kindmap) in map.iter() {
|
||||
let KindMap(ref kindmap_) = *kindmap;
|
||||
for (k_kind, v) in kindmap_.iter() {
|
||||
if ! self.is_fresh(cat, *k_kind, *k_name, *v) {
|
||||
if !self.is_fresh(cat,
|
||||
k_kind.as_slice(),
|
||||
k_name.as_slice(),
|
||||
v.as_slice()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -420,7 +429,7 @@ impl<'a> Prep<'a> {
|
|||
debug!("Cache hit!");
|
||||
debug!("Trying to decode: {:?} / {:?} / {}",
|
||||
disc_in, disc_out, *res);
|
||||
Work::from_value(json_decode(*res))
|
||||
Work::from_value(json_decode(res.as_slice()))
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
@ -467,7 +476,7 @@ impl<'a, T:Send +
|
|||
&prep.declared_inputs,
|
||||
&exe.discovered_inputs,
|
||||
&exe.discovered_outputs,
|
||||
s);
|
||||
s.as_slice());
|
||||
v
|
||||
}
|
||||
}
|
||||
|
@ -484,7 +493,7 @@ fn test() {
|
|||
|
||||
// Create a path to a new file 'filename' in the directory in which
|
||||
// this test is running.
|
||||
fn make_path(filename: ~str) -> Path {
|
||||
fn make_path(filename: StrBuf) -> Path {
|
||||
let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename);
|
||||
if pth.exists() {
|
||||
fs::unlink(&pth).unwrap();
|
||||
|
@ -492,10 +501,10 @@ fn test() {
|
|||
return pth;
|
||||
}
|
||||
|
||||
let pth = make_path("foo.c".to_owned());
|
||||
let pth = make_path("foo.c".to_strbuf());
|
||||
File::create(&pth).write(bytes!("int main() { return 0; }")).unwrap();
|
||||
|
||||
let db_path = make_path("db.json".to_owned());
|
||||
let db_path = make_path("db.json".to_strbuf());
|
||||
|
||||
let cx = Context::new(Arc::new(RWLock::new(Database::new(db_path))),
|
||||
Arc::new(TreeMap::new()));
|
||||
|
@ -511,7 +520,7 @@ fn test() {
|
|||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
prep.declare_input("file", pth.as_str().unwrap(), file_content);
|
||||
prep.exec(proc(_exe) {
|
||||
let out = make_path("foo.o".to_owned());
|
||||
let out = make_path("foo.o".to_strbuf());
|
||||
let compiler = if cfg!(windows) {"gcc"} else {"cc"};
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
Process::status(compiler, [pth.as_str().unwrap().to_owned(),
|
||||
|
|
|
@ -13,7 +13,7 @@ pub mod kitties {
|
|||
meows : uint,
|
||||
|
||||
pub how_hungry : int,
|
||||
pub name : ~str,
|
||||
pub name : StrBuf,
|
||||
}
|
||||
|
||||
impl cat {
|
||||
|
@ -41,7 +41,7 @@ pub mod kitties {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||
pub fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
|
||||
cat {
|
||||
meows: in_x,
|
||||
how_hungry: in_y,
|
||||
|
|
|
@ -14,7 +14,7 @@ pub mod kitty {
|
|||
pub struct cat {
|
||||
meows : uint,
|
||||
pub how_hungry : int,
|
||||
pub name : ~str,
|
||||
pub name : StrBuf,
|
||||
}
|
||||
|
||||
impl fmt::Show for cat {
|
||||
|
@ -50,7 +50,7 @@ pub mod kitty {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||
pub fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
|
||||
cat {
|
||||
meows: in_x,
|
||||
how_hungry: in_y,
|
||||
|
|
|
@ -17,11 +17,11 @@ pub mod name_pool {
|
|||
pub type name_pool = ();
|
||||
|
||||
pub trait add {
|
||||
fn add(&self, s: ~str);
|
||||
fn add(&self, s: StrBuf);
|
||||
}
|
||||
|
||||
impl add for name_pool {
|
||||
fn add(&self, _s: ~str) {
|
||||
fn add(&self, _s: StrBuf) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
pub struct NameVal { pub name: ~str, pub val: int }
|
||||
pub struct NameVal { pub name: StrBuf, pub val: int }
|
||||
|
||||
pub fn struct_nameval() -> NameVal {
|
||||
NameVal { name: "crateresolve5".to_owned(), val: 10 }
|
||||
NameVal { name: "crateresolve5".to_strbuf(), val: 10 }
|
||||
}
|
||||
|
||||
pub enum e {
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
pub struct NameVal { pub name: ~str, pub val: int }
|
||||
pub struct NameVal { pub name: StrBuf, pub val: int }
|
||||
pub fn struct_nameval() -> NameVal {
|
||||
NameVal { name: "crateresolve5".to_owned(), val: 10 }
|
||||
NameVal { name: "crateresolve5".to_strbuf(), val: 10 }
|
||||
}
|
||||
|
||||
pub enum e {
|
||||
|
|
|
@ -14,7 +14,7 @@ pub trait Foo {
|
|||
}
|
||||
|
||||
pub struct Bar {
|
||||
pub x: ~str
|
||||
pub x: StrBuf
|
||||
}
|
||||
|
||||
impl Foo for Bar {
|
||||
|
|
|
@ -17,6 +17,6 @@ trait foo {
|
|||
fn foo(&self);
|
||||
}
|
||||
|
||||
impl foo for ~str {
|
||||
impl foo for StrBuf {
|
||||
fn foo(&self) {}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,11 @@ extern crate collections;
|
|||
use std::cell::RefCell;
|
||||
use collections::HashMap;
|
||||
|
||||
pub type header_map = HashMap<~str, @RefCell<Vec<@~str>>>;
|
||||
pub type header_map = HashMap<StrBuf, @RefCell<Vec<@StrBuf>>>;
|
||||
|
||||
// the unused ty param is necessary so this gets monomorphized
|
||||
pub fn request<T>(req: &header_map) {
|
||||
let _x = (**((**req.get(&"METHOD".to_owned())).clone()).borrow().clone().get(0)).clone();
|
||||
let _x = (**((**req.get(&"METHOD".to_strbuf())).clone()).borrow()
|
||||
.clone()
|
||||
.get(0)).clone();
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub mod testtypes {
|
|||
// Tests ty_float (does not test all variants of FloatTy)
|
||||
pub type FooFloat = f64;
|
||||
|
||||
// For ty_str, what kind of string should I use? &'static str? ~str? Raw str?
|
||||
// For ty_str, what kind of string should I use? &'static str? StrBuf? Raw str?
|
||||
|
||||
// Tests ty_enum
|
||||
pub enum FooEnum {
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
#![crate_type = "lib"]
|
||||
|
||||
trait to_strz {
|
||||
fn to_strz() -> ~str;
|
||||
fn to_strz() -> StrBuf;
|
||||
}
|
||||
|
||||
impl to_strz for ~str {
|
||||
fn to_strz() -> ~str { self.clone() }
|
||||
impl to_strz for StrBuf {
|
||||
fn to_strz() -> StrBuf { self.clone() }
|
||||
}
|
||||
|
|
|
@ -16,5 +16,5 @@ extern crate a;
|
|||
use a::to_strz;
|
||||
|
||||
impl to_strz for bool {
|
||||
fn to_strz() -> ~str { fmt!("%b", self) }
|
||||
fn to_strz() -> StrBuf { fmt!("%b", self) }
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub mod sub_foo {
|
|||
}
|
||||
|
||||
pub struct Boz {
|
||||
unused_str: ~str
|
||||
unused_str: StrBuf
|
||||
}
|
||||
|
||||
impl Boz {
|
||||
|
@ -46,8 +46,8 @@ pub mod sub_foo {
|
|||
}
|
||||
|
||||
impl Bort {
|
||||
pub fn bort() -> ~str {
|
||||
"bort()".to_owned()
|
||||
pub fn bort() -> StrBuf {
|
||||
"bort()".to_strbuf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
use std::int;
|
||||
|
||||
pub trait read {
|
||||
fn readMaybe(s: ~str) -> Option<Self>;
|
||||
fn readMaybe(s: StrBuf) -> Option<Self>;
|
||||
}
|
||||
|
||||
impl read for int {
|
||||
fn readMaybe(s: ~str) -> Option<int> {
|
||||
from_str::<int>(s)
|
||||
fn readMaybe(s: StrBuf) -> Option<int> {
|
||||
from_str::<int>(s.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl read for bool {
|
||||
fn readMaybe(s: ~str) -> Option<bool> {
|
||||
fn readMaybe(s: StrBuf) -> Option<bool> {
|
||||
match s.as_slice() {
|
||||
"true" => Some(true),
|
||||
"false" => Some(false),
|
||||
|
@ -33,7 +33,7 @@ impl read for bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read<T:read>(s: ~str) -> T {
|
||||
pub fn read<T:read>(s: StrBuf) -> T {
|
||||
match read::readMaybe(s) {
|
||||
Some(x) => x,
|
||||
_ => fail!("read failed!")
|
||||
|
|
|
@ -80,7 +80,7 @@ impl Results {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn bench_str<T:MutableSet<~str>,
|
||||
pub fn bench_str<T:MutableSet<StrBuf>,
|
||||
R:rand::Rng>(
|
||||
&mut self,
|
||||
rng: &mut R,
|
||||
|
@ -90,11 +90,11 @@ impl Results {
|
|||
let mut set = f();
|
||||
timed(&mut self.sequential_strings, || {
|
||||
for i in range(0u, num_keys) {
|
||||
set.insert(i.to_str());
|
||||
set.insert(i.to_str().to_strbuf());
|
||||
}
|
||||
|
||||
for i in range(0u, num_keys) {
|
||||
assert!(set.contains(&i.to_str()));
|
||||
assert!(set.contains(&i.to_str().to_strbuf()));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ impl Results {
|
|||
let mut set = f();
|
||||
timed(&mut self.random_strings, || {
|
||||
for _ in range(0, num_keys) {
|
||||
let s = rng.gen::<uint>().to_str();
|
||||
let s = rng.gen::<uint>().to_str().to_strbuf();
|
||||
set.insert(s);
|
||||
}
|
||||
})
|
||||
|
@ -112,11 +112,11 @@ impl Results {
|
|||
{
|
||||
let mut set = f();
|
||||
for i in range(0u, num_keys) {
|
||||
set.insert(i.to_str());
|
||||
set.insert(i.to_str().to_strbuf());
|
||||
}
|
||||
timed(&mut self.delete_strings, || {
|
||||
for i in range(0u, num_keys) {
|
||||
assert!(set.remove(&i.to_str()));
|
||||
assert!(set.remove(&i.to_str().to_strbuf()));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ fn main() {
|
|||
s
|
||||
});
|
||||
results.bench_str(&mut rng, num_keys, || {
|
||||
let s: HashSet<~str> = HashSet::new();
|
||||
let s: HashSet<StrBuf> = HashSet::new();
|
||||
s
|
||||
});
|
||||
write_results("collections::HashSet", &results);
|
||||
|
@ -189,7 +189,7 @@ fn main() {
|
|||
s
|
||||
});
|
||||
results.bench_str(&mut rng, num_keys, || {
|
||||
let s: TreeSet<~str> = TreeSet::new();
|
||||
let s: TreeSet<StrBuf> = TreeSet::new();
|
||||
s
|
||||
});
|
||||
write_results("collections::TreeSet", &results);
|
||||
|
|
|
@ -24,11 +24,13 @@ use std::vec;
|
|||
use std::io::File;
|
||||
|
||||
macro_rules! bench (
|
||||
($argv:expr, $id:ident) => (maybe_run_test($argv.as_slice(), stringify!($id).to_owned(), $id))
|
||||
($argv:expr, $id:ident) => (maybe_run_test($argv.as_slice(),
|
||||
stringify!($id).to_strbuf(),
|
||||
$id))
|
||||
)
|
||||
|
||||
fn main() {
|
||||
let argv = os::args();
|
||||
let argv = os::args().move_iter().map(|x| x.to_strbuf()).collect::<Vec<StrBuf>>();
|
||||
let _tests = argv.slice(1, argv.len());
|
||||
|
||||
bench!(argv, shift_push);
|
||||
|
@ -40,13 +42,13 @@ fn main() {
|
|||
bench!(argv, is_utf8_multibyte);
|
||||
}
|
||||
|
||||
fn maybe_run_test(argv: &[~str], name: ~str, test: ||) {
|
||||
fn maybe_run_test(argv: &[StrBuf], name: StrBuf, test: ||) {
|
||||
let mut run_test = false;
|
||||
|
||||
if os::getenv("RUST_BENCH").is_some() {
|
||||
run_test = true
|
||||
} else if argv.len() > 0 {
|
||||
run_test = argv.iter().any(|x| x == &"all".to_owned()) || argv.iter().any(|x| x == &name)
|
||||
run_test = argv.iter().any(|x| x == &"all".to_strbuf()) || argv.iter().any(|x| x == &name)
|
||||
}
|
||||
|
||||
if !run_test {
|
||||
|
|
|
@ -52,12 +52,12 @@ fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
|
|||
//println!("server exiting");
|
||||
}
|
||||
|
||||
fn run(args: &[~str]) {
|
||||
fn run(args: &[StrBuf]) {
|
||||
let (to_parent, from_child) = channel();
|
||||
let (to_child, from_parent) = channel();
|
||||
|
||||
let size = from_str::<uint>(args[1]).unwrap();
|
||||
let workers = from_str::<uint>(args[2]).unwrap();
|
||||
let size = from_str::<uint>(args[1].as_slice()).unwrap();
|
||||
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
|
||||
let num_bytes = 100;
|
||||
let start = time::precise_time_s();
|
||||
let mut worker_results = Vec::new();
|
||||
|
@ -97,13 +97,13 @@ fn run(args: &[~str]) {
|
|||
fn main() {
|
||||
let args = os::args();
|
||||
let args = if os::getenv("RUST_BENCH").is_some() {
|
||||
vec!("".to_owned(), "1000000".to_owned(), "10000".to_owned())
|
||||
vec!("".to_strbuf(), "1000000".to_strbuf(), "10000".to_strbuf())
|
||||
} else if args.len() <= 1u {
|
||||
vec!("".to_owned(), "10000".to_owned(), "4".to_owned())
|
||||
vec!("".to_strbuf(), "10000".to_strbuf(), "4".to_strbuf())
|
||||
} else {
|
||||
args.clone().move_iter().collect()
|
||||
args.move_iter().map(|x| x.to_strbuf()).collect()
|
||||
};
|
||||
|
||||
println!("{:?}", args);
|
||||
println!("{}", args);
|
||||
run(args.as_slice());
|
||||
}
|
||||
|
|
|
@ -47,11 +47,11 @@ fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
|
|||
//println!("server exiting");
|
||||
}
|
||||
|
||||
fn run(args: &[~str]) {
|
||||
fn run(args: &[StrBuf]) {
|
||||
let (to_parent, from_child) = channel();
|
||||
|
||||
let size = from_str::<uint>(args[1]).unwrap();
|
||||
let workers = from_str::<uint>(args[2]).unwrap();
|
||||
let size = from_str::<uint>(args[1].as_slice()).unwrap();
|
||||
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
|
||||
let num_bytes = 100;
|
||||
let start = time::precise_time_s();
|
||||
let mut worker_results = Vec::new();
|
||||
|
@ -107,11 +107,11 @@ fn run(args: &[~str]) {
|
|||
fn main() {
|
||||
let args = os::args();
|
||||
let args = if os::getenv("RUST_BENCH").is_some() {
|
||||
vec!("".to_owned(), "1000000".to_owned(), "8".to_owned())
|
||||
vec!("".to_strbuf(), "1000000".to_strbuf(), "8".to_strbuf())
|
||||
} else if args.len() <= 1u {
|
||||
vec!("".to_owned(), "10000".to_owned(), "4".to_owned())
|
||||
vec!("".to_strbuf(), "10000".to_strbuf(), "4".to_strbuf())
|
||||
} else {
|
||||
args.clone().move_iter().collect()
|
||||
args.clone().move_iter().map(|x| x.to_strbuf()).collect()
|
||||
};
|
||||
|
||||
println!("{:?}", args);
|
||||
|
|
|
@ -74,10 +74,10 @@ fn main() {
|
|||
let b = bottom_up_tree(&arena, -i, depth);
|
||||
chk += item_check(a) + item_check(b);
|
||||
}
|
||||
format!("{}\t trees of depth {}\t check: {}",
|
||||
iterations * 2, depth, chk)
|
||||
format_strbuf!("{}\t trees of depth {}\t check: {}",
|
||||
iterations * 2, depth, chk)
|
||||
})
|
||||
}).collect::<Vec<Future<~str>>>();
|
||||
}).collect::<Vec<Future<StrBuf>>>();
|
||||
|
||||
for message in messages.mut_iter() {
|
||||
println!("{}", *message.get_ref());
|
||||
|
|
|
@ -107,7 +107,7 @@ fn creature(
|
|||
mut color: Color,
|
||||
from_rendezvous: Receiver<CreatureInfo>,
|
||||
to_rendezvous: Sender<CreatureInfo>,
|
||||
to_rendezvous_log: Sender<~str>
|
||||
to_rendezvous_log: Sender<StrBuf>
|
||||
) {
|
||||
let mut creatures_met = 0;
|
||||
let mut evil_clones_met = 0;
|
||||
|
@ -132,7 +132,9 @@ fn creature(
|
|||
}
|
||||
}
|
||||
// log creatures met and evil clones of self
|
||||
let report = format!("{}{}", creatures_met, Number(evil_clones_met));
|
||||
let report = format_strbuf!("{}{}",
|
||||
creatures_met,
|
||||
Number(evil_clones_met));
|
||||
to_rendezvous_log.send(report);
|
||||
}
|
||||
|
||||
|
@ -141,7 +143,7 @@ fn rendezvous(nn: uint, set: Vec<Color>) {
|
|||
let (to_rendezvous, from_creatures) = channel::<CreatureInfo>();
|
||||
|
||||
// these channels will be passed to the creatures so they can talk to us
|
||||
let (to_rendezvous_log, from_creatures_log) = channel::<~str>();
|
||||
let (to_rendezvous_log, from_creatures_log) = channel::<StrBuf>();
|
||||
|
||||
// these channels will allow us to talk to each creature by 'name'/index
|
||||
let mut to_creature: Vec<Sender<CreatureInfo>> =
|
||||
|
|
|
@ -37,7 +37,7 @@ fn f64_cmp(x: f64, y: f64) -> Ordering {
|
|||
}
|
||||
|
||||
// given a map, print a sorted version of it
|
||||
fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> ~str {
|
||||
fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> StrBuf {
|
||||
fn pct(xx: uint, yy: uint) -> f64 {
|
||||
return (xx as f64) * 100.0 / (yy as f64);
|
||||
}
|
||||
|
@ -67,12 +67,12 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> ~str {
|
|||
.into_str(), v));
|
||||
}
|
||||
|
||||
return buffer.into_owned();
|
||||
return buffer
|
||||
}
|
||||
|
||||
// given a map, search for the frequency of a pattern
|
||||
fn find(mm: &HashMap<Vec<u8> , uint>, key: ~str) -> uint {
|
||||
let key = key.into_ascii().as_slice().to_lower().into_str();
|
||||
fn find(mm: &HashMap<Vec<u8> , uint>, key: StrBuf) -> uint {
|
||||
let key = key.to_owned().into_ascii().as_slice().to_lower().into_str();
|
||||
match mm.find_equiv(&key.as_bytes()) {
|
||||
option::None => { return 0u; }
|
||||
option::Some(&num) => { return num; }
|
||||
|
@ -106,7 +106,7 @@ fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> Vec<u8> {
|
|||
|
||||
fn make_sequence_processor(sz: uint,
|
||||
from_parent: &Receiver<Vec<u8>>,
|
||||
to_parent: &Sender<~str>) {
|
||||
to_parent: &Sender<StrBuf>) {
|
||||
let mut freqs: HashMap<Vec<u8>, uint> = HashMap::new();
|
||||
let mut carry = Vec::new();
|
||||
let mut total: uint = 0u;
|
||||
|
@ -129,13 +129,13 @@ fn make_sequence_processor(sz: uint,
|
|||
let buffer = match sz {
|
||||
1u => { sort_and_fmt(&freqs, total) }
|
||||
2u => { sort_and_fmt(&freqs, total) }
|
||||
3u => { format!("{}\t{}", find(&freqs, "GGT".to_owned()), "GGT") }
|
||||
4u => { format!("{}\t{}", find(&freqs, "GGTA".to_owned()), "GGTA") }
|
||||
6u => { format!("{}\t{}", find(&freqs, "GGTATT".to_owned()), "GGTATT") }
|
||||
12u => { format!("{}\t{}", find(&freqs, "GGTATTTTAATT".to_owned()), "GGTATTTTAATT") }
|
||||
18u => { format!("{}\t{}", find(&freqs, "GGTATTTTAATTTATAGT".to_owned()),
|
||||
3u => { format_strbuf!("{}\t{}", find(&freqs, "GGT".to_strbuf()), "GGT") }
|
||||
4u => { format_strbuf!("{}\t{}", find(&freqs, "GGTA".to_strbuf()), "GGTA") }
|
||||
6u => { format_strbuf!("{}\t{}", find(&freqs, "GGTATT".to_strbuf()), "GGTATT") }
|
||||
12u => { format_strbuf!("{}\t{}", find(&freqs, "GGTATTTTAATT".to_strbuf()), "GGTATTTTAATT") }
|
||||
18u => { format_strbuf!("{}\t{}", find(&freqs, "GGTATTTTAATTTATAGT".to_strbuf()),
|
||||
"GGTATTTTAATTTATAGT") }
|
||||
_ => { "".to_owned() }
|
||||
_ => { "".to_strbuf() }
|
||||
};
|
||||
|
||||
to_parent.send(buffer);
|
||||
|
@ -155,7 +155,7 @@ fn main() {
|
|||
|
||||
// initialize each sequence sorter
|
||||
let sizes = vec!(1u,2,3,4,6,12,18);
|
||||
let mut streams = Vec::from_fn(sizes.len(), |_| Some(channel::<~str>()));
|
||||
let mut streams = Vec::from_fn(sizes.len(), |_| Some(channel::<StrBuf>()));
|
||||
let mut from_child = Vec::new();
|
||||
let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| {
|
||||
let sz = *sz;
|
||||
|
|
|
@ -184,7 +184,7 @@ fn get_id(m: u64) -> u8 {
|
|||
fail!("{:016x} does not have a valid identifier", m);
|
||||
}
|
||||
|
||||
// Converts a list of mask to a ~str.
|
||||
// Converts a list of mask to a StrBuf.
|
||||
fn to_vec(raw_sol: &List<u64>) -> Vec<u8> {
|
||||
let mut sol = Vec::from_elem(50, '.' as u8);
|
||||
for &m in raw_sol.iter() {
|
||||
|
@ -198,7 +198,7 @@ fn to_vec(raw_sol: &List<u64>) -> Vec<u8> {
|
|||
sol
|
||||
}
|
||||
|
||||
// Prints a solution in ~str form.
|
||||
// Prints a solution in StrBuf form.
|
||||
fn print_sol(sol: &Vec<u8>) {
|
||||
for (i, c) in sol.iter().enumerate() {
|
||||
if (i) % 5 == 0 { println!(""); }
|
||||
|
|
|
@ -52,9 +52,10 @@ struct Config {
|
|||
stress: bool
|
||||
}
|
||||
|
||||
fn parse_opts(argv: Vec<~str> ) -> 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 opt_args = argv.slice(1, argv.len());
|
||||
|
||||
match getopts::getopts(opt_args, opts.as_slice()) {
|
||||
|
@ -92,11 +93,11 @@ fn stress(num_tasks: int) {
|
|||
fn main() {
|
||||
let args = os::args();
|
||||
let args = if os::getenv("RUST_BENCH").is_some() {
|
||||
vec!("".to_owned(), "20".to_owned())
|
||||
vec!("".to_strbuf(), "20".to_strbuf())
|
||||
} else if args.len() <= 1u {
|
||||
vec!("".to_owned(), "8".to_owned())
|
||||
vec!("".to_strbuf(), "8".to_strbuf())
|
||||
} else {
|
||||
args.move_iter().collect()
|
||||
args.move_iter().map(|x| x.to_strbuf()).collect()
|
||||
};
|
||||
|
||||
let opts = parse_opts(args.clone());
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:expected `~str` but found `int`
|
||||
// error-pattern:expected `std::strbuf::StrBuf` but found `int`
|
||||
|
||||
static i: ~str = 10i;
|
||||
fn main() { println!("{:?}", i); }
|
||||
static i: StrBuf = 10i;
|
||||
fn main() { println!("{}", i); }
|
||||
|
|
|
@ -12,4 +12,4 @@
|
|||
|
||||
mod m1 {}
|
||||
|
||||
fn main(args: Vec<~str>) { log(debug, m1::a); }
|
||||
fn main(args: Vec<StrBuf>) { log(debug, m1::a); }
|
||||
|
|
|
@ -14,6 +14,6 @@ mod m1 {
|
|||
pub mod a {}
|
||||
}
|
||||
|
||||
fn main(args: Vec<~str>) {
|
||||
fn main(args: Vec<StrBuf>) {
|
||||
log(debug, m1::a);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:`^` cannot be applied to type `~str`
|
||||
// error-pattern:`^` cannot be applied to type `std::strbuf::StrBuf`
|
||||
|
||||
fn main() { let x = "a".to_owned() ^ "b".to_owned(); }
|
||||
fn main() { let x = "a".to_strbuf() ^ "b".to_strbuf(); }
|
||||
|
|
|
@ -26,15 +26,15 @@ fn blah() {
|
|||
}
|
||||
|
||||
struct S {
|
||||
f: ~str,
|
||||
g: ~str
|
||||
f: StrBuf,
|
||||
g: StrBuf
|
||||
}
|
||||
impl Drop for S {
|
||||
fn drop(&mut self) { println!("{}", self.f); }
|
||||
}
|
||||
|
||||
fn move_in_match() {
|
||||
match S {f: "foo".to_owned(), g: "bar".to_owned()} {
|
||||
match S {f: "foo".to_strbuf(), g: "bar".to_strbuf()} {
|
||||
S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
|
||||
f: _s, //~ NOTE attempting to move value to here
|
||||
g: _t //~ NOTE and here
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn with(f: |&~str|) {}
|
||||
fn with(f: |&StrBuf|) {}
|
||||
|
||||
fn arg_item(&_x: &~str) {}
|
||||
fn arg_item(&_x: &StrBuf) {}
|
||||
//~^ ERROR cannot move out of dereference of `&`-pointer
|
||||
|
||||
fn arg_closure() {
|
||||
|
|
|
@ -8,20 +8,20 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
struct S {f:~str}
|
||||
struct S {f:StrBuf}
|
||||
impl Drop for S {
|
||||
fn drop(&mut self) { println!("{}", self.f); }
|
||||
}
|
||||
|
||||
fn move_in_match() {
|
||||
match S {f:"foo".to_owned()} {
|
||||
match S {f:"foo".to_strbuf()} {
|
||||
S {f:_s} => {}
|
||||
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
|
||||
}
|
||||
}
|
||||
|
||||
fn move_in_let() {
|
||||
let S {f:_s} = S {f:"foo".to_owned()};
|
||||
let S {f:_s} = S {f:"foo".to_strbuf()};
|
||||
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
|
||||
}
|
||||
|
||||
|
|
|
@ -8,20 +8,20 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
struct S(~str);
|
||||
struct S(StrBuf);
|
||||
impl Drop for S {
|
||||
fn drop(&mut self) { }
|
||||
}
|
||||
|
||||
fn move_in_match() {
|
||||
match S("foo".to_owned()) {
|
||||
match S("foo".to_strbuf()) {
|
||||
S(_s) => {}
|
||||
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
|
||||
}
|
||||
}
|
||||
|
||||
fn move_in_let() {
|
||||
let S(_s) = S("foo".to_owned());
|
||||
let S(_s) = S("foo".to_strbuf());
|
||||
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
|
||||
}
|
||||
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
|
||||
#[deriving(Clone)]
|
||||
struct Foo {
|
||||
string: ~str
|
||||
string: StrBuf
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let x = vec!(
|
||||
Foo { string: "foo".to_owned() },
|
||||
Foo { string: "bar".to_owned() },
|
||||
Foo { string: "baz".to_owned() }
|
||||
Foo { string: "foo".to_strbuf() },
|
||||
Foo { string: "bar".to_strbuf() },
|
||||
Foo { string: "baz".to_strbuf() }
|
||||
);
|
||||
let x: &[Foo] = x.as_slice();
|
||||
match x {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
struct Foo {
|
||||
t: ~str
|
||||
t: StrBuf
|
||||
}
|
||||
|
||||
fn cond() -> bool { true }
|
||||
|
|
|
@ -10,17 +10,17 @@
|
|||
|
||||
enum E {
|
||||
Foo,
|
||||
Bar(~str)
|
||||
Bar(StrBuf)
|
||||
}
|
||||
|
||||
struct S {
|
||||
x: E
|
||||
}
|
||||
|
||||
fn f(x: ~str) {}
|
||||
fn f(x: StrBuf) {}
|
||||
|
||||
fn main() {
|
||||
let s = S { x: Bar("hello".to_owned()) };
|
||||
let s = S { x: Bar("hello".to_strbuf()) };
|
||||
match &s.x {
|
||||
&Foo => {}
|
||||
&Bar(identifier) => f(identifier.clone()) //~ ERROR cannot move
|
||||
|
|
|
@ -27,7 +27,7 @@ enum SafeEnum {
|
|||
Variant1,
|
||||
Variant2(int),
|
||||
Variant3(WithDtor),
|
||||
Variant4(~str)
|
||||
Variant4(StrBuf)
|
||||
}
|
||||
|
||||
// These should be ok
|
||||
|
@ -106,8 +106,11 @@ static mut STATIC12: UnsafeStruct = UnsafeStruct;
|
|||
static mut STATIC13: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3(WithDtor)};
|
||||
//~^ ERROR mutable static items are not allowed to have destructors
|
||||
|
||||
static mut STATIC14: SafeStruct = SafeStruct{field1: Variant1, field2: Variant4("str".to_owned())};
|
||||
static mut STATIC14: SafeStruct = SafeStruct {
|
||||
//~^ ERROR mutable static items are not allowed to have destructors
|
||||
field1: Variant1,
|
||||
field2: Variant4("str".to_strbuf())
|
||||
};
|
||||
|
||||
static STATIC15: &'static [Box<MyOwned>] = &'static [box MyOwned, box MyOwned];
|
||||
//~^ ERROR static items are not allowed to have owned pointers
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
mod circular_modules_hello; //~ERROR: circular modules
|
||||
|
||||
pub fn hi_str() -> ~str {
|
||||
pub fn hi_str() -> StrBuf {
|
||||
"Hi!".to_owned()
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ struct cat {
|
|||
meows : uint,
|
||||
|
||||
how_hungry : int,
|
||||
name : ~str,
|
||||
name : StrBuf,
|
||||
}
|
||||
|
||||
impl cat {
|
||||
|
@ -49,7 +49,7 @@ impl cat {
|
|||
}
|
||||
}
|
||||
|
||||
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||
fn cat(in_x : uint, in_y : int, in_name: StrBuf) -> cat {
|
||||
cat {
|
||||
meows: in_x,
|
||||
how_hungry: in_y,
|
||||
|
@ -58,6 +58,6 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let nyan: Box<noisy> = box cat(0, 2, "nyan".to_owned()) as Box<noisy>;
|
||||
let nyan: Box<noisy> = box cat(0, 2, "nyan".to_strbuf()) as Box<noisy>;
|
||||
nyan.eat(); //~ ERROR does not implement any method in scope named `eat`
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
struct X {
|
||||
x: ~str,
|
||||
x: StrBuf,
|
||||
}
|
||||
|
||||
impl Drop for X {
|
||||
|
@ -18,13 +18,13 @@ impl Drop for X {
|
|||
}
|
||||
}
|
||||
|
||||
fn unwrap(x: X) -> ~str {
|
||||
fn unwrap(x: X) -> StrBuf {
|
||||
let X { x: y } = x; //~ ERROR cannot move out of type
|
||||
y
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = X { x: "hello".to_owned() };
|
||||
let x = X { x: "hello".to_strbuf() };
|
||||
let y = unwrap(x);
|
||||
println!("contents: {}", y);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
struct X {
|
||||
x: ~str,
|
||||
x: StrBuf,
|
||||
}
|
||||
|
||||
impl Drop for X {
|
||||
|
@ -19,7 +19,7 @@ impl Drop for X {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let x = X { x: "hello".to_owned() };
|
||||
let x = X { x: "hello".to_strbuf() };
|
||||
|
||||
match x {
|
||||
X { x: y } => println!("contents: {}", y)
|
||||
|
|
|
@ -8,16 +8,16 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn wants_uniq(x: ~str) { }
|
||||
fn wants_uniq(x: StrBuf) { }
|
||||
fn wants_slice(x: &str) { }
|
||||
|
||||
fn has_uniq(x: ~str) {
|
||||
fn has_uniq(x: StrBuf) {
|
||||
wants_uniq(x);
|
||||
wants_slice(x);
|
||||
wants_slice(x.as_slice());
|
||||
}
|
||||
|
||||
fn has_slice(x: &str) {
|
||||
wants_uniq(x); //~ ERROR mismatched types: expected `~str` but found `&str` (expected box but f
|
||||
wants_uniq(x); //~ ERROR mismatched types
|
||||
wants_slice(x);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ fn main() {
|
|||
//~^ ERROR mismatched types: expected `Foo<int>` but found `()`
|
||||
|
||||
// Including cases where the default is using previous type params.
|
||||
let _: HashMap<~str, int> = ();
|
||||
//~^ ERROR mismatched types: expected `HashMap<~str,int>` but found `()`
|
||||
let _: HashMap<~str, int, Hash<~str>> = ();
|
||||
//~^ ERROR mismatched types: expected `HashMap<~str,int>` but found `()`
|
||||
let _: HashMap<StrBuf, int> = ();
|
||||
//~^ ERROR mismatched types: expected `HashMap<std::strbuf::StrBuf,int>` but found `()`
|
||||
let _: HashMap<StrBuf, int, Hash<StrBuf>> = ();
|
||||
//~^ ERROR mismatched types: expected `HashMap<std::strbuf::StrBuf,int>` but found `()`
|
||||
|
||||
// But not when there's a different type in between.
|
||||
let _: Foo<A, int, C> = ();
|
||||
|
|
|
@ -16,4 +16,4 @@ use zed::baz;
|
|||
mod zed {
|
||||
pub fn bar() { println!("bar"); }
|
||||
}
|
||||
fn main(args: Vec<~str>) { bar(); }
|
||||
fn main(args: Vec<StrBuf>) { bar(); }
|
||||
|
|
|
@ -16,4 +16,4 @@ mod baz {}
|
|||
mod zed {
|
||||
pub fn bar() { println!("bar3"); }
|
||||
}
|
||||
fn main(args: Vec<~str>) { bar(); }
|
||||
fn main(args: Vec<StrBuf>) { bar(); }
|
||||
|
|
|
@ -10,17 +10,17 @@
|
|||
|
||||
pub fn main() {
|
||||
let v: Vec<int> = vec!(0, 1, 2, 3, 4, 5);
|
||||
let s: ~str = "abcdef".to_owned();
|
||||
let s: StrBuf = "abcdef".to_strbuf();
|
||||
assert_eq!(v.as_slice()[3u], 3);
|
||||
assert_eq!(v.as_slice()[3u8], 3); //~ ERROR: mismatched types
|
||||
assert_eq!(v.as_slice()[3i8], 3); //~ ERROR: mismatched types
|
||||
assert_eq!(v.as_slice()[3u32], 3); //~ ERROR: mismatched types
|
||||
assert_eq!(v.as_slice()[3i32], 3); //~ ERROR: mismatched types
|
||||
println!("{}", v.as_slice()[3u8]); //~ ERROR: mismatched types
|
||||
assert_eq!(s[3u], 'd' as u8);
|
||||
assert_eq!(s[3u8], 'd' as u8); //~ ERROR: mismatched types
|
||||
assert_eq!(s[3i8], 'd' as u8); //~ ERROR: mismatched types
|
||||
assert_eq!(s[3u32], 'd' as u8); //~ ERROR: mismatched types
|
||||
assert_eq!(s[3i32], 'd' as u8); //~ ERROR: mismatched types
|
||||
println!("{}", s[3u8]); //~ ERROR: mismatched types
|
||||
assert_eq!(s.as_slice()[3u], 'd' as u8);
|
||||
assert_eq!(s.as_slice()[3u8], 'd' as u8); //~ ERROR: mismatched types
|
||||
assert_eq!(s.as_slice()[3i8], 'd' as u8); //~ ERROR: mismatched types
|
||||
assert_eq!(s.as_slice()[3u32], 'd' as u8); //~ ERROR: mismatched types
|
||||
assert_eq!(s.as_slice()[3i32], 'd' as u8); //~ ERROR: mismatched types
|
||||
println!("{}", s.as_slice()[3u8]); //~ ERROR: mismatched types
|
||||
}
|
||||
|
|
|
@ -10,16 +10,16 @@
|
|||
|
||||
// Regression test for #13428
|
||||
|
||||
fn foo() -> ~str { //~ ERROR not all control paths return a value
|
||||
format!("Hello {}",
|
||||
"world")
|
||||
fn foo() -> StrBuf { //~ ERROR not all control paths return a value
|
||||
format_strbuf!("Hello {}",
|
||||
"world")
|
||||
// Put the trailing semicolon on its own line to test that the
|
||||
// note message gets the offending semicolon exactly
|
||||
; //~ NOTE consider removing this semicolon
|
||||
}
|
||||
|
||||
fn bar() -> ~str { //~ ERROR not all control paths return a value
|
||||
"foobar".to_owned()
|
||||
fn bar() -> StrBuf { //~ ERROR not all control paths return a value
|
||||
"foobar".to_strbuf()
|
||||
; //~ NOTE consider removing this semicolon
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
struct t(Box<t>); //~ ERROR this type cannot be instantiated
|
||||
|
||||
trait to_str_2 {
|
||||
fn my_to_str() -> ~str;
|
||||
fn my_to_str() -> StrBuf;
|
||||
}
|
||||
|
||||
// I use an impl here because it will cause
|
||||
// the compiler to attempt autoderef and then
|
||||
// try to resolve the method.
|
||||
impl to_str_2 for t {
|
||||
fn my_to_str() -> ~str { "t".to_owned() }
|
||||
fn my_to_str() -> StrBuf { "t".to_strbuf() }
|
||||
}
|
||||
|
||||
fn new_t(x: t) {
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn a(x: ~str) -> ~str {
|
||||
fn a(x: StrBuf) -> StrBuf {
|
||||
format!("First function with {}", x)
|
||||
}
|
||||
|
||||
fn a(x: ~str, y: ~str) -> ~str { //~ ERROR duplicate definition of value `a`
|
||||
fn a(x: StrBuf, y: StrBuf) -> StrBuf { //~ ERROR duplicate definition of value `a`
|
||||
format!("Second function with {} and {}", x, y)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
|
||||
struct HTMLImageData {
|
||||
image: Option<~str>
|
||||
image: Option<StrBuf>
|
||||
}
|
||||
|
||||
struct ElementData {
|
||||
|
|
|
@ -22,7 +22,7 @@ impl ToStr for Point { //~ ERROR implements a method not defined in the trait
|
|||
Point { x: x, y: y }
|
||||
}
|
||||
|
||||
fn to_str(&self) -> ~str {
|
||||
fn to_str(&self) -> StrBuf {
|
||||
format!("({}, {})", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
use std::io::ReaderUtil;
|
||||
use std::io::Reader;
|
||||
|
||||
fn bar(r:@ReaderUtil) -> ~str { r.read_line() }
|
||||
fn bar(r:@ReaderUtil) -> StrBuf { r.read_line() }
|
||||
|
||||
fn main() {
|
||||
let r : @Reader = io::stdin();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn foo(b: bool) -> Result<bool,~str> {
|
||||
fn foo(b: bool) -> Result<bool,StrBuf> {
|
||||
Err("bar".to_owned());
|
||||
//~^ ERROR: cannot determine a type for this expression: unconstrained type
|
||||
}
|
||||
|
|
|
@ -10,15 +10,15 @@
|
|||
|
||||
|
||||
pub struct CrateId {
|
||||
local_path: ~str,
|
||||
junk: ~str
|
||||
local_path: StrBuf,
|
||||
junk: StrBuf
|
||||
}
|
||||
|
||||
impl CrateId {
|
||||
fn new(s: &str) -> CrateId {
|
||||
CrateId {
|
||||
local_path: s.to_owned(),
|
||||
junk: "wutevs".to_owned()
|
||||
local_path: s.to_strbuf(),
|
||||
junk: "wutevs".to_strbuf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ trait ManyImplTrait {
|
|||
}
|
||||
}
|
||||
|
||||
impl ManyImplTrait for ~str {
|
||||
impl ManyImplTrait for StrBuf {
|
||||
fn is_str() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ fn test<'a,T,U:Copy>(_: &'a int) {
|
|||
|
||||
// ~ pointers are not ok
|
||||
assert_copy::<Box<int>>(); //~ ERROR does not fulfill
|
||||
assert_copy::<~str>(); //~ ERROR does not fulfill
|
||||
assert_copy::<StrBuf>(); //~ ERROR does not fulfill
|
||||
assert_copy::<Vec<int> >(); //~ ERROR does not fulfill
|
||||
assert_copy::<Box<&'a mut int>>(); //~ ERROR does not fulfill
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ fn test<'a,T,U:Send>(_: &'a int) {
|
|||
|
||||
// boxes are ok
|
||||
assert_send::<Box<int>>();
|
||||
assert_send::<~str>();
|
||||
assert_send::<StrBuf>();
|
||||
assert_send::<Vec<int> >();
|
||||
|
||||
// but not if they own a bad thing
|
||||
|
|
|
@ -51,7 +51,7 @@ fn good2() {
|
|||
sure that when purity is inherited that the source of the unsafe-ness
|
||||
is tracked correctly */
|
||||
unsafe {
|
||||
unsafe fn what() -> Vec<~str> { fail!() }
|
||||
unsafe fn what() -> Vec<StrBuf> { fail!() }
|
||||
|
||||
callback(|| {
|
||||
what();
|
||||
|
|
|
@ -12,36 +12,36 @@
|
|||
// of the various arms, particularly in the case where regions are
|
||||
// involved.
|
||||
|
||||
pub fn opt_str0<'a>(maybestr: &'a Option<~str>) -> &'a str {
|
||||
pub fn opt_str0<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
|
||||
if maybestr.is_none() {
|
||||
"(none)"
|
||||
} else {
|
||||
let s: &'a str = *maybestr.get_ref();
|
||||
let s: &'a str = maybestr.get_ref().as_slice();
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_str1<'a>(maybestr: &'a Option<~str>) -> &'a str {
|
||||
pub fn opt_str1<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
|
||||
if maybestr.is_some() {
|
||||
let s: &'a str = *maybestr.get_ref();
|
||||
let s: &'a str = maybestr.get_ref().as_slice();
|
||||
s
|
||||
} else {
|
||||
"(none)"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_str2<'a>(maybestr: &'a Option<~str>) -> &'static str {
|
||||
pub fn opt_str2<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
|
||||
if maybestr.is_none() { //~ ERROR mismatched types
|
||||
"(none)"
|
||||
} else {
|
||||
let s: &'a str = *maybestr.get_ref();
|
||||
let s: &'a str = maybestr.get_ref().as_slice();
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str {
|
||||
pub fn opt_str3<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
|
||||
if maybestr.is_some() { //~ ERROR mismatched types
|
||||
let s: &'a str = *maybestr.get_ref();
|
||||
let s: &'a str = maybestr.get_ref().as_slice();
|
||||
s
|
||||
} else {
|
||||
"(none)"
|
||||
|
|
|
@ -12,40 +12,40 @@
|
|||
// of the various arms, particularly in the case where regions are
|
||||
// involved.
|
||||
|
||||
pub fn opt_str0<'a>(maybestr: &'a Option<~str>) -> &'a str {
|
||||
pub fn opt_str0<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
|
||||
match *maybestr {
|
||||
Some(ref s) => {
|
||||
let s: &'a str = *s;
|
||||
let s: &'a str = s.as_slice();
|
||||
s
|
||||
}
|
||||
None => "(none)",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_str1<'a>(maybestr: &'a Option<~str>) -> &'a str {
|
||||
pub fn opt_str1<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
|
||||
match *maybestr {
|
||||
None => "(none)",
|
||||
Some(ref s) => {
|
||||
let s: &'a str = *s;
|
||||
let s: &'a str = s.as_slice();
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_str2<'a>(maybestr: &'a Option<~str>) -> &'static str {
|
||||
pub fn opt_str2<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
|
||||
match *maybestr { //~ ERROR mismatched types
|
||||
None => "(none)",
|
||||
Some(ref s) => {
|
||||
let s: &'a str = *s;
|
||||
let s: &'a str = s.as_slice();
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str {
|
||||
pub fn opt_str3<'a>(maybestr: &'a Option<StrBuf>) -> &'static str {
|
||||
match *maybestr { //~ ERROR mismatched types
|
||||
Some(ref s) => {
|
||||
let s: &'a str = *s;
|
||||
let s: &'a str = s.as_slice();
|
||||
s
|
||||
}
|
||||
None => "(none)",
|
||||
|
|
|
@ -15,9 +15,9 @@ use collections::HashMap;
|
|||
// Test that trait types printed in error msgs include the type arguments.
|
||||
|
||||
fn main() {
|
||||
let x: Box<HashMap<~str, ~str>> = box HashMap::new();
|
||||
let x: Box<Map<~str, ~str>> = x;
|
||||
let y: Box<Map<uint, ~str>> = box x;
|
||||
//~^ ERROR failed to find an implementation of trait core::container::Map<uint,~str>
|
||||
// for ~core::container::Map<~str,~str>:Send
|
||||
let x: Box<HashMap<int, int>> = box HashMap::new();
|
||||
let x: Box<Map<int, int>> = x;
|
||||
let y: Box<Map<uint, int>> = box x;
|
||||
//~^ ERROR failed to find an implementation of trait core::container::Map<uint,int>
|
||||
// for ~core::container::Map<int,int>:Send
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
match "foo".to_owned() {
|
||||
['f', 'o', ..] => { } //~ ERROR mismatched types: expected `~str` but found a vector pattern
|
||||
match "foo".to_strbuf() {
|
||||
['f', 'o', ..] => {} //~ ERROR mismatched types
|
||||
_ => { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,10 @@ fn main() {
|
|||
_ => ()
|
||||
}
|
||||
|
||||
let x: Vec<~str> = vec!("foo".to_owned(), "bar".to_owned(), "baz".to_owned());
|
||||
let x: &[~str] = x.as_slice();
|
||||
let x: Vec<StrBuf> = vec!["foo".to_strbuf(),
|
||||
"bar".to_strbuf(),
|
||||
"baz".to_strbuf()];
|
||||
let x: &[StrBuf] = x.as_slice();
|
||||
match x {
|
||||
[a, _, _, ..] => { println!("{}", a); }
|
||||
[_, _, _, _, _] => { } //~ ERROR unreachable pattern
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:cannot apply unary operator `-` to type `~str`
|
||||
// error-pattern:cannot apply unary operator `-` to type `std::strbuf::StrBuf`
|
||||
|
||||
fn main() { -"foo".to_owned(); }
|
||||
fn main() { -"foo".to_strbuf(); }
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
// Tests that if you move from `x.f` or `x[0]`, `x` is inaccessible.
|
||||
// Also tests that we give a more specific error message.
|
||||
|
||||
struct Foo { f: ~str, y: int }
|
||||
fn consume(_s: ~str) {}
|
||||
struct Foo { f: StrBuf, y: int }
|
||||
fn consume(_s: StrBuf) {}
|
||||
fn touch<A>(_a: &A) {}
|
||||
|
||||
fn f10() {
|
||||
let x = Foo { f: "hi".to_owned(), y: 3 };
|
||||
let x = Foo { f: "hi".to_strbuf(), y: 3 };
|
||||
consume(x.f);
|
||||
touch(&x.y); //~ ERROR use of partially moved value: `x`
|
||||
}
|
||||
|
||||
fn f20() {
|
||||
let x = vec!("hi".to_owned());
|
||||
let x = vec!("hi".to_strbuf());
|
||||
consume(x.move_iter().next().unwrap());
|
||||
touch(x.get(0)); //~ ERROR use of moved value: `x`
|
||||
}
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
#![feature(managed_boxes)]
|
||||
|
||||
struct Foo<A> { f: A }
|
||||
fn guard(_s: ~str) -> bool {fail!()}
|
||||
fn guard(_s: StrBuf) -> bool {fail!()}
|
||||
fn touch<A>(_a: &A) {}
|
||||
|
||||
fn f10() {
|
||||
let x = "hi".to_owned();
|
||||
let x = "hi".to_strbuf();
|
||||
let _y = Foo { f:x };
|
||||
touch(&x); //~ ERROR use of moved value: `x`
|
||||
}
|
||||
|
||||
fn f20() {
|
||||
let x = "hi".to_owned();
|
||||
let x = "hi".to_strbuf();
|
||||
let _y = (x, 3);
|
||||
touch(&x); //~ ERROR use of moved value: `x`
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ fn f21() {
|
|||
}
|
||||
|
||||
fn f30(cond: bool) {
|
||||
let x = "hi".to_owned();
|
||||
let y = "ho".to_owned();
|
||||
let x = "hi".to_strbuf();
|
||||
let y = "ho".to_strbuf();
|
||||
let _y = if cond {
|
||||
x
|
||||
} else {
|
||||
|
@ -48,8 +48,8 @@ fn f30(cond: bool) {
|
|||
}
|
||||
|
||||
fn f40(cond: bool) {
|
||||
let x = "hi".to_owned();
|
||||
let y = "ho".to_owned();
|
||||
let x = "hi".to_strbuf();
|
||||
let y = "ho".to_strbuf();
|
||||
let _y = match cond {
|
||||
true => x,
|
||||
false => y
|
||||
|
@ -59,8 +59,8 @@ fn f40(cond: bool) {
|
|||
}
|
||||
|
||||
fn f50(cond: bool) {
|
||||
let x = "hi".to_owned();
|
||||
let y = "ho".to_owned();
|
||||
let x = "hi".to_strbuf();
|
||||
let y = "ho".to_strbuf();
|
||||
let _y = match cond {
|
||||
_ if guard(x) => 10,
|
||||
true => 10,
|
||||
|
@ -71,31 +71,31 @@ fn f50(cond: bool) {
|
|||
}
|
||||
|
||||
fn f70() {
|
||||
let x = "hi".to_owned();
|
||||
let x = "hi".to_strbuf();
|
||||
let _y = [x];
|
||||
touch(&x); //~ ERROR use of moved value: `x`
|
||||
}
|
||||
|
||||
fn f80() {
|
||||
let x = "hi".to_owned();
|
||||
let x = "hi".to_strbuf();
|
||||
let _y = vec!(x);
|
||||
touch(&x); //~ ERROR use of moved value: `x`
|
||||
}
|
||||
|
||||
fn f100() {
|
||||
let x = vec!("hi".to_owned());
|
||||
let x = vec!("hi".to_strbuf());
|
||||
let _y = x.move_iter().next().unwrap();
|
||||
touch(&x); //~ ERROR use of moved value: `x`
|
||||
}
|
||||
|
||||
fn f110() {
|
||||
let x = vec!("hi".to_owned());
|
||||
let x = vec!("hi".to_strbuf());
|
||||
let _y = [x.move_iter().next().unwrap(), ..1];
|
||||
touch(&x); //~ ERROR use of moved value: `x`
|
||||
}
|
||||
|
||||
fn f120() {
|
||||
let mut x = vec!("hi".to_owned(), "ho".to_owned());
|
||||
let mut x = vec!("hi".to_strbuf(), "ho".to_strbuf());
|
||||
x.as_mut_slice().swap(0, 1);
|
||||
touch(x.get(0));
|
||||
touch(x.get(1));
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// terms of the binding, not the discriminant.
|
||||
|
||||
struct Foo<A> { f: A }
|
||||
fn guard(_s: ~str) -> bool {fail!()}
|
||||
fn guard(_s: StrBuf) -> bool {fail!()}
|
||||
fn touch<A>(_a: &A) {}
|
||||
|
||||
fn f10() {
|
||||
|
|
|
@ -14,5 +14,5 @@ struct S {
|
|||
|
||||
impl Cmp, ToStr for S { //~ ERROR: expected `{` but found `,`
|
||||
fn eq(&&other: S) { false }
|
||||
fn to_str(&self) -> ~str { "hi".to_owned() }
|
||||
fn to_str(&self) -> StrBuf { "hi".to_owned() }
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
struct foo {
|
||||
i: int,
|
||||
j: @~str,
|
||||
j: @StrBuf,
|
||||
}
|
||||
|
||||
fn foo(i:int, j: @~str) -> foo {
|
||||
fn foo(i:int, j: @StrBuf) -> foo {
|
||||
foo {
|
||||
i: i,
|
||||
j: j
|
||||
|
@ -26,7 +26,7 @@ fn foo(i:int, j: @~str) -> foo {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let cat = "kitty".to_owned();
|
||||
let cat = "kitty".to_strbuf();
|
||||
let (tx, _) = channel(); //~ ERROR does not fulfill `Send`
|
||||
tx.send(foo(42, @(cat))); //~ ERROR does not fulfill `Send`
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue