diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index b393b31017d36..32bd66c200431 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -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 { diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index f9c27ae6ae59d..47e9a013e1135 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -530,7 +530,7 @@ mod tests { } struct Noncopy { - string: ~str, + string: StrBuf, array: Vec , } @@ -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 ), }) }) diff --git a/src/libcollections/lru_cache.rs b/src/libcollections/lru_cache.rs index c062fc74c1d0e..72eefe4f44d66 100644 --- a/src/libcollections/lru_cache.rs +++ b/src/libcollections/lru_cache.rs @@ -270,23 +270,23 @@ mod tests { #[test] fn test_put_update() { - let mut cache: LruCache<~str, Vec> = 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> = 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 = 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] diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs index cd6b61049e01d..7b9260c7eb9dc 100644 --- a/src/libglob/lib.rs +++ b/src/libglob/lib.rs @@ -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] diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 06ca5d2637738..a87bb1e6752fd 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -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 { 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, diff --git a/src/libhexfloat/lib.rs b/src/libhexfloat/lib.rs index ac64f04c6fdb0..dda14fb10af02 100644 --- a/src/libhexfloat/lib.rs +++ b/src/libhexfloat/lib.rs @@ -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())) } } diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs index afbcf8c6ded5a..a5bcb7463029b 100644 --- a/src/liblog/directive.rs +++ b/src/liblog/directive.rs @@ -13,7 +13,7 @@ use std::cmp; #[deriving(Show, Clone)] pub struct LogDirective { - pub name: Option<~str>, + pub name: Option, pub level: u32, } @@ -64,7 +64,7 @@ pub fn parse_logging_spec(spec: &str) -> Vec { } }; 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); } } diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index ac69fc37d81b1..9dd87a38fb63a 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -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())); } diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index ac8da664de751..9f66f767f20e7 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -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!() + 32 => "8589934593".to_strbuf(), + 16 => "131073".to_strbuf(), + _ => fail!() }), (16, - "2".to_owned() + - "0".repeat(bits / 4 - 1) + "1") + format_strbuf!("2{}1", "0".repeat(bits / 4 - 1))) )), ( BigUint::from_slice([ 1, 2, 3 ]), vec!( (2, - "11".to_owned() + - "0".repeat(bits - 2) + "10" + - "0".repeat(bits - 1) + "1"), + format_strbuf!("11{}10{}1", + "0".repeat(bits - 2), + "0".repeat(bits - 1))), (4, - "3".to_owned() + - "0".repeat(bits / 2 - 1) + "2" + - "0".repeat(bits / 2 - 1) + "1"), + format_strbuf!("3{}2{}1", + "0".repeat(bits / 2 - 1), + "0".repeat(bits / 2 - 1))), (10, match bits { - 32 => "55340232229718589441".to_owned(), - 16 => "12885032961".to_owned(), + 32 => "55340232229718589441".to_strbuf(), + 16 => "12885032961".to_strbuf(), _ => fail!() }), - (16, "3".to_owned() + - "0".repeat(bits / 4 - 1) + "2" + - "0".repeat(bits / 4 - 1) + "1") + (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()); } } diff --git a/src/libnum/complex.rs b/src/libnum/complex.rs index 3a666273d4a8a..b82c4d177ba02 100644 --- a/src/libnum/complex.rs +++ b/src/libnum/complex.rs @@ -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()); } } diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index 825890e561930..bffca79f351d4 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -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) } - - 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()); - - 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()); + 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_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_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] diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 1f0dd9a407e2b..5b71d5c4da722 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -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. diff --git a/src/libregex/compile.rs b/src/libregex/compile.rs index e5166c6c17cb4..1ba691044463d 100644 --- a/src/libregex/compile.rs +++ b/src/libregex/compile.rs @@ -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>) { + pub fn new(ast: parse::Ast) -> (Program, Vec>) { 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, - names: Vec>, + names: Vec>, } // The compiler implemented here is extremely simple. Most of the complexity diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 3a28f0d1ed5c2..d1a01cc974f8b 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -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), + Capture(uint, Option, Box), // Represent concatenation as a flat vector to avoid blowing the // stack in the compiler. Cat(Vec), @@ -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 { 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, } pub fn parse(s: &str) -> Result { @@ -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 { 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::(s, 8) { + match num::from_str_radix::(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(&self, msg: &str) -> Result { 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() } } diff --git a/src/libregex/re.rs b/src/libregex/re.rs index b40968283bd50..f22889b22a324 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -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>, + pub names: Vec>, #[doc(hidden)] pub p: MaybeNative, } @@ -146,7 +146,10 @@ impl Regex { pub fn new(re: &str) -> Result { 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>, + named: Option>, } 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::(name) { - None => self.name(name).to_owned(), - Some(i) => self.at(i).to_owned(), - } + format_strbuf!("{}{}", + pre, + match from_str::(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("$")) diff --git a/src/libregex/test/bench.rs b/src/libregex/test/bench.rs index 17c66bc670a92..4c4ba8dd6bf93 100644 --- a/src/libregex/test/bench.rs +++ b/src/libregex/test/bench.rs @@ -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) diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index 9d25adacd8108..b85a1592eff02 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -105,8 +105,8 @@ struct NfaGen<'a> { cx: &'a ExtCtxt<'a>, sp: codemap::Span, prog: Program, - names: Vec>, - original: ~str, + names: Vec>, + 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 { 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 `{}`", diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index eaf6527ea829b..0d532d7cec13c 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -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(); diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 3ee38f7a4d65a..e43e7d69a2d00 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -176,10 +176,6 @@ pub fn test(input: &str, libs: HashSet, mut test_args: Vec) -> 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::>() - .as_slice(), - collector.tests); + testing::test_main(test_args.as_slice(), collector.tests); 0 } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index c1da6396d0e29..9e63848b90eab 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -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::>() - .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(); diff --git a/src/libsemver/lib.rs b/src/libsemver/lib.rs index 2707ccd4f0886..3035b30561787 100644 --- a/src/libsemver/lib.rs +++ b/src/libsemver/lib.rs @@ -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>(rdr: &mut T, pred: |char| -> bool) - -> (~str, Option) { + -> (StrBuf, Option) { let mut buf = StrBuf::new(); let mut ch = rdr.next(); loop { @@ -171,12 +171,12 @@ fn take_nonempty_prefix>(rdr: &mut T, pred: |char| -> bool) } } } - (buf.into_owned(), ch) + (buf, ch) } fn take_num>(rdr: &mut T) -> Option<(uint, Option)> { let (s, ch) = take_nonempty_prefix(rdr, char::is_digit); - match from_str::(s) { + match from_str::(s.as_slice()) { None => None, Some(i) => Some((i, ch)) } @@ -184,8 +184,8 @@ fn take_num>(rdr: &mut T) -> Option<(uint, Option)> { fn take_ident>(rdr: &mut T) -> Option<(Identifier, Option)> { let (s,ch) = take_nonempty_prefix(rdr, char::is_alphanumeric); - if s.chars().all(char::is_digit) { - match from_str::(s) { + if s.as_slice().chars().all(char::is_digit) { + match from_str::(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] diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 0a920a275acc4..88081d90b4001 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -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] diff --git a/src/libsync/future.rs b/src/libsync/future.rs index 2836f9cb4be82..b3268674fb1bb 100644 --- a/src/libsync/future.rs +++ b/src/libsync/future.rs @@ -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] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 9918d45e0a55d..2d1b938ec3781 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -126,10 +126,12 @@ impl Terminal { /// 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, ~str> { + pub fn new(out: T) -> Result, 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 Terminal { 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() { diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index ff01a8406edbb..46dd397853157 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -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 , /// Map of capability name to boolean value - pub bools: HashMap<~str, bool>, + pub bools: HashMap, /// Map of capability name to numeric value - pub numbers: HashMap<~str, u16>, + pub numbers: HashMap, /// Map of capability name to raw (unexpanded) string - pub strings: HashMap<~str, Vec > + pub strings: HashMap > } pub mod searcher; diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index 993b69be881ef..ed94de8e81ddd 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -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 , ~str> { + -> Result , 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 ,~str> { +fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,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 ,~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 = s.move_iter().collect(); if flags.precision > s.len() { @@ -543,7 +549,8 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,~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), diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index 2b50a20ac6ae1..5a1c8ea02e221 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -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, ~str> { + -> Result, 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 = 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 { 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 diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index a4be7ed51fbaf..a7365102f96ca 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -76,15 +76,17 @@ pub fn get_dbpath_for_term(term: &str) -> Option> { } /// Return open file for `term` -pub fn open(term: &str) -> Result { +pub fn open(term: &str) -> Result { 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"); } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index ca09d2cce6be6..ba8b8f776d97c 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -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); 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; // 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 ) { +pub fn test_main(args: &[StrBuf], tests: Vec ) { let opts = match parse_opts(args) { Some(Ok(o)) => o, @@ -231,7 +231,7 @@ pub fn test_main(args: &[~str], tests: Vec ) { // 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::>() + .as_slice(), + tests) +} + pub struct TestOpts { - pub filter: Option<~str>, + pub filter: Option, 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; +pub type OptRes = Result; fn optgroups() -> Vec { 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 { +pub fn parse_opts(args: &[StrBuf]) -> Option { let args_ = args.tail(); let matches = - match getopts::getopts(args_, optgroups().as_slice()) { + match getopts::getopts(args_.iter() + .map(|x| x.to_owned()) + .collect::>() + .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 { 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 { Some(Ok(test_opts)) } -pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> { +pub fn opt_shard(maybestr: Option) -> 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 ConsoleTestState { 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 ConsoleTestState { } } -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 = 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)); } } diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index e73a43efe76dd..bf40a2d601fcc 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -1028,17 +1028,20 @@ mod tests { #[test] fn test_boxplot_nonpositive() { #[allow(deprecated_owned_vector)] - fn t(s: &Summary, expected: ~str) { + fn t(s: &Summary, 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] diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index 3cfc611f34c3f..1ffe4d3cbadc4 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -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 { +pub fn strptime(s: &str, format: &str) -> Result { 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 { 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 { } } - fn parse_char(s: &str, pos: uint, c: char) -> Result { + fn parse_char(s: &str, pos: uint, c: char) -> Result { 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 { + -> Result { 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.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 { '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 { '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.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.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.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.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.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.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 { '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.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.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 { 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 { }; 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 { } /// 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"); - - 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!(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()); + let prefix = "Fri, 13 Feb 2009 15:31:30 ".to_strbuf(); + assert!(rfc822 == format_strbuf!("{}PST", prefix) || + rfc822 == format_strbuf!("{}Pacific Standard Time", prefix)); + + assert_eq!(local.ctime(), "Fri Feb 13 15:31:30 2009".to_strbuf()); + assert_eq!(local.rfc822z(), "Fri, 13 Feb 2009 15:31:30 -0800".to_strbuf()); + assert_eq!(local.rfc3339(), "2009-02-13T15:31:30-08:00".to_strbuf()); + + 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() { diff --git a/src/liburl/lib.rs b/src/liburl/lib.rs index b5c1c2d21f47a..a2e75e0bf9b1e 100644 --- a/src/liburl/lib.rs +++ b/src/liburl/lib.rs @@ -39,65 +39,67 @@ use std::uint; /// ```rust /// use url::{Url, UserInfo}; /// -/// let url = Url { scheme: "https".to_owned(), -/// user: Some(UserInfo { user: "username".to_owned(), pass: None }), -/// host: "example.com".to_owned(), -/// port: Some("8080".to_owned()), -/// path: "/foo/bar".to_owned(), -/// query: vec!(("baz".to_owned(), "qux".to_owned())), -/// fragment: Some("quz".to_owned()) }; +/// let url = Url { scheme: "https".to_strbuf(), +/// user: Some(UserInfo { user: "username".to_strbuf(), pass: None }), +/// host: "example.com".to_strbuf(), +/// port: Some("8080".to_strbuf()), +/// path: "/foo/bar".to_strbuf(), +/// query: vec!(("baz".to_strbuf(), "qux".to_strbuf())), +/// fragment: Some("quz".to_strbuf()) }; /// // https://username@example.com:8080/foo/bar?baz=qux#quz /// ``` #[deriving(Clone, Eq, TotalEq)] pub struct Url { /// The scheme part of a URL, such as `https` in the above example. - pub scheme: ~str, + pub scheme: StrBuf, /// A URL subcomponent for user authentication. `username` in the above example. pub user: Option, /// A domain name or IP address. For example, `example.com`. - pub host: ~str, + pub host: StrBuf, /// A TCP port number, for example `8080`. - pub port: Option<~str>, + pub port: Option, /// The path component of a URL, for example `/foo/bar`. - pub path: ~str, - /// The query component of a URL. `vec!(("baz".to_owned(), "qux".to_owned()))` represents the - /// fragment `baz=qux` in the above example. + pub path: StrBuf, + /// The query component of a URL. + /// `vec!(("baz".to_strbuf(), "qux".to_strbuf()))` represents the fragment + /// `baz=qux` in the above example. pub query: Query, /// The fragment component, such as `quz`. Doesn't include the leading `#` character. - pub fragment: Option<~str> + pub fragment: Option } #[deriving(Clone, Eq)] pub struct Path { /// The path component of a URL, for example `/foo/bar`. - pub path: ~str, - /// The query component of a URL. `vec!(("baz".to_owned(), "qux".to_owned()))` represents the - /// fragment `baz=qux` in the above example. + pub path: StrBuf, + /// The query component of a URL. + /// `vec!(("baz".to_strbuf(), "qux".to_strbuf()))` represents the fragment + /// `baz=qux` in the above example. pub query: Query, /// The fragment component, such as `quz`. Doesn't include the leading `#` character. - pub fragment: Option<~str> + pub fragment: Option } /// An optional subcomponent of a URI authority component. #[deriving(Clone, Eq, TotalEq)] pub struct UserInfo { /// The user name. - pub user: ~str, + pub user: StrBuf, /// Password or other scheme-specific authentication information. - pub pass: Option<~str> + pub pass: Option } /// Represents the query component of a URI. -pub type Query = Vec<(~str, ~str)>; +pub type Query = Vec<(StrBuf, StrBuf)>; impl Url { - pub fn new(scheme: ~str, + pub fn new(scheme: StrBuf, user: Option, - host: ~str, - port: Option<~str>, - path: ~str, + host: StrBuf, + port: Option, + path: StrBuf, query: Query, - fragment: Option<~str>) + fragment: Option) -> Url { Url { scheme: scheme, @@ -112,9 +114,9 @@ impl Url { } impl Path { - pub fn new(path: ~str, + pub fn new(path: StrBuf, query: Query, - fragment: Option<~str>) + fragment: Option) -> Path { Path { path: path, @@ -126,12 +128,12 @@ impl Path { impl UserInfo { #[inline] - pub fn new(user: ~str, pass: Option<~str>) -> UserInfo { + pub fn new(user: StrBuf, pass: Option) -> UserInfo { UserInfo { user: user, pass: pass } } } -fn encode_inner(s: &str, full_url: bool) -> ~str { +fn encode_inner(s: &str, full_url: bool) -> StrBuf { let mut rdr = BufReader::new(s.as_bytes()); let mut out = StrBuf::new(); @@ -171,7 +173,7 @@ fn encode_inner(s: &str, full_url: bool) -> ~str { } } - out.into_owned() + out } /** @@ -189,7 +191,7 @@ fn encode_inner(s: &str, full_url: bool) -> ~str { * println!("{}", url); // https://example.com/Rust%20(programming%20language) * ``` */ -pub fn encode(s: &str) -> ~str { +pub fn encode(s: &str) -> StrBuf { encode_inner(s, true) } @@ -200,11 +202,11 @@ pub fn encode(s: &str) -> ~str { * This function is compliant with RFC 3986. */ -pub fn encode_component(s: &str) -> ~str { +pub fn encode_component(s: &str) -> StrBuf { encode_inner(s, false) } -fn decode_inner(s: &str, full_url: bool) -> ~str { +fn decode_inner(s: &str, full_url: bool) -> StrBuf { let mut rdr = BufReader::new(s.as_bytes()); let mut out = StrBuf::new(); @@ -247,7 +249,7 @@ fn decode_inner(s: &str, full_url: bool) -> ~str { } } - out.into_owned() + out } /** @@ -264,18 +266,18 @@ fn decode_inner(s: &str, full_url: bool) -> ~str { * println!("{}", url); // https://example.com/Rust (programming language) * ``` */ -pub fn decode(s: &str) -> ~str { +pub fn decode(s: &str) -> StrBuf { decode_inner(s, true) } /** * Decode a string encoded with percent encoding. */ -pub fn decode_component(s: &str) -> ~str { +pub fn decode_component(s: &str) -> StrBuf { decode_inner(s, false) } -fn encode_plus(s: &str) -> ~str { +fn encode_plus(s: &str) -> StrBuf { let mut rdr = BufReader::new(s.as_bytes()); let mut out = StrBuf::new(); @@ -294,18 +296,18 @@ fn encode_plus(s: &str) -> ~str { } } - out.into_owned() + out } /** * Encode a hashmap to the 'application/x-www-form-urlencoded' media type. */ -pub fn encode_form_urlencoded(m: &HashMap<~str, Vec<~str>>) -> ~str { +pub fn encode_form_urlencoded(m: &HashMap>) -> StrBuf { let mut out = StrBuf::new(); let mut first = true; for (key, values) in m.iter() { - let key = encode_plus(*key); + let key = encode_plus(key.as_slice()); for value in values.iter() { if first { @@ -315,11 +317,13 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, Vec<~str>>) -> ~str { first = false; } - out.push_str(format!("{}={}", key, encode_plus(*value))); + out.push_str(format!("{}={}", + key, + encode_plus(value.as_slice()))); } } - out.into_owned() + out } /** @@ -327,9 +331,9 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, Vec<~str>>) -> ~str { * type into a hashmap. */ #[allow(experimental)] -pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, Vec<~str>> { +pub fn decode_form_urlencoded(s: &[u8]) -> HashMap> { let mut rdr = BufReader::new(s); - let mut m: HashMap<~str,Vec<~str>> = HashMap::new(); + let mut m: HashMap> = HashMap::new(); let mut key = StrBuf::new(); let mut value = StrBuf::new(); let mut parsing_key = true; @@ -348,8 +352,8 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, Vec<~str>> { None => vec!(), }; - values.push(value.into_owned()); - m.insert(key.into_owned(), values); + values.push(value); + m.insert(key, values); } parsing_key = true; @@ -386,15 +390,15 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, Vec<~str>> { None => vec!(), }; - values.push(value.into_owned()); - m.insert(key.into_owned(), values); + values.push(value); + m.insert(key, values); } m } -fn split_char_first(s: &str, c: char) -> (~str, ~str) { +fn split_char_first(s: &str, c: char) -> (StrBuf, StrBuf) { let len = s.len(); let mut index = len; let mut mat = 0; @@ -413,10 +417,10 @@ fn split_char_first(s: &str, c: char) -> (~str, ~str) { } } if index+mat == len { - return (s.slice(0, index).to_owned(), "".to_owned()); + return (s.slice(0, index).to_strbuf(), "".to_strbuf()); } else { - return (s.slice(0, index).to_owned(), - s.slice(index + mat, s.len()).to_owned()); + return (s.slice(0, index).to_strbuf(), + s.slice(index + mat, s.len()).to_strbuf()); } } @@ -434,7 +438,8 @@ fn query_from_str(rawquery: &str) -> Query { if !rawquery.is_empty() { for p in rawquery.split('&') { let (k, v) = split_char_first(p, '='); - query.push((decode_component(k), decode_component(v))); + query.push((decode_component(k.as_slice()), + decode_component(v.as_slice()))); }; } return query; @@ -446,24 +451,24 @@ fn query_from_str(rawquery: &str) -> Query { * # Example * * ```rust - * let query = vec!(("title".to_owned(), "The Village".to_owned()), - ("north".to_owned(), "52.91".to_owned()), - ("west".to_owned(), "4.10".to_owned())); + * let query = vec!(("title".to_strbuf(), "The Village".to_strbuf()), + ("north".to_strbuf(), "52.91".to_strbuf()), + ("west".to_strbuf(), "4.10".to_strbuf())); * println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10 * ``` */ #[allow(unused_must_use)] -pub fn query_to_str(query: &Query) -> ~str { +pub fn query_to_str(query: &Query) -> StrBuf { use std::io::MemWriter; use std::str; let mut writer = MemWriter::new(); for (i, &(ref k, ref v)) in query.iter().enumerate() { if i != 0 { write!(&mut writer, "&"); } - write!(&mut writer, "{}={}", encode_component(*k), - encode_component(*v)); + write!(&mut writer, "{}={}", encode_component(k.as_slice()), + encode_component(v.as_slice())); } - str::from_utf8_lossy(writer.unwrap().as_slice()).into_owned() + str::from_utf8_lossy(writer.unwrap().as_slice()).to_strbuf() } /** @@ -478,35 +483,36 @@ pub fn query_to_str(query: &Query) -> ~str { * * let scheme = match get_scheme("https://example.com/") { * Ok((sch, _)) => sch, - * Err(_) => "(None)".to_owned(), + * Err(_) => "(None)".to_strbuf(), * }; * println!("Scheme in use: {}.", scheme); // Scheme in use: https. * ``` */ -pub fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> { +pub fn get_scheme(rawurl: &str) -> Result<(StrBuf, StrBuf), StrBuf> { for (i,c) in rawurl.chars().enumerate() { match c { 'A' .. 'Z' | 'a' .. 'z' => continue, '0' .. '9' | '+' | '-' | '.' => { if i == 0 { - return Err("url: Scheme must begin with a letter.".to_owned()); + return Err("url: Scheme must begin with a \ + letter.".to_strbuf()); } continue; } ':' => { if i == 0 { - return Err("url: Scheme cannot be empty.".to_owned()); + return Err("url: Scheme cannot be empty.".to_strbuf()); } else { - return Ok((rawurl.slice(0,i).to_owned(), - rawurl.slice(i+1,rawurl.len()).to_owned())); + return Ok((rawurl.slice(0,i).to_strbuf(), + rawurl.slice(i+1,rawurl.len()).to_strbuf())); } } _ => { - return Err("url: Invalid character in scheme.".to_owned()); + return Err("url: Invalid character in scheme.".to_strbuf()); } } }; - return Err("url: Scheme must be terminated with a colon.".to_owned()); + return Err("url: Scheme must be terminated with a colon.".to_strbuf()); } #[deriving(Clone, Eq)] @@ -518,10 +524,10 @@ enum Input { // returns userinfo, host, port, and unparsed part, or an error fn get_authority(rawurl: &str) -> - Result<(Option, ~str, Option<~str>, ~str), ~str> { + Result<(Option, StrBuf, Option, StrBuf), StrBuf> { if !rawurl.starts_with("//") { // there is no authority. - return Ok((None, "".to_owned(), None, rawurl.to_str())); + return Ok((None, "".to_strbuf(), None, rawurl.to_str().to_strbuf())); } enum State { @@ -538,7 +544,7 @@ fn get_authority(rawurl: &str) -> let mut input = Digit; // most restricted, start here. let mut userinfo = None; - let mut host = "".to_owned(); + let mut host = "".to_strbuf(); let mut port = None; let mut colon_count = 0; @@ -565,7 +571,7 @@ fn get_authority(rawurl: &str) -> // separators, don't change anything } _ => { - return Err("Illegal character in authority".to_owned()); + return Err("Illegal character in authority".to_strbuf()); } } @@ -582,7 +588,7 @@ fn get_authority(rawurl: &str) -> // multiple colons means ipv6 address. if input == Unreserved { return Err( - "Illegal characters in IPv6 address.".to_owned()); + "Illegal characters in IPv6 address.".to_strbuf()); } st = Ip6Host; } @@ -590,7 +596,7 @@ fn get_authority(rawurl: &str) -> pos = i; if input == Unreserved { // must be port - host = rawurl.slice(begin, i).to_owned(); + host = rawurl.slice(begin, i).to_strbuf(); st = InPort; } else { // can't be sure whether this is an ipv6 address or a port @@ -599,19 +605,20 @@ fn get_authority(rawurl: &str) -> } Ip6Port => { if input == Unreserved { - return Err("Illegal characters in authority.".to_owned()); + return Err("Illegal characters in \ + authority.".to_strbuf()); } st = Ip6Host; } Ip6Host => { if colon_count > 7 { - host = rawurl.slice(begin, i).to_owned(); + host = rawurl.slice(begin, i).to_strbuf(); pos = i; st = InPort; } } _ => { - return Err("Invalid ':' in authority.".to_owned()); + return Err("Invalid ':' in authority.".to_strbuf()); } } input = Digit; // reset input class @@ -622,18 +629,18 @@ fn get_authority(rawurl: &str) -> colon_count = 0; // reset count match st { Start => { - let user = rawurl.slice(begin, i).to_owned(); + let user = rawurl.slice(begin, i).to_strbuf(); userinfo = Some(UserInfo::new(user, None)); st = InHost; } PassHostPort => { - let user = rawurl.slice(begin, pos).to_owned(); - let pass = rawurl.slice(pos+1, i).to_owned(); + let user = rawurl.slice(begin, pos).to_strbuf(); + let pass = rawurl.slice(pos+1, i).to_strbuf(); userinfo = Some(UserInfo::new(user, Some(pass))); st = InHost; } _ => { - return Err("Invalid '@' in authority.".to_owned()); + return Err("Invalid '@' in authority.".to_strbuf()); } } begin = i+1; @@ -650,34 +657,34 @@ fn get_authority(rawurl: &str) -> // finish up match st { Start => { - host = rawurl.slice(begin, end).to_owned(); + host = rawurl.slice(begin, end).to_strbuf(); } PassHostPort | Ip6Port => { if input != Digit { - return Err("Non-digit characters in port.".to_owned()); + return Err("Non-digit characters in port.".to_strbuf()); } - host = rawurl.slice(begin, pos).to_owned(); - port = Some(rawurl.slice(pos+1, end).to_owned()); + host = rawurl.slice(begin, pos).to_strbuf(); + port = Some(rawurl.slice(pos+1, end).to_strbuf()); } Ip6Host | InHost => { - host = rawurl.slice(begin, end).to_owned(); + host = rawurl.slice(begin, end).to_strbuf(); } InPort => { if input != Digit { - return Err("Non-digit characters in port.".to_owned()); + return Err("Non-digit characters in port.".to_strbuf()); } - port = Some(rawurl.slice(pos+1, end).to_owned()); + port = Some(rawurl.slice(pos+1, end).to_strbuf()); } } - let rest = rawurl.slice(end, len).to_owned(); + let rest = rawurl.slice(end, len).to_strbuf(); return Ok((userinfo, host, port, rest)); } // returns the path and unparsed part of url, or an error fn get_path(rawurl: &str, authority: bool) -> - Result<(~str, ~str), ~str> { + Result<(StrBuf, StrBuf), StrBuf> { let len = rawurl.len(); let mut end = len; for (i,c) in rawurl.chars().enumerate() { @@ -691,24 +698,24 @@ fn get_path(rawurl: &str, authority: bool) -> end = i; break; } - _ => return Err("Invalid character in path.".to_owned()) + _ => return Err("Invalid character in path.".to_strbuf()) } } if authority { if end != 0 && !rawurl.starts_with("/") { return Err("Non-empty path must begin with\ - '/' in presence of authority.".to_owned()); + '/' in presence of authority.".to_strbuf()); } } return Ok((decode_component(rawurl.slice(0, end)), - rawurl.slice(end, len).to_owned())); + rawurl.slice(end, len).to_strbuf())); } // returns the parsed query and the fragment, if present fn get_query_fragment(rawurl: &str) -> - Result<(Query, Option<~str>), ~str> { + Result<(Query, Option), StrBuf> { if !rawurl.starts_with("?") { if rawurl.starts_with("#") { let f = decode_component(rawurl.slice( @@ -721,8 +728,11 @@ fn get_query_fragment(rawurl: &str) -> } let (q, r) = split_char_first(rawurl.slice(1, rawurl.len()), '#'); let f = if r.len() != 0 { - Some(decode_component(r)) } else { None }; - return Ok((query_from_str(q), f)); + Some(decode_component(r.as_slice())) + } else { + None + }; + return Ok((query_from_str(q.as_slice()), f)); } /** @@ -736,7 +746,7 @@ fn get_query_fragment(rawurl: &str) -> * * A `Url` struct type representing the URL. */ -pub fn from_str(rawurl: &str) -> Result { +pub fn from_str(rawurl: &str) -> Result { // scheme let (scheme, rest) = match get_scheme(rawurl) { Ok(val) => val, @@ -744,20 +754,20 @@ pub fn from_str(rawurl: &str) -> Result { }; // authority - let (userinfo, host, port, rest) = match get_authority(rest) { + let (userinfo, host, port, rest) = match get_authority(rest.as_slice()) { Ok(val) => val, Err(e) => return Err(e), }; // path - let has_authority = if host == "".to_owned() { false } else { true }; - let (path, rest) = match get_path(rest, has_authority) { + let has_authority = host.len() > 0; + let (path, rest) = match get_path(rest.as_slice(), has_authority) { Ok(val) => val, Err(e) => return Err(e), }; // query and fragment - let (query, fragment) = match get_query_fragment(rest) { + let (query, fragment) = match get_query_fragment(rest.as_slice()) { Ok(val) => val, Err(e) => return Err(e), }; @@ -765,14 +775,14 @@ pub fn from_str(rawurl: &str) -> Result { Ok(Url::new(scheme, userinfo, host, port, path, query, fragment)) } -pub fn path_from_str(rawpath: &str) -> Result { +pub fn path_from_str(rawpath: &str) -> Result { let (path, rest) = match get_path(rawpath, false) { Ok(val) => val, Err(e) => return Err(e) }; // query and fragment - let (query, fragment) = match get_query_fragment(rest) { + let (query, fragment) = match get_query_fragment(rest.as_slice()) { Ok(val) => val, Err(e) => return Err(e), }; @@ -836,8 +846,9 @@ impl fmt::Show for Url { } match self.fragment { - Some(ref fragment) => write!(f.buf, "\\#{}", - encode_component(*fragment)), + Some(ref fragment) => { + write!(f.buf, "\\#{}", encode_component(fragment.as_slice())) + } None => Ok(()), } } @@ -852,7 +863,7 @@ impl fmt::Show for Path { match self.fragment { Some(ref fragment) => { - write!(f.buf, "\\#{}", encode_component(*fragment)) + write!(f.buf, "\\#{}", encode_component(fragment.as_slice())) } None => Ok(()) } @@ -877,53 +888,53 @@ impl Hash for Path { #[test] fn test_split_char_first() { let (u,v) = split_char_first("hello, sweet world", ','); - assert_eq!(u, "hello".to_owned()); - assert_eq!(v, " sweet world".to_owned()); + assert_eq!(u, "hello".to_strbuf()); + assert_eq!(v, " sweet world".to_strbuf()); let (u,v) = split_char_first("hello sweet world", ','); - assert_eq!(u, "hello sweet world".to_owned()); - assert_eq!(v, "".to_owned()); + assert_eq!(u, "hello sweet world".to_strbuf()); + assert_eq!(v, "".to_strbuf()); } #[test] fn test_get_authority() { let (u, h, p, r) = get_authority( "//user:pass@rust-lang.org/something").unwrap(); - assert_eq!(u, Some(UserInfo::new("user".to_owned(), Some("pass".to_owned())))); - assert_eq!(h, "rust-lang.org".to_owned()); + assert_eq!(u, Some(UserInfo::new("user".to_strbuf(), Some("pass".to_strbuf())))); + assert_eq!(h, "rust-lang.org".to_strbuf()); assert!(p.is_none()); - assert_eq!(r, "/something".to_owned()); + assert_eq!(r, "/something".to_strbuf()); let (u, h, p, r) = get_authority( "//rust-lang.org:8000?something").unwrap(); assert!(u.is_none()); - assert_eq!(h, "rust-lang.org".to_owned()); - assert_eq!(p, Some("8000".to_owned())); - assert_eq!(r, "?something".to_owned()); + assert_eq!(h, "rust-lang.org".to_strbuf()); + assert_eq!(p, Some("8000".to_strbuf())); + assert_eq!(r, "?something".to_strbuf()); let (u, h, p, r) = get_authority( "//rust-lang.org#blah").unwrap(); assert!(u.is_none()); - assert_eq!(h, "rust-lang.org".to_owned()); + assert_eq!(h, "rust-lang.org".to_strbuf()); assert!(p.is_none()); - assert_eq!(r, "#blah".to_owned()); + assert_eq!(r, "#blah".to_strbuf()); // ipv6 tests let (_, h, _, _) = get_authority( "//2001:0db8:85a3:0042:0000:8a2e:0370:7334#blah").unwrap(); - assert_eq!(h, "2001:0db8:85a3:0042:0000:8a2e:0370:7334".to_owned()); + assert_eq!(h, "2001:0db8:85a3:0042:0000:8a2e:0370:7334".to_strbuf()); let (_, h, p, _) = get_authority( "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah").unwrap(); - assert_eq!(h, "2001:0db8:85a3:0042:0000:8a2e:0370:7334".to_owned()); - assert_eq!(p, Some("8000".to_owned())); + assert_eq!(h, "2001:0db8:85a3:0042:0000:8a2e:0370:7334".to_strbuf()); + assert_eq!(p, Some("8000".to_strbuf())); let (u, h, p, _) = get_authority( "//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah" ).unwrap(); - assert_eq!(u, Some(UserInfo::new("us".to_owned(), Some("p".to_owned())))); - assert_eq!(h, "2001:0db8:85a3:0042:0000:8a2e:0370:7334".to_owned()); - assert_eq!(p, Some("8000".to_owned())); + assert_eq!(u, Some(UserInfo::new("us".to_strbuf(), Some("p".to_strbuf())))); + assert_eq!(h, "2001:0db8:85a3:0042:0000:8a2e:0370:7334".to_strbuf()); + assert_eq!(p, Some("8000".to_strbuf())); // invalid authorities; assert!(get_authority("//user:pass@rust-lang:something").is_err()); @@ -935,22 +946,22 @@ fn test_get_authority() { // these parse as empty, because they don't start with '//' let (_, h, _, _) = get_authority("user:pass@rust-lang").unwrap(); - assert_eq!(h, "".to_owned()); + assert_eq!(h, "".to_strbuf()); let (_, h, _, _) = get_authority("rust-lang.org").unwrap(); - assert_eq!(h, "".to_owned()); + assert_eq!(h, "".to_strbuf()); } #[test] fn test_get_path() { let (p, r) = get_path("/something+%20orother", true).unwrap(); - assert_eq!(p, "/something+ orother".to_owned()); - assert_eq!(r, "".to_owned()); + assert_eq!(p, "/something+ orother".to_strbuf()); + assert_eq!(r, "".to_strbuf()); let (p, r) = get_path("test@email.com#fragment", false).unwrap(); - assert_eq!(p, "test@email.com".to_owned()); - assert_eq!(r, "#fragment".to_owned()); + assert_eq!(p, "test@email.com".to_strbuf()); + assert_eq!(r, "#fragment".to_strbuf()); let (p, r) = get_path("/gen/:addr=?q=v", false).unwrap(); - assert_eq!(p, "/gen/:addr=".to_owned()); - assert_eq!(r, "?q=v".to_owned()); + assert_eq!(p, "/gen/:addr=".to_strbuf()); + assert_eq!(r, "?q=v".to_strbuf()); //failure cases assert!(get_path("something?q", true).is_err()); @@ -966,87 +977,88 @@ mod tests { #[test] fn test_url_parse() { - let url = "http://user:pass@rust-lang.org:8080/doc/~u?s=v#something".to_owned(); + let url = "http://user:pass@rust-lang.org:8080/doc/~u?s=v#something"; let up = from_str(url); let u = up.unwrap(); - assert_eq!(&u.scheme, &"http".to_owned()); - assert_eq!(&u.user, &Some(UserInfo::new("user".to_owned(), Some("pass".to_owned())))); - assert_eq!(&u.host, &"rust-lang.org".to_owned()); - assert_eq!(&u.port, &Some("8080".to_owned())); - assert_eq!(&u.path, &"/doc/~u".to_owned()); - assert_eq!(&u.query, &vec!(("s".to_owned(), "v".to_owned()))); - assert_eq!(&u.fragment, &Some("something".to_owned())); + assert_eq!(&u.scheme, &"http".to_strbuf()); + assert_eq!(&u.user, &Some(UserInfo::new("user".to_strbuf(), Some("pass".to_strbuf())))); + assert_eq!(&u.host, &"rust-lang.org".to_strbuf()); + assert_eq!(&u.port, &Some("8080".to_strbuf())); + assert_eq!(&u.path, &"/doc/~u".to_strbuf()); + assert_eq!(&u.query, &vec!(("s".to_strbuf(), "v".to_strbuf()))); + assert_eq!(&u.fragment, &Some("something".to_strbuf())); } #[test] fn test_path_parse() { - let path = "/doc/~u?s=v#something".to_owned(); + let path = "/doc/~u?s=v#something"; let up = path_from_str(path); let u = up.unwrap(); - assert_eq!(&u.path, &"/doc/~u".to_owned()); - assert_eq!(&u.query, &vec!(("s".to_owned(), "v".to_owned()))); - assert_eq!(&u.fragment, &Some("something".to_owned())); + assert_eq!(&u.path, &"/doc/~u".to_strbuf()); + assert_eq!(&u.query, &vec!(("s".to_strbuf(), "v".to_strbuf()))); + assert_eq!(&u.fragment, &Some("something".to_strbuf())); } #[test] fn test_url_parse_host_slash() { - let urlstr = "http://0.42.42.42/".to_owned(); + let urlstr = "http://0.42.42.42/"; let url = from_str(urlstr).unwrap(); - assert!(url.host == "0.42.42.42".to_owned()); - assert!(url.path == "/".to_owned()); + assert!(url.host == "0.42.42.42".to_strbuf()); + assert!(url.path == "/".to_strbuf()); } #[test] fn test_path_parse_host_slash() { - let pathstr = "/".to_owned(); + let pathstr = "/"; let path = path_from_str(pathstr).unwrap(); - assert!(path.path == "/".to_owned()); + assert!(path.path == "/".to_strbuf()); } #[test] fn test_url_host_with_port() { - let urlstr = "scheme://host:1234".to_owned(); + let urlstr = "scheme://host:1234"; let url = from_str(urlstr).unwrap(); - assert_eq!(&url.scheme, &"scheme".to_owned()); - assert_eq!(&url.host, &"host".to_owned()); - assert_eq!(&url.port, &Some("1234".to_owned())); - assert_eq!(&url.path, &"".to_owned()); // is empty path really correct? Other tests think so - let urlstr = "scheme://host:1234/".to_owned(); + assert_eq!(&url.scheme, &"scheme".to_strbuf()); + assert_eq!(&url.host, &"host".to_strbuf()); + assert_eq!(&url.port, &Some("1234".to_strbuf())); + // is empty path really correct? Other tests think so + assert_eq!(&url.path, &"".to_strbuf()); + let urlstr = "scheme://host:1234/"; let url = from_str(urlstr).unwrap(); - assert_eq!(&url.scheme, &"scheme".to_owned()); - assert_eq!(&url.host, &"host".to_owned()); - assert_eq!(&url.port, &Some("1234".to_owned())); - assert_eq!(&url.path, &"/".to_owned()); + assert_eq!(&url.scheme, &"scheme".to_strbuf()); + assert_eq!(&url.host, &"host".to_strbuf()); + assert_eq!(&url.port, &Some("1234".to_strbuf())); + assert_eq!(&url.path, &"/".to_strbuf()); } #[test] fn test_url_with_underscores() { - let urlstr = "http://dotcom.com/file_name.html".to_owned(); + let urlstr = "http://dotcom.com/file_name.html"; let url = from_str(urlstr).unwrap(); - assert!(url.path == "/file_name.html".to_owned()); + assert!(url.path == "/file_name.html".to_strbuf()); } #[test] fn test_path_with_underscores() { - let pathstr = "/file_name.html".to_owned(); + let pathstr = "/file_name.html"; let path = path_from_str(pathstr).unwrap(); - assert!(path.path == "/file_name.html".to_owned()); + assert!(path.path == "/file_name.html".to_strbuf()); } #[test] fn test_url_with_dashes() { - let urlstr = "http://dotcom.com/file-name.html".to_owned(); + let urlstr = "http://dotcom.com/file-name.html"; let url = from_str(urlstr).unwrap(); - assert!(url.path == "/file-name.html".to_owned()); + assert!(url.path == "/file-name.html".to_strbuf()); } #[test] fn test_path_with_dashes() { - let pathstr = "/file-name.html".to_owned(); + let pathstr = "/file-name.html"; let path = path_from_str(pathstr).unwrap(); - assert!(path.path == "/file-name.html".to_owned()); + assert!(path.path == "/file-name.html".to_strbuf()); } #[test] @@ -1062,217 +1074,217 @@ mod tests { #[test] fn test_full_url_parse_and_format() { - let url = "http://user:pass@rust-lang.org/doc?s=v#something".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://user:pass@rust-lang.org/doc?s=v#something"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_userless_url_parse_and_format() { - let url = "http://rust-lang.org/doc?s=v#something".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://rust-lang.org/doc?s=v#something"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_queryless_url_parse_and_format() { - let url = "http://user:pass@rust-lang.org/doc#something".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://user:pass@rust-lang.org/doc#something"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_empty_query_url_parse_and_format() { - let url = "http://user:pass@rust-lang.org/doc?#something".to_owned(); - let should_be = "http://user:pass@rust-lang.org/doc#something".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), should_be); + let url = "http://user:pass@rust-lang.org/doc?#something"; + let should_be = "http://user:pass@rust-lang.org/doc#something"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), should_be); } #[test] fn test_fragmentless_url_parse_and_format() { - let url = "http://user:pass@rust-lang.org/doc?q=v".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://user:pass@rust-lang.org/doc?q=v"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_minimal_url_parse_and_format() { - let url = "http://rust-lang.org/doc".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://rust-lang.org/doc"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_url_with_port_parse_and_format() { - let url = "http://rust-lang.org:80/doc".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://rust-lang.org:80/doc"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_scheme_host_only_url_parse_and_format() { - let url = "http://rust-lang.org".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://rust-lang.org"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_pathless_url_parse_and_format() { - let url = "http://user:pass@rust-lang.org?q=v#something".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://user:pass@rust-lang.org?q=v#something"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_scheme_host_fragment_only_url_parse_and_format() { - let url = "http://rust-lang.org#something".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "http://rust-lang.org#something"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_url_component_encoding() { - let url = "http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B".to_owned(); + let url = "http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B"; let u = from_str(url).unwrap(); - assert!(u.path == "/doc uments".to_owned()); - assert!(u.query == vec!(("ba%d ".to_owned(), "#&+".to_owned()))); + assert!(u.path == "/doc uments".to_strbuf()); + assert!(u.query == vec!(("ba%d ".to_strbuf(), "#&+".to_strbuf()))); } #[test] fn test_path_component_encoding() { - let path = "/doc%20uments?ba%25d%20=%23%26%2B".to_owned(); + let path = "/doc%20uments?ba%25d%20=%23%26%2B"; let p = path_from_str(path).unwrap(); - assert!(p.path == "/doc uments".to_owned()); - assert!(p.query == vec!(("ba%d ".to_owned(), "#&+".to_owned()))); + assert!(p.path == "/doc uments".to_strbuf()); + assert!(p.query == vec!(("ba%d ".to_strbuf(), "#&+".to_strbuf()))); } #[test] fn test_url_without_authority() { - let url = "mailto:test@email.com".to_owned(); - assert_eq!(from_str(url).unwrap().to_str(), url); + let url = "mailto:test@email.com"; + assert_eq!(from_str(url).unwrap().to_str().as_slice(), url); } #[test] fn test_encode() { - assert_eq!(encode(""), "".to_owned()); - assert_eq!(encode("http://example.com"), "http://example.com".to_owned()); - assert_eq!(encode("foo bar% baz"), "foo%20bar%25%20baz".to_owned()); - assert_eq!(encode(" "), "%20".to_owned()); - assert_eq!(encode("!"), "!".to_owned()); - assert_eq!(encode("\""), "\"".to_owned()); - assert_eq!(encode("#"), "#".to_owned()); - assert_eq!(encode("$"), "$".to_owned()); - assert_eq!(encode("%"), "%25".to_owned()); - assert_eq!(encode("&"), "&".to_owned()); - assert_eq!(encode("'"), "%27".to_owned()); - assert_eq!(encode("("), "(".to_owned()); - assert_eq!(encode(")"), ")".to_owned()); - assert_eq!(encode("*"), "*".to_owned()); - assert_eq!(encode("+"), "+".to_owned()); - assert_eq!(encode(","), ",".to_owned()); - assert_eq!(encode("/"), "/".to_owned()); - assert_eq!(encode(":"), ":".to_owned()); - assert_eq!(encode(";"), ";".to_owned()); - assert_eq!(encode("="), "=".to_owned()); - assert_eq!(encode("?"), "?".to_owned()); - assert_eq!(encode("@"), "@".to_owned()); - assert_eq!(encode("["), "[".to_owned()); - assert_eq!(encode("]"), "]".to_owned()); + assert_eq!(encode(""), "".to_strbuf()); + assert_eq!(encode("http://example.com"), "http://example.com".to_strbuf()); + assert_eq!(encode("foo bar% baz"), "foo%20bar%25%20baz".to_strbuf()); + assert_eq!(encode(" "), "%20".to_strbuf()); + assert_eq!(encode("!"), "!".to_strbuf()); + assert_eq!(encode("\""), "\"".to_strbuf()); + assert_eq!(encode("#"), "#".to_strbuf()); + assert_eq!(encode("$"), "$".to_strbuf()); + assert_eq!(encode("%"), "%25".to_strbuf()); + assert_eq!(encode("&"), "&".to_strbuf()); + assert_eq!(encode("'"), "%27".to_strbuf()); + assert_eq!(encode("("), "(".to_strbuf()); + assert_eq!(encode(")"), ")".to_strbuf()); + assert_eq!(encode("*"), "*".to_strbuf()); + assert_eq!(encode("+"), "+".to_strbuf()); + assert_eq!(encode(","), ",".to_strbuf()); + assert_eq!(encode("/"), "/".to_strbuf()); + assert_eq!(encode(":"), ":".to_strbuf()); + assert_eq!(encode(";"), ";".to_strbuf()); + assert_eq!(encode("="), "=".to_strbuf()); + assert_eq!(encode("?"), "?".to_strbuf()); + assert_eq!(encode("@"), "@".to_strbuf()); + assert_eq!(encode("["), "[".to_strbuf()); + assert_eq!(encode("]"), "]".to_strbuf()); } #[test] fn test_encode_component() { - assert_eq!(encode_component(""), "".to_owned()); + assert_eq!(encode_component(""), "".to_strbuf()); assert!(encode_component("http://example.com") == - "http%3A%2F%2Fexample.com".to_owned()); + "http%3A%2F%2Fexample.com".to_strbuf()); assert!(encode_component("foo bar% baz") == - "foo%20bar%25%20baz".to_owned()); - assert_eq!(encode_component(" "), "%20".to_owned()); - assert_eq!(encode_component("!"), "%21".to_owned()); - assert_eq!(encode_component("#"), "%23".to_owned()); - assert_eq!(encode_component("$"), "%24".to_owned()); - assert_eq!(encode_component("%"), "%25".to_owned()); - assert_eq!(encode_component("&"), "%26".to_owned()); - assert_eq!(encode_component("'"), "%27".to_owned()); - assert_eq!(encode_component("("), "%28".to_owned()); - assert_eq!(encode_component(")"), "%29".to_owned()); - assert_eq!(encode_component("*"), "%2A".to_owned()); - assert_eq!(encode_component("+"), "%2B".to_owned()); - assert_eq!(encode_component(","), "%2C".to_owned()); - assert_eq!(encode_component("/"), "%2F".to_owned()); - assert_eq!(encode_component(":"), "%3A".to_owned()); - assert_eq!(encode_component(";"), "%3B".to_owned()); - assert_eq!(encode_component("="), "%3D".to_owned()); - assert_eq!(encode_component("?"), "%3F".to_owned()); - assert_eq!(encode_component("@"), "%40".to_owned()); - assert_eq!(encode_component("["), "%5B".to_owned()); - assert_eq!(encode_component("]"), "%5D".to_owned()); + "foo%20bar%25%20baz".to_strbuf()); + assert_eq!(encode_component(" "), "%20".to_strbuf()); + assert_eq!(encode_component("!"), "%21".to_strbuf()); + assert_eq!(encode_component("#"), "%23".to_strbuf()); + assert_eq!(encode_component("$"), "%24".to_strbuf()); + assert_eq!(encode_component("%"), "%25".to_strbuf()); + assert_eq!(encode_component("&"), "%26".to_strbuf()); + assert_eq!(encode_component("'"), "%27".to_strbuf()); + assert_eq!(encode_component("("), "%28".to_strbuf()); + assert_eq!(encode_component(")"), "%29".to_strbuf()); + assert_eq!(encode_component("*"), "%2A".to_strbuf()); + assert_eq!(encode_component("+"), "%2B".to_strbuf()); + assert_eq!(encode_component(","), "%2C".to_strbuf()); + assert_eq!(encode_component("/"), "%2F".to_strbuf()); + assert_eq!(encode_component(":"), "%3A".to_strbuf()); + assert_eq!(encode_component(";"), "%3B".to_strbuf()); + assert_eq!(encode_component("="), "%3D".to_strbuf()); + assert_eq!(encode_component("?"), "%3F".to_strbuf()); + assert_eq!(encode_component("@"), "%40".to_strbuf()); + assert_eq!(encode_component("["), "%5B".to_strbuf()); + assert_eq!(encode_component("]"), "%5D".to_strbuf()); } #[test] fn test_decode() { - assert_eq!(decode(""), "".to_owned()); - assert_eq!(decode("abc/def 123"), "abc/def 123".to_owned()); - assert_eq!(decode("abc%2Fdef%20123"), "abc%2Fdef 123".to_owned()); - assert_eq!(decode("%20"), " ".to_owned()); - assert_eq!(decode("%21"), "%21".to_owned()); - assert_eq!(decode("%22"), "%22".to_owned()); - assert_eq!(decode("%23"), "%23".to_owned()); - assert_eq!(decode("%24"), "%24".to_owned()); - assert_eq!(decode("%25"), "%".to_owned()); - assert_eq!(decode("%26"), "%26".to_owned()); - assert_eq!(decode("%27"), "'".to_owned()); - assert_eq!(decode("%28"), "%28".to_owned()); - assert_eq!(decode("%29"), "%29".to_owned()); - assert_eq!(decode("%2A"), "%2A".to_owned()); - assert_eq!(decode("%2B"), "%2B".to_owned()); - assert_eq!(decode("%2C"), "%2C".to_owned()); - assert_eq!(decode("%2F"), "%2F".to_owned()); - assert_eq!(decode("%3A"), "%3A".to_owned()); - assert_eq!(decode("%3B"), "%3B".to_owned()); - assert_eq!(decode("%3D"), "%3D".to_owned()); - assert_eq!(decode("%3F"), "%3F".to_owned()); - assert_eq!(decode("%40"), "%40".to_owned()); - assert_eq!(decode("%5B"), "%5B".to_owned()); - assert_eq!(decode("%5D"), "%5D".to_owned()); + assert_eq!(decode(""), "".to_strbuf()); + assert_eq!(decode("abc/def 123"), "abc/def 123".to_strbuf()); + assert_eq!(decode("abc%2Fdef%20123"), "abc%2Fdef 123".to_strbuf()); + assert_eq!(decode("%20"), " ".to_strbuf()); + assert_eq!(decode("%21"), "%21".to_strbuf()); + assert_eq!(decode("%22"), "%22".to_strbuf()); + assert_eq!(decode("%23"), "%23".to_strbuf()); + assert_eq!(decode("%24"), "%24".to_strbuf()); + assert_eq!(decode("%25"), "%".to_strbuf()); + assert_eq!(decode("%26"), "%26".to_strbuf()); + assert_eq!(decode("%27"), "'".to_strbuf()); + assert_eq!(decode("%28"), "%28".to_strbuf()); + assert_eq!(decode("%29"), "%29".to_strbuf()); + assert_eq!(decode("%2A"), "%2A".to_strbuf()); + assert_eq!(decode("%2B"), "%2B".to_strbuf()); + assert_eq!(decode("%2C"), "%2C".to_strbuf()); + assert_eq!(decode("%2F"), "%2F".to_strbuf()); + assert_eq!(decode("%3A"), "%3A".to_strbuf()); + assert_eq!(decode("%3B"), "%3B".to_strbuf()); + assert_eq!(decode("%3D"), "%3D".to_strbuf()); + assert_eq!(decode("%3F"), "%3F".to_strbuf()); + assert_eq!(decode("%40"), "%40".to_strbuf()); + assert_eq!(decode("%5B"), "%5B".to_strbuf()); + assert_eq!(decode("%5D"), "%5D".to_strbuf()); } #[test] fn test_decode_component() { - assert_eq!(decode_component(""), "".to_owned()); - assert_eq!(decode_component("abc/def 123"), "abc/def 123".to_owned()); - assert_eq!(decode_component("abc%2Fdef%20123"), "abc/def 123".to_owned()); - assert_eq!(decode_component("%20"), " ".to_owned()); - assert_eq!(decode_component("%21"), "!".to_owned()); - assert_eq!(decode_component("%22"), "\"".to_owned()); - assert_eq!(decode_component("%23"), "#".to_owned()); - assert_eq!(decode_component("%24"), "$".to_owned()); - assert_eq!(decode_component("%25"), "%".to_owned()); - assert_eq!(decode_component("%26"), "&".to_owned()); - assert_eq!(decode_component("%27"), "'".to_owned()); - assert_eq!(decode_component("%28"), "(".to_owned()); - assert_eq!(decode_component("%29"), ")".to_owned()); - assert_eq!(decode_component("%2A"), "*".to_owned()); - assert_eq!(decode_component("%2B"), "+".to_owned()); - assert_eq!(decode_component("%2C"), ",".to_owned()); - assert_eq!(decode_component("%2F"), "/".to_owned()); - assert_eq!(decode_component("%3A"), ":".to_owned()); - assert_eq!(decode_component("%3B"), ";".to_owned()); - assert_eq!(decode_component("%3D"), "=".to_owned()); - assert_eq!(decode_component("%3F"), "?".to_owned()); - assert_eq!(decode_component("%40"), "@".to_owned()); - assert_eq!(decode_component("%5B"), "[".to_owned()); - assert_eq!(decode_component("%5D"), "]".to_owned()); + assert_eq!(decode_component(""), "".to_strbuf()); + assert_eq!(decode_component("abc/def 123"), "abc/def 123".to_strbuf()); + assert_eq!(decode_component("abc%2Fdef%20123"), "abc/def 123".to_strbuf()); + assert_eq!(decode_component("%20"), " ".to_strbuf()); + assert_eq!(decode_component("%21"), "!".to_strbuf()); + assert_eq!(decode_component("%22"), "\"".to_strbuf()); + assert_eq!(decode_component("%23"), "#".to_strbuf()); + assert_eq!(decode_component("%24"), "$".to_strbuf()); + assert_eq!(decode_component("%25"), "%".to_strbuf()); + assert_eq!(decode_component("%26"), "&".to_strbuf()); + assert_eq!(decode_component("%27"), "'".to_strbuf()); + assert_eq!(decode_component("%28"), "(".to_strbuf()); + assert_eq!(decode_component("%29"), ")".to_strbuf()); + assert_eq!(decode_component("%2A"), "*".to_strbuf()); + assert_eq!(decode_component("%2B"), "+".to_strbuf()); + assert_eq!(decode_component("%2C"), ",".to_strbuf()); + assert_eq!(decode_component("%2F"), "/".to_strbuf()); + assert_eq!(decode_component("%3A"), ":".to_strbuf()); + assert_eq!(decode_component("%3B"), ";".to_strbuf()); + assert_eq!(decode_component("%3D"), "=".to_strbuf()); + assert_eq!(decode_component("%3F"), "?".to_strbuf()); + assert_eq!(decode_component("%40"), "@".to_strbuf()); + assert_eq!(decode_component("%5B"), "[".to_strbuf()); + assert_eq!(decode_component("%5D"), "]".to_strbuf()); } #[test] fn test_encode_form_urlencoded() { let mut m = HashMap::new(); - assert_eq!(encode_form_urlencoded(&m), "".to_owned()); + assert_eq!(encode_form_urlencoded(&m), "".to_strbuf()); - m.insert("".to_owned(), vec!()); - m.insert("foo".to_owned(), vec!()); - assert_eq!(encode_form_urlencoded(&m), "".to_owned()); + m.insert("".to_strbuf(), vec!()); + m.insert("foo".to_strbuf(), vec!()); + assert_eq!(encode_form_urlencoded(&m), "".to_strbuf()); let mut m = HashMap::new(); - m.insert("foo".to_owned(), vec!("bar".to_owned(), "123".to_owned())); - assert_eq!(encode_form_urlencoded(&m), "foo=bar&foo=123".to_owned()); + m.insert("foo".to_strbuf(), vec!("bar".to_strbuf(), "123".to_strbuf())); + assert_eq!(encode_form_urlencoded(&m), "foo=bar&foo=123".to_strbuf()); let mut m = HashMap::new(); - m.insert("foo bar".to_owned(), vec!("abc".to_owned(), "12 = 34".to_owned())); + m.insert("foo bar".to_strbuf(), vec!("abc".to_strbuf(), "12 = 34".to_strbuf())); assert!(encode_form_urlencoded(&m) == - "foo+bar=abc&foo+bar=12+%3D+34".to_owned()); + "foo+bar=abc&foo+bar=12+%3D+34".to_strbuf()); } #[test] @@ -1282,7 +1294,8 @@ mod tests { let s = "a=1&foo+bar=abc&foo+bar=12+%3D+34".as_bytes(); let form = decode_form_urlencoded(s); assert_eq!(form.len(), 2); - assert_eq!(form.get(&"a".to_owned()), &vec!("1".to_owned())); - assert_eq!(form.get(&"foo bar".to_owned()), &vec!("abc".to_owned(), "12 = 34".to_owned())); + assert_eq!(form.get(&"a".to_strbuf()), &vec!("1".to_strbuf())); + assert_eq!(form.get(&"foo bar".to_strbuf()), + &vec!("abc".to_strbuf(), "12 = 34".to_strbuf())); } } diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index f1abc9ffaacca..d75f967a229b1 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -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 = 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, E> Encodable 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::>() .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); } diff --git a/src/libworkcache/lib.rs b/src/libworkcache/lib.rs index 1dd87f3954e4f..c2dd8459540d8 100644 --- a/src/libworkcache/lib.rs +++ b/src/libworkcache/lib.rs @@ -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); #[deriving(Clone, Eq, Encodable, Decodable)] -struct KindMap(TreeMap<~str, ~str>); +struct KindMap(TreeMap); 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, 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 = TreeMapbool>; #[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, io::IoError>>(t: &T) -> ~str { +fn json_encode<'a, T:Encodable, 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 { 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(), diff --git a/src/test/auxiliary/cci_class_4.rs b/src/test/auxiliary/cci_class_4.rs index 733509753d384..67e57de085aaf 100644 --- a/src/test/auxiliary/cci_class_4.rs +++ b/src/test/auxiliary/cci_class_4.rs @@ -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, diff --git a/src/test/auxiliary/cci_class_cast.rs b/src/test/auxiliary/cci_class_cast.rs index 2ce4f818659e8..0abacf9ecdd23 100644 --- a/src/test/auxiliary/cci_class_cast.rs +++ b/src/test/auxiliary/cci_class_cast.rs @@ -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, diff --git a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs index f7b42e05d7f8d..36e46f6c8c286 100644 --- a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs +++ b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs @@ -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) { } } } diff --git a/src/test/auxiliary/crateresolve5-1.rs b/src/test/auxiliary/crateresolve5-1.rs index 8c9ce5dda66f2..ca3cf1bd857ae 100644 --- a/src/test/auxiliary/crateresolve5-1.rs +++ b/src/test/auxiliary/crateresolve5-1.rs @@ -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 { diff --git a/src/test/auxiliary/crateresolve5-2.rs b/src/test/auxiliary/crateresolve5-2.rs index 52296e2c054a4..631f68d0b8474 100644 --- a/src/test/auxiliary/crateresolve5-2.rs +++ b/src/test/auxiliary/crateresolve5-2.rs @@ -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 { diff --git a/src/test/auxiliary/explicit_self_xcrate.rs b/src/test/auxiliary/explicit_self_xcrate.rs index e482e8c62cab2..c23af84b3f5ee 100644 --- a/src/test/auxiliary/explicit_self_xcrate.rs +++ b/src/test/auxiliary/explicit_self_xcrate.rs @@ -14,7 +14,7 @@ pub trait Foo { } pub struct Bar { - pub x: ~str + pub x: StrBuf } impl Foo for Bar { diff --git a/src/test/auxiliary/issue-2414-a.rs b/src/test/auxiliary/issue-2414-a.rs index 0e444a43c7cef..7767859144ac9 100644 --- a/src/test/auxiliary/issue-2414-a.rs +++ b/src/test/auxiliary/issue-2414-a.rs @@ -17,6 +17,6 @@ trait foo { fn foo(&self); } -impl foo for ~str { +impl foo for StrBuf { fn foo(&self) {} } diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index 5da5653f26e64..495999bfcbcba 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -17,9 +17,11 @@ extern crate collections; use std::cell::RefCell; use collections::HashMap; -pub type header_map = HashMap<~str, @RefCell>>; +pub type header_map = HashMap>>; // the unused ty param is necessary so this gets monomorphized pub fn request(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(); } diff --git a/src/test/auxiliary/issue13507.rs b/src/test/auxiliary/issue13507.rs index 2b4df978cc8c5..3c860958e2c10 100644 --- a/src/test/auxiliary/issue13507.rs +++ b/src/test/auxiliary/issue13507.rs @@ -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 { diff --git a/src/test/auxiliary/issue_2242_a.rs b/src/test/auxiliary/issue_2242_a.rs index e51624dec3880..855e48f3f91a0 100644 --- a/src/test/auxiliary/issue_2242_a.rs +++ b/src/test/auxiliary/issue_2242_a.rs @@ -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() } } diff --git a/src/test/auxiliary/issue_2242_c.rs b/src/test/auxiliary/issue_2242_c.rs index 4beb8118e210e..6c04a742efb8d 100644 --- a/src/test/auxiliary/issue_2242_c.rs +++ b/src/test/auxiliary/issue_2242_c.rs @@ -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) } } diff --git a/src/test/auxiliary/reexported_static_methods.rs b/src/test/auxiliary/reexported_static_methods.rs index 6d94bfcf613b9..f93bd5e2e4972 100644 --- a/src/test/auxiliary/reexported_static_methods.rs +++ b/src/test/auxiliary/reexported_static_methods.rs @@ -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() } } } diff --git a/src/test/auxiliary/static-methods-crate.rs b/src/test/auxiliary/static-methods-crate.rs index 4e0489b068500..367ab47ceaa1a 100644 --- a/src/test/auxiliary/static-methods-crate.rs +++ b/src/test/auxiliary/static-methods-crate.rs @@ -14,17 +14,17 @@ use std::int; pub trait read { - fn readMaybe(s: ~str) -> Option; + fn readMaybe(s: StrBuf) -> Option; } impl read for int { - fn readMaybe(s: ~str) -> Option { - from_str::(s) + fn readMaybe(s: StrBuf) -> Option { + from_str::(s.as_slice()) } } impl read for bool { - fn readMaybe(s: ~str) -> Option { + fn readMaybe(s: StrBuf) -> Option { match s.as_slice() { "true" => Some(true), "false" => Some(false), @@ -33,7 +33,7 @@ impl read for bool { } } -pub fn read(s: ~str) -> T { +pub fn read(s: StrBuf) -> T { match read::readMaybe(s) { Some(x) => x, _ => fail!("read failed!") diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index 53b371e06cbe0..757d61f285746 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -80,7 +80,7 @@ impl Results { } } - pub fn bench_str, + pub fn bench_str, 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::().to_str(); + let s = rng.gen::().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 = 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 = TreeSet::new(); s }); write_results("collections::TreeSet", &results); diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 7e54198bd3961..9c854a31c1e5e 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -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::>(); 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 { diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 5a42d2e3c59fa..0135688a81cb5 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -52,12 +52,12 @@ fn server(requests: &Receiver, responses: &Sender) { //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::(args[1]).unwrap(); - let workers = from_str::(args[2]).unwrap(); + let size = from_str::(args[1].as_slice()).unwrap(); + let workers = from_str::(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()); } diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 741cc4be4faed..20ed7efcb8316 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -47,11 +47,11 @@ fn server(requests: &Receiver, responses: &Sender) { //println!("server exiting"); } -fn run(args: &[~str]) { +fn run(args: &[StrBuf]) { let (to_parent, from_child) = channel(); - let size = from_str::(args[1]).unwrap(); - let workers = from_str::(args[2]).unwrap(); + let size = from_str::(args[1].as_slice()).unwrap(); + let workers = from_str::(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); diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 8914c5b327ecc..181d19ade3ab4 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -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::>>(); + }).collect::>>(); for message in messages.mut_iter() { println!("{}", *message.get_ref()); diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 07e5b08c37ccb..9db068e56c29a 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -107,7 +107,7 @@ fn creature( mut color: Color, from_rendezvous: Receiver, to_rendezvous: Sender, - to_rendezvous_log: Sender<~str> + to_rendezvous_log: Sender ) { 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) { let (to_rendezvous, from_creatures) = channel::(); // 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::(); // these channels will allow us to talk to each creature by 'name'/index let mut to_creature: Vec> = diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 04032c4aa3903..250562a095ea0 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -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 , uint>, total: uint) -> ~str { +fn sort_and_fmt(mm: &HashMap , 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 , 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 , uint>, key: ~str) -> uint { - let key = key.into_ascii().as_slice().to_lower().into_str(); +fn find(mm: &HashMap , 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 { fn make_sequence_processor(sz: uint, from_parent: &Receiver>, - to_parent: &Sender<~str>) { + to_parent: &Sender) { let mut freqs: HashMap, 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::())); let mut from_child = Vec::new(); let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| { let sz = *sz; diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 45f8b1b9a839c..dd795b7faea81 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -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) -> Vec { 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) -> Vec { sol } -// Prints a solution in ~str form. +// Prints a solution in StrBuf form. fn print_sol(sol: &Vec) { for (i, c) in sol.iter().enumerate() { if (i) % 5 == 0 { println!(""); } diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 0819b71853a49..a6e579689ed42 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -52,9 +52,10 @@ struct Config { stress: bool } -fn parse_opts(argv: Vec<~str> ) -> Config { +fn parse_opts(argv: Vec ) -> Config { let opts = vec!(getopts::optflag("", "stress", "")); + let argv = argv.iter().map(|x| x.to_str()).collect::>(); 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()); diff --git a/src/test/compile-fail/bad-const-type.rs b/src/test/compile-fail/bad-const-type.rs index 92643eca3c83b..ab5735150fdc4 100644 --- a/src/test/compile-fail/bad-const-type.rs +++ b/src/test/compile-fail/bad-const-type.rs @@ -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); } diff --git a/src/test/compile-fail/bad-expr-path.rs b/src/test/compile-fail/bad-expr-path.rs index 6e73427f80f95..0fadbbe785d90 100644 --- a/src/test/compile-fail/bad-expr-path.rs +++ b/src/test/compile-fail/bad-expr-path.rs @@ -12,4 +12,4 @@ mod m1 {} -fn main(args: Vec<~str>) { log(debug, m1::a); } +fn main(args: Vec) { log(debug, m1::a); } diff --git a/src/test/compile-fail/bad-expr-path2.rs b/src/test/compile-fail/bad-expr-path2.rs index d2b3a57868683..84bdf40dbabea 100644 --- a/src/test/compile-fail/bad-expr-path2.rs +++ b/src/test/compile-fail/bad-expr-path2.rs @@ -14,6 +14,6 @@ mod m1 { pub mod a {} } -fn main(args: Vec<~str>) { +fn main(args: Vec) { log(debug, m1::a); } diff --git a/src/test/compile-fail/binop-bitxor-str.rs b/src/test/compile-fail/binop-bitxor-str.rs index d97628bad7a79..c0da78737ca9f 100644 --- a/src/test/compile-fail/binop-bitxor-str.rs +++ b/src/test/compile-fail/binop-bitxor-str.rs @@ -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(); } diff --git a/src/test/compile-fail/borrowck-move-error-with-note.rs b/src/test/compile-fail/borrowck-move-error-with-note.rs index 72101d86960c2..de77bb8144d87 100644 --- a/src/test/compile-fail/borrowck-move-error-with-note.rs +++ b/src/test/compile-fail/borrowck-move-error-with-note.rs @@ -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 diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs index 2be5d5701352a..c65f2523f9bd8 100644 --- a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -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() { diff --git a/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs b/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs index e40fc4e4b236f..1de48b6192097 100644 --- a/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs +++ b/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs @@ -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 } diff --git a/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs b/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs index 9701283469b1f..0b7939f18980c 100644 --- a/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs +++ b/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs @@ -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 } diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs index 317c30c6e19b4..a30d8d44ca072 100644 --- a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs @@ -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 { diff --git a/src/test/compile-fail/break-outside-loop.rs b/src/test/compile-fail/break-outside-loop.rs index 210e3d3af800b..5a5b63ba8466c 100644 --- a/src/test/compile-fail/break-outside-loop.rs +++ b/src/test/compile-fail/break-outside-loop.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - t: ~str + t: StrBuf } fn cond() -> bool { true } diff --git a/src/test/compile-fail/by-move-pattern-binding.rs b/src/test/compile-fail/by-move-pattern-binding.rs index 986db86a6c1e1..12d9e1610a535 100644 --- a/src/test/compile-fail/by-move-pattern-binding.rs +++ b/src/test/compile-fail/by-move-pattern-binding.rs @@ -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 diff --git a/src/test/compile-fail/check-static-values-constraints.rs b/src/test/compile-fail/check-static-values-constraints.rs index 6c1e759cc2fa7..06317f06f262d 100644 --- a/src/test/compile-fail/check-static-values-constraints.rs +++ b/src/test/compile-fail/check-static-values-constraints.rs @@ -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] = &'static [box MyOwned, box MyOwned]; //~^ ERROR static items are not allowed to have owned pointers diff --git a/src/test/compile-fail/circular_modules_main.rs b/src/test/compile-fail/circular_modules_main.rs index a1739849807cc..bc9f3247db706 100644 --- a/src/test/compile-fail/circular_modules_main.rs +++ b/src/test/compile-fail/circular_modules_main.rs @@ -11,7 +11,7 @@ mod circular_modules_hello; //~ERROR: circular modules -pub fn hi_str() -> ~str { +pub fn hi_str() -> StrBuf { "Hi!".to_owned() } diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index c4344db027bae..b28d9dabbb93b 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -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 = box cat(0, 2, "nyan".to_owned()) as Box; + let nyan: Box = box cat(0, 2, "nyan".to_strbuf()) as Box; nyan.eat(); //~ ERROR does not implement any method in scope named `eat` } diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs index 40bb63907c9f1..acf825f8913f6 100644 --- a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs @@ -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); } diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs index eec665b62f9d1..80e624afdb876 100644 --- a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs @@ -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) diff --git a/src/test/compile-fail/estr-subtyping.rs b/src/test/compile-fail/estr-subtyping.rs index db86b5e092c52..b2ac06127847c 100644 --- a/src/test/compile-fail/estr-subtyping.rs +++ b/src/test/compile-fail/estr-subtyping.rs @@ -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); } diff --git a/src/test/compile-fail/generic-type-params-name-repr.rs b/src/test/compile-fail/generic-type-params-name-repr.rs index e3d624e9452ba..39b6a276e7075 100644 --- a/src/test/compile-fail/generic-type-params-name-repr.rs +++ b/src/test/compile-fail/generic-type-params-name-repr.rs @@ -28,10 +28,10 @@ fn main() { //~^ ERROR mismatched types: expected `Foo` 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 = (); + //~^ ERROR mismatched types: expected `HashMap` but found `()` + let _: HashMap> = (); + //~^ ERROR mismatched types: expected `HashMap` but found `()` // But not when there's a different type in between. let _: Foo = (); diff --git a/src/test/compile-fail/import.rs b/src/test/compile-fail/import.rs index 350b077690418..654443bde24c9 100644 --- a/src/test/compile-fail/import.rs +++ b/src/test/compile-fail/import.rs @@ -16,4 +16,4 @@ use zed::baz; mod zed { pub fn bar() { println!("bar"); } } -fn main(args: Vec<~str>) { bar(); } +fn main(args: Vec) { bar(); } diff --git a/src/test/compile-fail/import2.rs b/src/test/compile-fail/import2.rs index 8b282ba88418b..11e757803065b 100644 --- a/src/test/compile-fail/import2.rs +++ b/src/test/compile-fail/import2.rs @@ -16,4 +16,4 @@ mod baz {} mod zed { pub fn bar() { println!("bar3"); } } -fn main(args: Vec<~str>) { bar(); } +fn main(args: Vec) { bar(); } diff --git a/src/test/compile-fail/integral-indexing.rs b/src/test/compile-fail/integral-indexing.rs index ee839893e8ebe..d41573b85575a 100644 --- a/src/test/compile-fail/integral-indexing.rs +++ b/src/test/compile-fail/integral-indexing.rs @@ -10,17 +10,17 @@ pub fn main() { let v: Vec = 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 } diff --git a/src/test/compile-fail/issue-13428.rs b/src/test/compile-fail/issue-13428.rs index 7e24d909237bb..ab763a2b583ca 100644 --- a/src/test/compile-fail/issue-13428.rs +++ b/src/test/compile-fail/issue-13428.rs @@ -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 } diff --git a/src/test/compile-fail/issue-2063.rs b/src/test/compile-fail/issue-2063.rs index 4a6219aafd081..fcbe8f7b56362 100644 --- a/src/test/compile-fail/issue-2063.rs +++ b/src/test/compile-fail/issue-2063.rs @@ -16,14 +16,14 @@ struct t(Box); //~ 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) { diff --git a/src/test/compile-fail/issue-3099.rs b/src/test/compile-fail/issue-3099.rs index 85989c4a40a6b..365ee54645f20 100644 --- a/src/test/compile-fail/issue-3099.rs +++ b/src/test/compile-fail/issue-3099.rs @@ -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) } diff --git a/src/test/compile-fail/issue-3601.rs b/src/test/compile-fail/issue-3601.rs index 6ca4e22576ec4..15bcc53b8cec4 100644 --- a/src/test/compile-fail/issue-3601.rs +++ b/src/test/compile-fail/issue-3601.rs @@ -10,7 +10,7 @@ struct HTMLImageData { - image: Option<~str> + image: Option } struct ElementData { diff --git a/src/test/compile-fail/issue-3973.rs b/src/test/compile-fail/issue-3973.rs index c44336aeaf52b..fdf9a39696352 100644 --- a/src/test/compile-fail/issue-3973.rs +++ b/src/test/compile-fail/issue-3973.rs @@ -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) } } diff --git a/src/test/compile-fail/issue-5543.rs b/src/test/compile-fail/issue-5543.rs index f143d74d8c232..ebc82ab361d54 100644 --- a/src/test/compile-fail/issue-5543.rs +++ b/src/test/compile-fail/issue-5543.rs @@ -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(); diff --git a/src/test/compile-fail/issue-6458-4.rs b/src/test/compile-fail/issue-6458-4.rs index 1d792dba0d874..b12d2be612ec5 100644 --- a/src/test/compile-fail/issue-6458-4.rs +++ b/src/test/compile-fail/issue-6458-4.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(b: bool) -> Result { +fn foo(b: bool) -> Result { Err("bar".to_owned()); //~^ ERROR: cannot determine a type for this expression: unconstrained type } diff --git a/src/test/compile-fail/issue-7573.rs b/src/test/compile-fail/issue-7573.rs index e39b2d9309bec..d79bc942118d5 100644 --- a/src/test/compile-fail/issue-7573.rs +++ b/src/test/compile-fail/issue-7573.rs @@ -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() } } } diff --git a/src/test/compile-fail/issue-7575.rs b/src/test/compile-fail/issue-7575.rs index 5b03e6fc2265d..f23e398596f00 100644 --- a/src/test/compile-fail/issue-7575.rs +++ b/src/test/compile-fail/issue-7575.rs @@ -51,7 +51,7 @@ trait ManyImplTrait { } } -impl ManyImplTrait for ~str { +impl ManyImplTrait for StrBuf { fn is_str() -> bool { true } diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index 694b0f1dbe27d..c5c14005c70a6 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -39,7 +39,7 @@ fn test<'a,T,U:Copy>(_: &'a int) { // ~ pointers are not ok assert_copy::>(); //~ ERROR does not fulfill - assert_copy::<~str>(); //~ ERROR does not fulfill + assert_copy::(); //~ ERROR does not fulfill assert_copy:: >(); //~ ERROR does not fulfill assert_copy::>(); //~ ERROR does not fulfill diff --git a/src/test/compile-fail/kindck-send.rs b/src/test/compile-fail/kindck-send.rs index 518e97515e799..c2c35e05edea4 100644 --- a/src/test/compile-fail/kindck-send.rs +++ b/src/test/compile-fail/kindck-send.rs @@ -30,7 +30,7 @@ fn test<'a,T,U:Send>(_: &'a int) { // boxes are ok assert_send::>(); - assert_send::<~str>(); + assert_send::(); assert_send:: >(); // but not if they own a bad thing diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index ecea33cbe8efd..c33719a2fc19b 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -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 { fail!() } callback(|| { what(); diff --git a/src/test/compile-fail/lub-if.rs b/src/test/compile-fail/lub-if.rs index 6b5055cb1a2cd..fe64551a4b537 100644 --- a/src/test/compile-fail/lub-if.rs +++ b/src/test/compile-fail/lub-if.rs @@ -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) -> &'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) -> &'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) -> &'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) -> &'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)" diff --git a/src/test/compile-fail/lub-match.rs b/src/test/compile-fail/lub-match.rs index 37b9cc55dc822..932107b787814 100644 --- a/src/test/compile-fail/lub-match.rs +++ b/src/test/compile-fail/lub-match.rs @@ -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) -> &'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) -> &'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) -> &'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) -> &'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)", diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index b59011b588021..aa8cb84481f1e 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -15,9 +15,9 @@ use collections::HashMap; // Test that trait types printed in error msgs include the type arguments. fn main() { - let x: Box> = box HashMap::new(); - let x: Box> = x; - let y: Box> = box x; - //~^ ERROR failed to find an implementation of trait core::container::Map - // for ~core::container::Map<~str,~str>:Send + let x: Box> = box HashMap::new(); + let x: Box> = x; + let y: Box> = box x; + //~^ ERROR failed to find an implementation of trait core::container::Map + // for ~core::container::Map:Send } diff --git a/src/test/compile-fail/match-vec-mismatch.rs b/src/test/compile-fail/match-vec-mismatch.rs index 17c93f596e9c5..56d3d76bf7c17 100644 --- a/src/test/compile-fail/match-vec-mismatch.rs +++ b/src/test/compile-fail/match-vec-mismatch.rs @@ -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 _ => { } } } diff --git a/src/test/compile-fail/match-vec-unreachable.rs b/src/test/compile-fail/match-vec-unreachable.rs index 2e3b5e399f195..128c25889d87b 100644 --- a/src/test/compile-fail/match-vec-unreachable.rs +++ b/src/test/compile-fail/match-vec-unreachable.rs @@ -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 = vec!["foo".to_strbuf(), + "bar".to_strbuf(), + "baz".to_strbuf()]; + let x: &[StrBuf] = x.as_slice(); match x { [a, _, _, ..] => { println!("{}", a); } [_, _, _, _, _] => { } //~ ERROR unreachable pattern diff --git a/src/test/compile-fail/minus-string.rs b/src/test/compile-fail/minus-string.rs index 636debc77e01b..b194b2d833164 100644 --- a/src/test/compile-fail/minus-string.rs +++ b/src/test/compile-fail/minus-string.rs @@ -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(); } diff --git a/src/test/compile-fail/moves-based-on-type-access-to-field.rs b/src/test/compile-fail/moves-based-on-type-access-to-field.rs index dc2cd22e632e0..fcad6469bccf6 100644 --- a/src/test/compile-fail/moves-based-on-type-access-to-field.rs +++ b/src/test/compile-fail/moves-based-on-type-access-to-field.rs @@ -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) {} 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` } diff --git a/src/test/compile-fail/moves-based-on-type-exprs.rs b/src/test/compile-fail/moves-based-on-type-exprs.rs index ea96d87855e74..29b4dc573e3a2 100644 --- a/src/test/compile-fail/moves-based-on-type-exprs.rs +++ b/src/test/compile-fail/moves-based-on-type-exprs.rs @@ -14,17 +14,17 @@ #![feature(managed_boxes)] struct Foo { f: A } -fn guard(_s: ~str) -> bool {fail!()} +fn guard(_s: StrBuf) -> bool {fail!()} fn touch(_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)); diff --git a/src/test/compile-fail/moves-based-on-type-match-bindings.rs b/src/test/compile-fail/moves-based-on-type-match-bindings.rs index 59918b51e4c90..83b7658a47389 100644 --- a/src/test/compile-fail/moves-based-on-type-match-bindings.rs +++ b/src/test/compile-fail/moves-based-on-type-match-bindings.rs @@ -13,7 +13,7 @@ // terms of the binding, not the discriminant. struct Foo { f: A } -fn guard(_s: ~str) -> bool {fail!()} +fn guard(_s: StrBuf) -> bool {fail!()} fn touch(_a: &A) {} fn f10() { diff --git a/src/test/compile-fail/multitrait.rs b/src/test/compile-fail/multitrait.rs index a57e7ebe6a04f..a0c007a2627e0 100644 --- a/src/test/compile-fail/multitrait.rs +++ b/src/test/compile-fail/multitrait.rs @@ -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() } } diff --git a/src/test/compile-fail/unsendable-class.rs b/src/test/compile-fail/unsendable-class.rs index a30337aba68c3..a0e3a15dfa529 100644 --- a/src/test/compile-fail/unsendable-class.rs +++ b/src/test/compile-fail/unsendable-class.rs @@ -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` } diff --git a/src/test/debuginfo/issue11600.rs b/src/test/debuginfo/issue11600.rs index 426a40bf8bdab..915ccab770056 100644 --- a/src/test/debuginfo/issue11600.rs +++ b/src/test/debuginfo/issue11600.rs @@ -13,7 +13,7 @@ // ignore-test fn main() { - let args : ~[~str] = ::std::os::args(); + let args : ~[StrBuf] = ::std::os::args(); ::std::io::println(args[0]); } @@ -25,6 +25,6 @@ fn main() { // compile-flags:-g // gdb-command:list // gdb-check:1[...]fn main() { -// gdb-check:2[...]let args : ~[~str] = ::std::os::args(); +// gdb-check:2[...]let args : ~[StrBuf] = ::std::os::args(); // gdb-check:3[...]::std::io::println(args[0]); // gdb-check:4[...]} diff --git a/src/test/pretty/closure-reform-pretty.rs b/src/test/pretty/closure-reform-pretty.rs index a9d0d1f67d5f6..d18627c1ba182 100644 --- a/src/test/pretty/closure-reform-pretty.rs +++ b/src/test/pretty/closure-reform-pretty.rs @@ -13,7 +13,7 @@ // pp-exact -fn call_it(f: proc(~str) -> ~str) { } +fn call_it(f: proc(StrBuf) -> StrBuf) { } fn call_this(f: |&str|: Send) { } diff --git a/src/test/run-fail/binop-fail-2.rs b/src/test/run-fail/binop-fail-2.rs index 1186c5008f73e..680481ad491b9 100644 --- a/src/test/run-fail/binop-fail-2.rs +++ b/src/test/run-fail/binop-fail-2.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern:quux -fn my_err(s: ~str) -> ! { println!("{}", s); fail!("quux"); } -fn main() { 3u == my_err("bye".to_owned()); } +fn my_err(s: StrBuf) -> ! { println!("{}", s); fail!("quux"); } +fn main() { 3u == my_err("bye".to_strbuf()); } diff --git a/src/test/run-fail/binop-fail.rs b/src/test/run-fail/binop-fail.rs index 1186c5008f73e..680481ad491b9 100644 --- a/src/test/run-fail/binop-fail.rs +++ b/src/test/run-fail/binop-fail.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern:quux -fn my_err(s: ~str) -> ! { println!("{}", s); fail!("quux"); } -fn main() { 3u == my_err("bye".to_owned()); } +fn my_err(s: StrBuf) -> ! { println!("{}", s); fail!("quux"); } +fn main() { 3u == my_err("bye".to_strbuf()); } diff --git a/src/test/run-fail/fmt-fail.rs b/src/test/run-fail/fmt-fail.rs index 9c7979efb6c02..37955561c08b6 100644 --- a/src/test/run-fail/fmt-fail.rs +++ b/src/test/run-fail/fmt-fail.rs @@ -10,4 +10,7 @@ // error-pattern:meh -fn main() { let str_var: ~str = "meh".to_owned(); fail!("{}", str_var); } +fn main() { + let str_var: StrBuf = "meh".to_strbuf(); + fail!("{}", str_var); +} diff --git a/src/test/run-fail/if-cond-bot.rs b/src/test/run-fail/if-cond-bot.rs index f300a1fa7158e..ef8a38df1781f 100644 --- a/src/test/run-fail/if-cond-bot.rs +++ b/src/test/run-fail/if-cond-bot.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern:quux -fn my_err(s: ~str) -> ! { println!("{}", s); fail!("quux"); } -fn main() { if my_err("bye".to_owned()) { } } +fn my_err(s: StrBuf) -> ! { println!("{}", s); fail!("quux"); } +fn main() { if my_err("bye".to_strbuf()) { } } diff --git a/src/test/run-fail/match-bot-fail.rs b/src/test/run-fail/match-bot-fail.rs index 9728c84b9005d..d75466a1738b5 100644 --- a/src/test/run-fail/match-bot-fail.rs +++ b/src/test/run-fail/match-bot-fail.rs @@ -13,7 +13,7 @@ #![allow(unreachable_code)] #![allow(unused_variable)] -fn foo(s: ~str) { } +fn foo(s: StrBuf) { } fn main() { let i = diff --git a/src/test/run-fail/result-get-fail.rs b/src/test/run-fail/result-get-fail.rs index 0a3746e44651e..613957980de44 100644 --- a/src/test/run-fail/result-get-fail.rs +++ b/src/test/run-fail/result-get-fail.rs @@ -13,5 +13,5 @@ use std::result; fn main() { - println!("{:?}", result::Err::("kitty".to_owned()).unwrap()); + println!("{:?}", result::Err::("kitty".to_strbuf()).unwrap()); } diff --git a/src/test/run-fail/rhs-type.rs b/src/test/run-fail/rhs-type.rs index 584be2d89b756..d224393b2eaeb 100644 --- a/src/test/run-fail/rhs-type.rs +++ b/src/test/run-fail/rhs-type.rs @@ -15,7 +15,7 @@ #![allow(unreachable_code)] #![allow(unused_variable)] -struct T { t: ~str } +struct T { t: StrBuf } fn main() { let pth = fail!("bye"); diff --git a/src/test/run-fail/str-overrun.rs b/src/test/run-fail/str-overrun.rs index 9f7b03ac2ea3d..879a14896d62b 100644 --- a/src/test/run-fail/str-overrun.rs +++ b/src/test/run-fail/str-overrun.rs @@ -11,8 +11,8 @@ // error-pattern:index out of bounds: the len is 5 but the index is 5 fn main() { - let s: ~str = "hello".to_owned(); + let s: StrBuf = "hello".to_strbuf(); // Bounds-check failure. - assert_eq!(s[5], 0x0 as u8); + assert_eq!(s.as_slice()[5], 0x0 as u8); } diff --git a/src/test/run-fail/unwind-lambda.rs b/src/test/run-fail/unwind-lambda.rs index ddaddcec39000..d3be456f3428d 100644 --- a/src/test/run-fail/unwind-lambda.rs +++ b/src/test/run-fail/unwind-lambda.rs @@ -13,17 +13,17 @@ // error-pattern:fail fn main() { - let cheese = "roquefort".to_owned(); - let carrots = @"crunchy".to_owned(); + let cheese = "roquefort".to_strbuf(); + let carrots = @"crunchy".to_strbuf(); - let result: |@~str, |~str||: 'static = (|tasties, macerate| { + let result: |@StrBuf, |StrBuf||: 'static = (|tasties, macerate| { macerate((*tasties).clone()); }); result(carrots, |food| { - let mush = food + cheese; + let mush = format_strbuf!("{}{}", food, cheese); let cheese = cheese.clone(); let f: || = || { - let _chew = mush + cheese; + let _chew = format_strbuf!("{}{}", mush, cheese); fail!("so yummy") }; f(); diff --git a/src/test/run-make/unicode-input/span_length.rs b/src/test/run-make/unicode-input/span_length.rs index 13f141008b792..d561497521551 100644 --- a/src/test/run-make/unicode-input/span_length.rs +++ b/src/test/run-make/unicode-input/span_length.rs @@ -48,7 +48,7 @@ fn main() { let _ = write!(&mut File::create(&main_file).unwrap(), r"\#![feature(non_ascii_idents)] fn main() \{ {} \}", // random string of length n - range(0, n).map(|_| random_char()).collect::<~str>()); + range(0, n).map(|_| random_char()).collect::()); } // rustc is passed to us with --out-dir and -L etc., so we diff --git a/src/test/run-pass-fulldeps/qquote.rs b/src/test/run-pass-fulldeps/qquote.rs index 3b3e4066e0ccd..4b8aed0a18738 100644 --- a/src/test/run-pass-fulldeps/qquote.rs +++ b/src/test/run-pass-fulldeps/qquote.rs @@ -75,7 +75,7 @@ fn main() { } fn check_pp(cx: fake_ext_ctxt, - expr: T, f: |pprust::ps, T|, expect: ~str) { + expr: T, f: |pprust::ps, T|, expect: StrBuf) { let s = io::with_str_writer(|wr| { let pp = pprust::rust_printer(wr, cx.parse_sess().interner); f(pp, expr); diff --git a/src/test/run-pass/alias-uninit-value.rs b/src/test/run-pass/alias-uninit-value.rs index ab395466afcf7..a78622a37a2fd 100644 --- a/src/test/run-pass/alias-uninit-value.rs +++ b/src/test/run-pass/alias-uninit-value.rs @@ -14,10 +14,10 @@ enum sty { ty_nil, } -struct RawT {struct_: sty, cname: Option<~str>, hash: uint} +struct RawT {struct_: sty, cname: Option, hash: uint} -fn mk_raw_ty(st: sty, cname: Option<~str>) -> RawT { +fn mk_raw_ty(st: sty, cname: Option) -> RawT { return RawT {struct_: st, cname: cname, hash: 0u}; } -pub fn main() { mk_raw_ty(ty_nil, None::<~str>); } +pub fn main() { mk_raw_ty(ty_nil, None::); } diff --git a/src/test/run-pass/autobind.rs b/src/test/run-pass/autobind.rs index 5dad14c7d99be..445abf4ca4951 100644 --- a/src/test/run-pass/autobind.rs +++ b/src/test/run-pass/autobind.rs @@ -15,6 +15,7 @@ fn g(act: |Vec | -> int) -> int { return act(vec!(1, 2, 3)); } pub fn main() { assert_eq!(g(f), 1); - let f1: |Vec<~str> | -> ~str = f; - assert_eq!(f1(vec!("x".to_owned(), "y".to_owned(), "z".to_owned())), "x".to_owned()); + let f1: |Vec| -> StrBuf = f; + assert_eq!(f1(vec!["x".to_strbuf(), "y".to_strbuf(), "z".to_strbuf()]), + "x".to_strbuf()); } diff --git a/src/test/run-pass/autoref-intermediate-types-issue-3585.rs b/src/test/run-pass/autoref-intermediate-types-issue-3585.rs index ca11fb355c000..778704a4b96e4 100644 --- a/src/test/run-pass/autoref-intermediate-types-issue-3585.rs +++ b/src/test/run-pass/autoref-intermediate-types-issue-3585.rs @@ -11,22 +11,22 @@ #![feature(managed_boxes)] trait Foo { - fn foo(&self) -> ~str; + fn foo(&self) -> StrBuf; } impl Foo for @T { - fn foo(&self) -> ~str { - format!("@{}", (**self).foo()) + fn foo(&self) -> StrBuf { + format_strbuf!("@{}", (**self).foo()) } } impl Foo for uint { - fn foo(&self) -> ~str { - format!("{}", *self) + fn foo(&self) -> StrBuf { + format_strbuf!("{}", *self) } } pub fn main() { let x = @3u; - assert_eq!(x.foo(), "@3".to_owned()); + assert_eq!(x.foo(), "@3".to_strbuf()); } diff --git a/src/test/run-pass/backtrace.rs b/src/test/run-pass/backtrace.rs index 53fe91cff3745..260ce69f821d7 100644 --- a/src/test/run-pass/backtrace.rs +++ b/src/test/run-pass/backtrace.rs @@ -36,14 +36,21 @@ fn double() { } fn runtest(me: &str) { - let mut env = os::env().move_iter().collect::>(); - match env.iter().position(|&(ref s, _)| "RUST_BACKTRACE" == *s) { + let mut env = os::env().move_iter() + .map(|(ref k, ref v)| { + (k.to_strbuf(), v.to_strbuf()) + }).collect::>(); + match env.iter() + .position(|&(ref s, _)| "RUST_BACKTRACE" == s.as_slice()) { Some(i) => { env.remove(i); } None => {} } - env.push(("RUST_BACKTRACE".to_owned(), "1".to_owned())); + env.push(("RUST_BACKTRACE".to_strbuf(), "1".to_strbuf())); // Make sure that the stack trace is printed + let env = env.iter() + .map(|&(ref k, ref v)| (k.to_owned(), v.to_owned())) + .collect::>(); let mut p = Process::configure(ProcessConfig { program: me, args: ["fail".to_owned()], diff --git a/src/test/run-pass/block-explicit-types.rs b/src/test/run-pass/block-explicit-types.rs index 8df2679aa53d5..f60510dc802f3 100644 --- a/src/test/run-pass/block-explicit-types.rs +++ b/src/test/run-pass/block-explicit-types.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn main() { - fn as_buf(s: ~str, f: |~str| -> T) -> T { f(s) } - as_buf("foo".to_owned(), |foo: ~str| -> () println!("{}", foo) ); + fn as_buf(s: StrBuf, f: |StrBuf| -> T) -> T { f(s) } + as_buf("foo".to_strbuf(), |foo: StrBuf| -> () println!("{}", foo) ); } diff --git a/src/test/run-pass/borrowed-ptr-pattern-2.rs b/src/test/run-pass/borrowed-ptr-pattern-2.rs index c961f59f98148..c80246d27e681 100644 --- a/src/test/run-pass/borrowed-ptr-pattern-2.rs +++ b/src/test/run-pass/borrowed-ptr-pattern-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(s: &~str) -> bool { +fn foo(s: &StrBuf) -> bool { match s.as_slice() { "kitty" => true, _ => false @@ -16,6 +16,6 @@ fn foo(s: &~str) -> bool { } pub fn main() { - assert!(foo(&"kitty".to_owned())); - assert!(!foo(&"gata".to_owned())); + assert!(foo(&"kitty".to_strbuf())); + assert!(!foo(&"gata".to_strbuf())); } diff --git a/src/test/run-pass/bug-7183-generics.rs b/src/test/run-pass/bug-7183-generics.rs index 86fde76fb75fd..5f536026ea62f 100644 --- a/src/test/run-pass/bug-7183-generics.rs +++ b/src/test/run-pass/bug-7183-generics.rs @@ -9,35 +9,36 @@ // except according to those terms. trait Speak { - fn say(&self, s:&str) -> ~str; - fn hi(&self) -> ~str { hello(self) } + fn say(&self, s:&str) -> StrBuf; + fn hi(&self) -> StrBuf { hello(self) } } -fn hello(s:&S) -> ~str{ +fn hello(s:&S) -> StrBuf{ s.say("hello") } impl Speak for int { - fn say(&self, s:&str) -> ~str { - format!("{}: {}", s, *self) + fn say(&self, s:&str) -> StrBuf { + format_strbuf!("{}: {}", s, *self) } } impl Speak for Option { - fn say(&self, s:&str) -> ~str { + fn say(&self, s:&str) -> StrBuf { match *self { - None => format!("{} - none", s), - Some(ref x) => { "something!".to_owned() + x.say(s) } + None => format_strbuf!("{} - none", s), + Some(ref x) => { format_strbuf!("something!{}", x.say(s)) } } } } pub fn main() { - assert_eq!(3.hi(), "hello: 3".to_owned()); - assert_eq!(Some(Some(3)).hi(), "something!something!hello: 3".to_owned()); - assert_eq!(None::.hi(), "hello - none".to_owned()); + assert_eq!(3.hi(), "hello: 3".to_strbuf()); + assert_eq!(Some(Some(3)).hi(), + "something!something!hello: 3".to_strbuf()); + assert_eq!(None::.hi(), "hello - none".to_strbuf()); - assert_eq!(Some(None::).hi(), "something!hello - none".to_owned()); - assert_eq!(Some(3).hi(), "something!hello: 3".to_owned()); + assert_eq!(Some(None::).hi(), "something!hello - none".to_strbuf()); + assert_eq!(Some(3).hi(), "something!hello: 3".to_strbuf()); } diff --git a/src/test/run-pass/c-stack-returning-int64.rs b/src/test/run-pass/c-stack-returning-int64.rs index 0b38c7fa1ddfe..501d36886a485 100644 --- a/src/test/run-pass/c-stack-returning-int64.rs +++ b/src/test/run-pass/c-stack-returning-int64.rs @@ -21,15 +21,16 @@ mod mlibc { } } -fn atol(s: ~str) -> int { - s.with_c_str(|x| unsafe { mlibc::atol(x) as int }) +fn atol(s: StrBuf) -> int { + s.as_slice().with_c_str(|x| unsafe { mlibc::atol(x) as int }) } -fn atoll(s: ~str) -> i64 { - s.with_c_str(|x| unsafe { mlibc::atoll(x) as i64 }) +fn atoll(s: StrBuf) -> i64 { + s.as_slice().with_c_str(|x| unsafe { mlibc::atoll(x) as i64 }) } pub fn main() { - assert_eq!(atol("1024".to_owned()) * 10, atol("10240".to_owned())); - assert!((atoll("11111111111111111".to_owned()) * 10) == atoll("111111111111111110".to_owned())); + assert_eq!(atol("1024".to_strbuf()) * 10, atol("10240".to_strbuf())); + assert!((atoll("11111111111111111".to_strbuf()) * 10) == + atoll("111111111111111110".to_strbuf())); } diff --git a/src/test/run-pass/child-outlives-parent.rs b/src/test/run-pass/child-outlives-parent.rs index d32eb03e10105..c85b4b06387b3 100644 --- a/src/test/run-pass/child-outlives-parent.rs +++ b/src/test/run-pass/child-outlives-parent.rs @@ -12,8 +12,8 @@ use std::task; -fn child2(_s: ~str) { } +fn child2(_s: StrBuf) { } pub fn main() { - let _x = task::spawn(proc() child2("hi".to_owned())); + let _x = task::spawn(proc() child2("hi".to_strbuf())); } diff --git a/src/test/run-pass/class-attributes-1.rs b/src/test/run-pass/class-attributes-1.rs index 75c3f1a06e223..55cf41d73d591 100644 --- a/src/test/run-pass/class-attributes-1.rs +++ b/src/test/run-pass/class-attributes-1.rs @@ -11,7 +11,7 @@ // pp-exact - Make sure we actually print the attributes struct cat { - name: ~str, + name: StrBuf, } impl Drop for cat { @@ -21,6 +21,6 @@ impl Drop for cat { #[cat_maker] -fn cat(name: ~str) -> cat { cat{name: name,} } +fn cat(name: StrBuf) -> cat { cat{name: name,} } -pub fn main() { let _kitty = cat("Spotty".to_owned()); } +pub fn main() { let _kitty = cat("Spotty".to_strbuf()); } diff --git a/src/test/run-pass/class-attributes-2.rs b/src/test/run-pass/class-attributes-2.rs index d506fa6eb3316..b1ed70278ef32 100644 --- a/src/test/run-pass/class-attributes-2.rs +++ b/src/test/run-pass/class-attributes-2.rs @@ -9,7 +9,7 @@ // except according to those terms. struct cat { - name: ~str, + name: StrBuf, } impl Drop for cat { @@ -26,12 +26,12 @@ impl Drop for cat { /** Maybe it should technically be a kitten_maker. */ -fn cat(name: ~str) -> cat { +fn cat(name: StrBuf) -> cat { cat { name: name } } pub fn main() { - let _kitty = cat("Spotty".to_owned()); + let _kitty = cat("Spotty".to_strbuf()); } diff --git a/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs b/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs index c6c78283e19f5..df9b30697d943 100644 --- a/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs +++ b/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs @@ -14,13 +14,13 @@ extern crate cci_class_cast; use std::to_str::ToStr; use cci_class_cast::kitty::cat; -fn print_out(thing: Box, expected: ~str) { +fn print_out(thing: Box, expected: StrBuf) { let actual = thing.to_str(); println!("{}", actual); - assert_eq!(actual, expected); + assert_eq!(actual.to_strbuf(), expected); } pub fn main() { - let nyan: Box = box cat(0u, 2, "nyan".to_owned()) as Box; - print_out(nyan, "nyan".to_owned()); + let nyan: Box = box cat(0u, 2, "nyan".to_strbuf()) as Box; + print_out(nyan, "nyan".to_strbuf()); } diff --git a/src/test/run-pass/class-cast-to-trait-multiple-types.rs b/src/test/run-pass/class-cast-to-trait-multiple-types.rs index 701a6d44bf5fd..486a505350b8b 100644 --- a/src/test/run-pass/class-cast-to-trait-multiple-types.rs +++ b/src/test/run-pass/class-cast-to-trait-multiple-types.rs @@ -53,7 +53,7 @@ struct cat { meows: uint, how_hungry: int, - name: ~str, + name: StrBuf, } impl noisy for cat { @@ -79,7 +79,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, @@ -93,7 +93,7 @@ fn annoy_neighbors(critter: &mut noisy) { } pub fn main() { - let mut nyan: cat = cat(0u, 2, "nyan".to_owned()); + let mut nyan: cat = cat(0u, 2, "nyan".to_strbuf()); let mut whitefang: dog = dog(); annoy_neighbors(&mut nyan); annoy_neighbors(&mut whitefang); diff --git a/src/test/run-pass/class-cast-to-trait.rs b/src/test/run-pass/class-cast-to-trait.rs index fb479b5937ae2..99070b9737259 100644 --- a/src/test/run-pass/class-cast-to-trait.rs +++ b/src/test/run-pass/class-cast-to-trait.rs @@ -19,7 +19,7 @@ trait noisy { struct cat { meows: uint, how_hungry: int, - name: ~str, + name: StrBuf, } impl noisy for cat { @@ -50,7 +50,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, @@ -60,7 +60,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { pub fn main() { - let mut nyan = cat(0u, 2, "nyan".to_owned()); + let mut nyan = cat(0u, 2, "nyan".to_strbuf()); let mut nyan: &mut noisy = &mut nyan; nyan.speak(); } diff --git a/src/test/run-pass/class-exports.rs b/src/test/run-pass/class-exports.rs index 96270577ce2b9..a7039ca708d96 100644 --- a/src/test/run-pass/class-exports.rs +++ b/src/test/run-pass/class-exports.rs @@ -17,14 +17,14 @@ use kitty::cat; mod kitty { pub struct cat { meows: uint, - name: ~str, + name: StrBuf, } impl cat { - pub fn get_name(&self) -> ~str { self.name.clone() } + pub fn get_name(&self) -> StrBuf { self.name.clone() } } - pub fn cat(in_name: ~str) -> cat { + pub fn cat(in_name: StrBuf) -> cat { cat { name: in_name, meows: 0u @@ -33,5 +33,6 @@ mod kitty { } pub fn main() { - assert_eq!(cat("Spreckles".to_owned()).get_name(), "Spreckles".to_owned()); + assert_eq!(cat("Spreckles".to_strbuf()).get_name(), + "Spreckles".to_strbuf()); } diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 360e82cf8fdac..f02d41df21e4b 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -114,9 +114,9 @@ impl cat { } pub fn main() { - let mut nyan: cat<~str> = cat::new(0, 2, "nyan".to_owned()); + let mut nyan: cat = cat::new(0, 2, "nyan".to_strbuf()); for _ in range(1u, 5) { nyan.speak(); } - assert!(*nyan.find(&1).unwrap() == "nyan".to_owned()); + assert!(*nyan.find(&1).unwrap() == "nyan".to_strbuf()); assert_eq!(nyan.find(&10), None); let mut spotty: cat = cat::new(2, 57, tuxedo); for _ in range(0u, 6) { spotty.speak(); } diff --git a/src/test/run-pass/class-implement-trait-cross-crate.rs b/src/test/run-pass/class-implement-trait-cross-crate.rs index c068c226f4d38..e3a1829597ea4 100644 --- a/src/test/run-pass/class-implement-trait-cross-crate.rs +++ b/src/test/run-pass/class-implement-trait-cross-crate.rs @@ -16,7 +16,7 @@ struct cat { meows: uint, how_hungry : int, - name : ~str, + name : StrBuf, } impl cat { @@ -47,7 +47,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, @@ -57,7 +57,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { pub fn main() { - let mut nyan = cat(0u, 2, "nyan".to_owned()); + let mut nyan = cat(0u, 2, "nyan".to_strbuf()); nyan.eat(); assert!((!nyan.eat())); for _ in range(1u, 10u) { nyan.speak(); }; diff --git a/src/test/run-pass/class-implement-traits.rs b/src/test/run-pass/class-implement-traits.rs index 3739e350d798c..92dc231bf7a52 100644 --- a/src/test/run-pass/class-implement-traits.rs +++ b/src/test/run-pass/class-implement-traits.rs @@ -18,7 +18,7 @@ struct cat { meows : uint, how_hungry : int, - name : ~str, + name : StrBuf, } impl cat { @@ -48,7 +48,7 @@ impl noisy for cat { fn speak(&mut self) { self.meow(); } } -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, @@ -62,7 +62,7 @@ fn make_speak(mut c: C) { } pub fn main() { - let mut nyan = cat(0u, 2, "nyan".to_owned()); + let mut nyan = cat(0u, 2, "nyan".to_strbuf()); nyan.eat(); assert!((!nyan.eat())); for _ in range(1u, 10u) { diff --git a/src/test/run-pass/class-separate-impl.rs b/src/test/run-pass/class-separate-impl.rs index 417c927701d32..874cf1233b8bb 100644 --- a/src/test/run-pass/class-separate-impl.rs +++ b/src/test/run-pass/class-separate-impl.rs @@ -14,7 +14,7 @@ struct cat { meows : uint, how_hungry : int, - name : ~str, + name : StrBuf, } impl cat { @@ -43,7 +43,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, @@ -57,13 +57,13 @@ impl fmt::Show for cat { } } -fn print_out(thing: Box, expected: ~str) { +fn print_out(thing: Box, expected: StrBuf) { let actual = thing.to_str(); println!("{}", actual); - assert_eq!(actual, expected); + assert_eq!(actual.to_strbuf(), expected); } pub fn main() { - let nyan: Box = box cat(0u, 2, "nyan".to_owned()) as Box; - print_out(nyan, "nyan".to_owned()); + let nyan: Box = box cat(0u, 2, "nyan".to_strbuf()) as Box; + print_out(nyan, "nyan".to_strbuf()); } diff --git a/src/test/run-pass/class-str-field.rs b/src/test/run-pass/class-str-field.rs index c1ecbd9b1d2b5..438020bab297b 100644 --- a/src/test/run-pass/class-str-field.rs +++ b/src/test/run-pass/class-str-field.rs @@ -10,16 +10,16 @@ struct cat { - name : ~str, + name : StrBuf, } -fn cat(in_name: ~str) -> cat { +fn cat(in_name: StrBuf) -> cat { cat { name: in_name } } pub fn main() { - let _nyan = cat("nyan".to_owned()); + let _nyan = cat("nyan".to_strbuf()); } diff --git a/src/test/run-pass/classes-cross-crate.rs b/src/test/run-pass/classes-cross-crate.rs index d1b47e45ccfed..554fb607b15f3 100644 --- a/src/test/run-pass/classes-cross-crate.rs +++ b/src/test/run-pass/classes-cross-crate.rs @@ -13,7 +13,7 @@ extern crate cci_class_4; use cci_class_4::kitties::cat; pub fn main() { - let mut nyan = cat(0u, 2, "nyan".to_owned()); + let mut nyan = cat(0u, 2, "nyan".to_strbuf()); nyan.eat(); assert!((!nyan.eat())); for _ in range(1u, 10u) { nyan.speak(); }; diff --git a/src/test/run-pass/classes.rs b/src/test/run-pass/classes.rs index d54a29cde064e..33360df56e94a 100644 --- a/src/test/run-pass/classes.rs +++ b/src/test/run-pass/classes.rs @@ -12,7 +12,7 @@ struct cat { meows : uint, how_hungry : int, - name : ~str, + name : StrBuf, } impl cat { @@ -40,7 +40,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, @@ -49,7 +49,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { } pub fn main() { - let mut nyan = cat(0u, 2, "nyan".to_owned()); + let mut nyan = cat(0u, 2, "nyan".to_strbuf()); nyan.eat(); assert!((!nyan.eat())); for _ in range(1u, 10u) { nyan.speak(); }; diff --git a/src/test/run-pass/closure-reform.rs b/src/test/run-pass/closure-reform.rs index 202ec7edb1939..47ca20b6ee824 100644 --- a/src/test/run-pass/closure-reform.rs +++ b/src/test/run-pass/closure-reform.rs @@ -14,8 +14,8 @@ use std::mem; use std::io::stdio::println; -fn call_it(f: proc(~str) -> ~str) { - println!("{}", f("Fred".to_owned())) +fn call_it(f: proc(StrBuf) -> StrBuf) { + println!("{}", f("Fred".to_strbuf())) } fn call_a_thunk(f: ||) { @@ -48,17 +48,17 @@ fn call_bare_again(f: extern "Rust" fn(&str)) { pub fn main() { // Procs - let greeting = "Hello ".to_owned(); + let greeting = "Hello ".to_strbuf(); call_it(proc(s) { - greeting + s + format_strbuf!("{}{}", greeting, s) }); - let greeting = "Goodbye ".to_owned(); - call_it(proc(s) greeting + s); + let greeting = "Goodbye ".to_strbuf(); + call_it(proc(s) format_strbuf!("{}{}", greeting, s)); - let greeting = "How's life, ".to_owned(); - call_it(proc(s: ~str) -> ~str { - greeting + s + let greeting = "How's life, ".to_strbuf(); + call_it(proc(s: StrBuf) -> StrBuf { + format_strbuf!("{}{}", greeting, s) }); // Closures diff --git a/src/test/run-pass/complex.rs b/src/test/run-pass/complex.rs index 3ade33b43750d..0d06ff9610c9d 100644 --- a/src/test/run-pass/complex.rs +++ b/src/test/run-pass/complex.rs @@ -15,18 +15,18 @@ type t = int; fn nothing() { } -fn putstr(_s: ~str) { } +fn putstr(_s: StrBuf) { } fn putint(_i: int) { let mut i: int = 33; - while i < 36 { putstr("hi".to_owned()); i = i + 1; } + while i < 36 { putstr("hi".to_strbuf()); i = i + 1; } } fn zerg(i: int) -> int { return i; } fn foo(x: int) -> int { let mut y: t = x + 2; - putstr("hello".to_owned()); + putstr("hello".to_strbuf()); while y < 10 { putint(y); if y * 3 == 4 { y = y + 2; nothing(); } } let mut z: t; z = 0x55; diff --git a/src/test/run-pass/conditional-compile.rs b/src/test/run-pass/conditional-compile.rs index ebb495de88b8f..19ed116cc5c21 100644 --- a/src/test/run-pass/conditional-compile.rs +++ b/src/test/run-pass/conditional-compile.rs @@ -108,8 +108,8 @@ mod test_foreign_items { pub mod rustrt { extern { #[cfg(bogus)] - pub fn write() -> ~str; - pub fn write() -> ~str; + pub fn write() -> StrBuf; + pub fn write() -> StrBuf; } } } diff --git a/src/test/run-pass/const-enum-structlike.rs b/src/test/run-pass/const-enum-structlike.rs index 56cfcfae7a6f2..712b3344210c3 100644 --- a/src/test/run-pass/const-enum-structlike.rs +++ b/src/test/run-pass/const-enum-structlike.rs @@ -11,7 +11,7 @@ #![feature(struct_variant)] enum E { - S0 { s: ~str }, + S0 { s: StrBuf }, S1 { u: uint } } diff --git a/src/test/run-pass/crate-method-reexport-grrrrrrr.rs b/src/test/run-pass/crate-method-reexport-grrrrrrr.rs index 82b33d02214ae..56f6871ed54c3 100644 --- a/src/test/run-pass/crate-method-reexport-grrrrrrr.rs +++ b/src/test/run-pass/crate-method-reexport-grrrrrrr.rs @@ -24,5 +24,5 @@ pub fn main() { let x = @(); x.cx(); let y = (); - y.add("hi".to_owned()); + y.add("hi".to_strbuf()); } diff --git a/src/test/run-pass/deriving-hash.rs b/src/test/run-pass/deriving-hash.rs index ce24fa7160704..5b61b095fb67d 100644 --- a/src/test/run-pass/deriving-hash.rs +++ b/src/test/run-pass/deriving-hash.rs @@ -15,13 +15,21 @@ use std::hash::Hash; #[deriving(Hash)] struct Person { id: uint, - name: ~str, + name: StrBuf, phone: uint, } fn main() { - let person1 = Person { id: 5, name: "Janet".to_owned(), phone: 555_666_7777 }; - let person2 = Person { id: 5, name: "Bob".to_owned(), phone: 555_666_7777 }; + let person1 = Person { + id: 5, + name: "Janet".to_strbuf(), + phone: 555_666_7777 + }; + let person2 = Person { + id: 5, + name: "Bob".to_strbuf(), + phone: 555_666_7777 + }; assert!(hash::hash(&person1) == hash::hash(&person1)); assert!(hash::hash(&person1) != hash::hash(&person2)); } diff --git a/src/test/run-pass/deriving-show-2.rs b/src/test/run-pass/deriving-show-2.rs index 9811caacda00c..59ab75ddaaf19 100644 --- a/src/test/run-pass/deriving-show-2.rs +++ b/src/test/run-pass/deriving-show-2.rs @@ -17,7 +17,7 @@ enum A {} #[deriving(Show)] enum B { B1, B2, B3 } #[deriving(Show)] -enum C { C1(int), C2(B), C3(~str) } +enum C { C1(int), C2(B), C3(StrBuf) } #[deriving(Show)] enum D { D1{ a: int } } #[deriving(Show)] diff --git a/src/test/run-pass/deriving-via-extension-struct-tuple.rs b/src/test/run-pass/deriving-via-extension-struct-tuple.rs index fc425dd707622..835741ab7e319 100644 --- a/src/test/run-pass/deriving-via-extension-struct-tuple.rs +++ b/src/test/run-pass/deriving-via-extension-struct-tuple.rs @@ -9,12 +9,12 @@ // except according to those terms. #[deriving(Eq, Show)] -struct Foo(int, int, ~str); +struct Foo(int, int, StrBuf); pub fn main() { - let a1 = Foo(5, 6, "abc".to_owned()); - let a2 = Foo(5, 6, "abc".to_owned()); - let b = Foo(5, 7, "def".to_owned()); + let a1 = Foo(5, 6, "abc".to_strbuf()); + let a2 = Foo(5, 6, "abc".to_strbuf()); + let b = Foo(5, 7, "def".to_strbuf()); assert!(a1 == a1); assert!(a2 == a1); diff --git a/src/test/run-pass/drop-on-ret.rs b/src/test/run-pass/drop-on-ret.rs index 0ab0788fcf716..e2d14239598bf 100644 --- a/src/test/run-pass/drop-on-ret.rs +++ b/src/test/run-pass/drop-on-ret.rs @@ -13,7 +13,7 @@ fn f() -> int { if true { - let _s: ~str = "should not leak".to_owned(); + let _s: StrBuf = "should not leak".to_strbuf(); return 1; } return 0; diff --git a/src/test/run-pass/enum-disr-val-pretty.rs b/src/test/run-pass/enum-disr-val-pretty.rs index 5397d5e65e4df..26d2fce3fa8ca 100644 --- a/src/test/run-pass/enum-disr-val-pretty.rs +++ b/src/test/run-pass/enum-disr-val-pretty.rs @@ -13,13 +13,13 @@ enum color { red = 1, green, blue, imaginary = -1, } pub fn main() { - test_color(red, 1, "red".to_owned()); - test_color(green, 2, "green".to_owned()); - test_color(blue, 3, "blue".to_owned()); - test_color(imaginary, -1, "imaginary".to_owned()); + test_color(red, 1, "red".to_strbuf()); + test_color(green, 2, "green".to_strbuf()); + test_color(blue, 3, "blue".to_strbuf()); + test_color(imaginary, -1, "imaginary".to_strbuf()); } -fn test_color(color: color, val: int, _name: ~str) { +fn test_color(color: color, val: int, _name: StrBuf) { assert!(color as int == val); assert!(color as f64 == val as f64); } diff --git a/src/test/run-pass/enum-variants.rs b/src/test/run-pass/enum-variants.rs index 363b44384af05..5327a29733e80 100644 --- a/src/test/run-pass/enum-variants.rs +++ b/src/test/run-pass/enum-variants.rs @@ -13,13 +13,13 @@ #![feature(struct_variant)] enum Animal { - Dog (~str, f64), - Cat { name: ~str, weight: f64 } + Dog (StrBuf, f64), + Cat { name: StrBuf, weight: f64 } } pub fn main() { - let mut a: Animal = Dog("Cocoa".to_owned(), 37.2); - a = Cat{ name: "Spotty".to_owned(), weight: 2.7 }; + let mut a: Animal = Dog("Cocoa".to_strbuf(), 37.2); + a = Cat{ name: "Spotty".to_strbuf(), weight: 2.7 }; // permuting the fields should work too - let _c = Cat { weight: 3.1, name: "Spreckles".to_owned() }; + let _c = Cat { weight: 3.1, name: "Spreckles".to_strbuf() }; } diff --git a/src/test/run-pass/estr-uniq.rs b/src/test/run-pass/estr-uniq.rs index e879453f7c981..85a796a686b35 100644 --- a/src/test/run-pass/estr-uniq.rs +++ b/src/test/run-pass/estr-uniq.rs @@ -11,10 +11,10 @@ #![allow(dead_assignment)] pub fn main() { - let x : ~str = "hello".to_owned(); - let _y : ~str = "there".to_owned(); - let mut z = "thing".to_owned(); + let x : StrBuf = "hello".to_strbuf(); + let _y : StrBuf = "there".to_strbuf(); + let mut z = "thing".to_strbuf(); z = x; - assert_eq!(z[0], ('h' as u8)); - assert_eq!(z[4], ('o' as u8)); + assert_eq!(z.as_slice()[0], ('h' as u8)); + assert_eq!(z.as_slice()[4], ('o' as u8)); } diff --git a/src/test/run-pass/explicit_self_xcrate_exe.rs b/src/test/run-pass/explicit_self_xcrate_exe.rs index f536b055c6c5d..4e6b038f8ed4a 100644 --- a/src/test/run-pass/explicit_self_xcrate_exe.rs +++ b/src/test/run-pass/explicit_self_xcrate_exe.rs @@ -14,6 +14,6 @@ extern crate explicit_self_xcrate; use explicit_self_xcrate::{Foo, Bar}; pub fn main() { - let x = Bar { x: "hello".to_owned() }; + let x = Bar { x: "hello".to_strbuf() }; x.f(); } diff --git a/src/test/run-pass/foreign-fn-linkname.rs b/src/test/run-pass/foreign-fn-linkname.rs index 76902470c06e2..d57031c81e784 100644 --- a/src/test/run-pass/foreign-fn-linkname.rs +++ b/src/test/run-pass/foreign-fn-linkname.rs @@ -22,9 +22,9 @@ mod mlibc { } } -fn strlen(str: ~str) -> uint { +fn strlen(str: StrBuf) -> uint { // C string is terminated with a zero - str.with_c_str(|buf| { + str.as_slice().with_c_str(|buf| { unsafe { mlibc::my_strlen(buf) as uint } @@ -32,6 +32,6 @@ fn strlen(str: ~str) -> uint { } pub fn main() { - let len = strlen("Rust".to_owned()); + let len = strlen("Rust".to_strbuf()); assert_eq!(len, 4u); } diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 32ce8e6f54225..33a538098562f 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -20,20 +20,22 @@ extern crate collections; This originally came from the word-count benchmark. */ -pub fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, "1".to_owned()); } +pub fn map(filename: StrBuf, emit: map_reduce::putter) { + emit(filename, "1".to_strbuf()); +} mod map_reduce { use collections::HashMap; use std::str; use std::task; - pub type putter<'a> = |~str, ~str|: 'a; + pub type putter<'a> = |StrBuf, StrBuf|: 'a; - pub type mapper = extern fn(~str, putter); + pub type mapper = extern fn(StrBuf, putter); enum ctrl_proto { find_reducer(Vec, Sender), mapper_done, } - fn start_mappers(ctrl: Sender, inputs: Vec<~str>) { + fn start_mappers(ctrl: Sender, inputs: Vec) { for i in inputs.iter() { let ctrl = ctrl.clone(); let i = i.clone(); @@ -41,12 +43,12 @@ mod map_reduce { } } - fn map_task(ctrl: Sender, input: ~str) { + fn map_task(ctrl: Sender, input: StrBuf) { let mut intermediates = HashMap::new(); - fn emit(im: &mut HashMap<~str, int>, - ctrl: Sender, key: ~str, - _val: ~str) { + fn emit(im: &mut HashMap, + ctrl: Sender, key: StrBuf, + _val: StrBuf) { if im.contains_key(&key) { return; } @@ -64,13 +66,13 @@ mod map_reduce { ctrl_clone.send(mapper_done); } - pub fn map_reduce(inputs: Vec<~str>) { + pub fn map_reduce(inputs: Vec) { let (tx, rx) = channel(); // This task becomes the master control task. It spawns others // to do the rest. - let mut reducers: HashMap<~str, int>; + let mut reducers: HashMap; reducers = HashMap::new(); @@ -83,8 +85,8 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(&str::from_utf8(k.as_slice()).unwrap() - .to_owned()) { + match reducers.find(&str::from_utf8( + k.as_slice()).unwrap().to_strbuf()) { Some(&_c) => { c = _c; } None => { c = 0; } } @@ -96,5 +98,6 @@ mod map_reduce { } pub fn main() { - map_reduce::map_reduce(vec!("../src/test/run-pass/hashmap-memory.rs".to_owned())); + map_reduce::map_reduce( + vec!("../src/test/run-pass/hashmap-memory.rs".to_strbuf())); } diff --git a/src/test/run-pass/html-literals.rs b/src/test/run-pass/html-literals.rs index ebecfb2c78ac2..13211e0d3d134 100644 --- a/src/test/run-pass/html-literals.rs +++ b/src/test/run-pass/html-literals.rs @@ -41,7 +41,7 @@ macro_rules! parse_node ( ) => ( parse_node!( [$(: $tags ($(:$tag_nodes),*))*]; - [$(:$head_nodes,)* :tag(stringify!($head).to_owned(), + [$(:$head_nodes,)* :tag(stringify!($head).to_strbuf(), vec!($($nodes),*))]; $($rest)* ) @@ -66,7 +66,7 @@ macro_rules! parse_node ( ) => ( parse_node!( [$(: $tags ($(:$tag_nodes),*))*]; - [$(:$nodes,)* :text(".".to_owned())]; + [$(:$nodes,)* :text(".".to_strbuf())]; $($rest)* ) ); @@ -78,7 +78,7 @@ macro_rules! parse_node ( ) => ( parse_node!( [$(: $tags ($(:$tag_nodes),*))*]; - [$(:$nodes,)* :text(stringify!($word).to_owned())]; + [$(:$nodes,)* :text(stringify!($word).to_strbuf())]; $($rest)* ) ); @@ -98,6 +98,6 @@ pub fn main() { } enum HTMLFragment { - tag(~str, Vec ), - text(~str), + tag(StrBuf, Vec ), + text(StrBuf), } diff --git a/src/test/run-pass/issue-10228.rs b/src/test/run-pass/issue-10228.rs index 7059087685637..ce02f16634f21 100644 --- a/src/test/run-pass/issue-10228.rs +++ b/src/test/run-pass/issue-10228.rs @@ -13,7 +13,7 @@ enum StdioContainer { } struct Test<'a> { - args: &'a [~str], + args: &'a [StrBuf], io: &'a [StdioContainer] } diff --git a/src/test/run-pass/issue-13304.rs b/src/test/run-pass/issue-13304.rs index fc1825d22cd94..36db5a64555b5 100644 --- a/src/test/run-pass/issue-13304.rs +++ b/src/test/run-pass/issue-13304.rs @@ -35,22 +35,25 @@ fn main() { rx.recv(); } } else { - parent("green".to_owned()); - parent("native".to_owned()); + parent("green".to_strbuf()); + parent("native".to_strbuf()); let (tx, rx) = channel(); native::task::spawn(proc() { - parent("green".to_owned()); - parent("native".to_owned()); + parent("green".to_strbuf()); + parent("native".to_strbuf()); tx.send(()); }); rx.recv(); } } -fn parent(flavor: ~str) { +fn parent(flavor: StrBuf) { let args = os::args(); let args = args.as_slice(); - let mut p = io::Process::new(args[0].as_slice(), ["child".to_owned(), flavor]).unwrap(); + let mut p = io::Process::new(args[0].as_slice(), [ + "child".to_owned(), + flavor.to_owned() + ]).unwrap(); p.stdin.get_mut_ref().write_str("test1\ntest2\ntest3").unwrap(); let out = p.wait_with_output().unwrap(); assert!(out.status.success()); diff --git a/src/test/run-pass/issue-1701.rs b/src/test/run-pass/issue-1701.rs index 965b875a9e61c..cef46d56b7dd5 100644 --- a/src/test/run-pass/issue-1701.rs +++ b/src/test/run-pass/issue-1701.rs @@ -10,22 +10,22 @@ enum pattern { tabby, tortoiseshell, calico } enum breed { beagle, rottweiler, pug } -type name = ~str; +type name = StrBuf; enum ear_kind { lop, upright } enum animal { cat(pattern), dog(breed), rabbit(name, ear_kind), tiger } -fn noise(a: animal) -> Option<~str> { +fn noise(a: animal) -> Option { match a { - cat(..) => { Some("meow".to_owned()) } - dog(..) => { Some("woof".to_owned()) } + cat(..) => { Some("meow".to_strbuf()) } + dog(..) => { Some("woof".to_strbuf()) } rabbit(..) => { None } - tiger(..) => { Some("roar".to_owned()) } + tiger(..) => { Some("roar".to_strbuf()) } } } pub fn main() { - assert_eq!(noise(cat(tabby)), Some("meow".to_owned())); - assert_eq!(noise(dog(pug)), Some("woof".to_owned())); - assert_eq!(noise(rabbit("Hilbert".to_owned(), upright)), None); - assert_eq!(noise(tiger), Some("roar".to_owned())); + assert_eq!(noise(cat(tabby)), Some("meow".to_strbuf())); + assert_eq!(noise(dog(pug)), Some("woof".to_strbuf())); + assert_eq!(noise(rabbit("Hilbert".to_strbuf(), upright)), None); + assert_eq!(noise(tiger), Some("roar".to_strbuf())); } diff --git a/src/test/run-pass/issue-2631-b.rs b/src/test/run-pass/issue-2631-b.rs index ce67b4c3fda7e..8216e34113594 100644 --- a/src/test/run-pass/issue-2631-b.rs +++ b/src/test/run-pass/issue-2631-b.rs @@ -20,8 +20,8 @@ use std::cell::RefCell; use collections::HashMap; pub fn main() { - let v = vec!(@"hi".to_owned()); + let v = vec!(@"hi".to_strbuf()); let mut m: req::header_map = HashMap::new(); - m.insert("METHOD".to_owned(), @RefCell::new(v)); + m.insert("METHOD".to_strbuf(), @RefCell::new(v)); request::(&m); } diff --git a/src/test/run-pass/issue-2804-2.rs b/src/test/run-pass/issue-2804-2.rs index 597a709201f1f..57eb0df560f81 100644 --- a/src/test/run-pass/issue-2804-2.rs +++ b/src/test/run-pass/issue-2804-2.rs @@ -16,8 +16,8 @@ extern crate collections; use collections::HashMap; -fn add_interfaces(managed_ip: ~str, device: HashMap<~str, int>) { - println!("{}, {:?}", managed_ip, device.get(&"interfaces".to_owned())); +fn add_interfaces(managed_ip: StrBuf, device: HashMap) { + println!("{}, {:?}", managed_ip, device.get(&"interfaces".to_strbuf())); } pub fn main() {} diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index dfd34fcf5918c..9405c62a184c6 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -21,11 +21,11 @@ enum object { int_value(i64), } -fn lookup(table: Box, key: ~str, default: ~str) -> ~str +fn lookup(table: Box, key: StrBuf, default: StrBuf) -> StrBuf { - match table.find(&key) { + match table.find(&key.to_owned()) { option::Some(&json::String(ref s)) => { - (*s).clone() + (*s).to_strbuf() } option::Some(value) => { println!("{} was expected to be a string but is a {:?}", key, value); @@ -37,25 +37,27 @@ fn lookup(table: Box, key: ~str, default: ~str) -> ~str } } -fn add_interface(_store: int, managed_ip: ~str, data: json::Json) -> (~str, object) +fn add_interface(_store: int, managed_ip: StrBuf, data: json::Json) -> (StrBuf, object) { match &data { &json::Object(ref interface) => { - let name = lookup((*interface).clone(), "ifDescr".to_owned(), "".to_owned()); - let label = format!("{}-{}", managed_ip, name); + let name = lookup((*interface).clone(), + "ifDescr".to_strbuf(), + "".to_strbuf()); + let label = format_strbuf!("{}-{}", managed_ip, name); (label, bool_value(false)) } _ => { println!("Expected dict for {} interfaces but found {:?}", managed_ip, data); - ("gnos:missing-interface".to_owned(), bool_value(true)) + ("gnos:missing-interface".to_strbuf(), bool_value(true)) } } } -fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, json::Json>) --> Vec<(~str, object)> { - match device.get(&"interfaces".to_owned()) +fn add_interfaces(store: int, managed_ip: StrBuf, device: HashMap) +-> Vec<(StrBuf, object)> { + match device.get(&"interfaces".to_strbuf()) { &json::List(ref interfaces) => { @@ -66,7 +68,7 @@ fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, json::Json _ => { println!("Expected list for {} interfaces but found {:?}", managed_ip, - device.get(&"interfaces".to_owned())); + device.get(&"interfaces".to_strbuf())); Vec::new() } } diff --git a/src/test/run-pass/issue-3037.rs b/src/test/run-pass/issue-3037.rs index ef403a6c9cb21..0a6482c26b9fa 100644 --- a/src/test/run-pass/issue-3037.rs +++ b/src/test/run-pass/issue-3037.rs @@ -10,7 +10,7 @@ enum what { } -fn what_to_str(x: what) -> ~str +fn what_to_str(x: what) -> StrBuf { match x { } diff --git a/src/test/run-pass/issue-3389.rs b/src/test/run-pass/issue-3389.rs index 404b066ac10be..5eefd5ef08abe 100644 --- a/src/test/run-pass/issue-3389.rs +++ b/src/test/run-pass/issue-3389.rs @@ -10,11 +10,11 @@ struct trie_node { - content: Vec<~str> , + content: Vec , children: Vec , } -fn print_str_vector(vector: Vec<~str> ) { +fn print_str_vector(vector: Vec ) { for string in vector.iter() { println!("{}", *string); } @@ -25,8 +25,8 @@ pub fn main() { content: Vec::new(), children: Vec::new() }; - let v = vec!("123".to_owned(), "abc".to_owned()); - node.content = vec!("123".to_owned(), "abc".to_owned()); + let v = vec!("123".to_strbuf(), "abc".to_strbuf()); + node.content = vec!("123".to_strbuf(), "abc".to_strbuf()); print_str_vector(v); print_str_vector(node.content.clone()); diff --git a/src/test/run-pass/issue-3424.rs b/src/test/run-pass/issue-3424.rs index 5a27009d0587c..6423ab1cb6402 100644 --- a/src/test/run-pass/issue-3424.rs +++ b/src/test/run-pass/issue-3424.rs @@ -15,11 +15,13 @@ use std::path::{Path}; use std::path; use std::result; -type rsrc_loader = proc(path: &Path) -> result::Result<~str, ~str>; +type rsrc_loader = proc(path: &Path) -> result::Result; fn tester() { - let loader: rsrc_loader = proc(_path) {result::Ok("more blah".to_owned())}; + let loader: rsrc_loader = proc(_path) { + result::Ok("more blah".to_strbuf()) + }; let path = path::Path::new("blah"); assert!(loader(&path).is_ok()); diff --git a/src/test/run-pass/issue-3556.rs b/src/test/run-pass/issue-3556.rs index abc21901a0366..910f7c328a700 100644 --- a/src/test/run-pass/issue-3556.rs +++ b/src/test/run-pass/issue-3556.rs @@ -11,12 +11,12 @@ #![feature(managed_boxes)] enum Token { - Text(@~str), - ETag(@Vec<~str> , @~str), - UTag(@Vec<~str> , @~str), - Section(@Vec<~str> , bool, @Vec , @~str, @~str, @~str, @~str, @~str), - IncompleteSection(@Vec<~str> , bool, @~str, bool), - Partial(@~str, @~str, @~str), + Text(@StrBuf), + ETag(@Vec , @StrBuf), + UTag(@Vec , @StrBuf), + Section(@Vec , bool, @Vec , @StrBuf, @StrBuf, @StrBuf, @StrBuf, @StrBuf), + IncompleteSection(@Vec , bool, @StrBuf, bool), + Partial(@StrBuf, @StrBuf, @StrBuf), } fn check_strs(actual: &str, expected: &str) -> bool @@ -35,10 +35,13 @@ pub fn main() // assert!(check_strs(fmt!("%?", ETag(@~["foo".to_owned()], @"bar".to_owned())), // "ETag(@~[ ~\"foo\" ], @~\"bar\")")); - let t = Text(@"foo".to_owned()); - let u = Section(@vec!("alpha".to_owned()), true, @vec!(t), @"foo".to_owned(), - @"foo".to_owned(), @"foo".to_owned(), @"foo".to_owned(), - @"foo".to_owned()); + let t = Text(@"foo".to_strbuf()); + let u = Section(@vec!("alpha".to_strbuf()), + true, + @vec!(t), + @"foo".to_strbuf(), + @"foo".to_strbuf(), @"foo".to_strbuf(), @"foo".to_strbuf(), + @"foo".to_strbuf()); let v = format!("{:?}", u); // this is the line that causes the seg fault assert!(v.len() > 0); } diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index 8529947245846..ac2ce615fee40 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -100,8 +100,10 @@ impl fmt::Show for AsciiArt { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Convert each line into a string. let lines = self.lines.iter() - .map(|line| str::from_chars(line.as_slice())) - .collect::>(); + .map(|line| { + str::from_chars(line.as_slice()).to_strbuf() + }) + .collect::>(); // Concatenate the lines together using a new-line. write!(f.buf, "{}", lines.connect("\n")) diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index 95bbf77024c8f..f1fd83b179f40 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -15,10 +15,10 @@ type SamplesFn = proc(samples: &RingBuffer):Send; enum Msg { - GetSamples(~str, SamplesFn), // sample set name, callback which receives samples + GetSamples(StrBuf, SamplesFn), // sample set name, callback which receives samples } -fn foo(name: ~str, samples_chan: Sender) { +fn foo(name: StrBuf, samples_chan: Sender) { task::spawn(proc() { let mut samples_chan = samples_chan; let callback: SamplesFn = proc(buffer) { diff --git a/src/test/run-pass/issue-3702.rs b/src/test/run-pass/issue-3702.rs index 84414461e96c9..9ee34d58c371c 100644 --- a/src/test/run-pass/issue-3702.rs +++ b/src/test/run-pass/issue-3702.rs @@ -11,7 +11,7 @@ pub fn main() { trait Text { - fn to_str(&self) -> ~str; + fn to_str(&self) -> StrBuf; } fn to_string(t: Box) { diff --git a/src/test/run-pass/issue-3935.rs b/src/test/run-pass/issue-3935.rs index 36a5396e6cfaa..ef24a8cd9d15f 100644 --- a/src/test/run-pass/issue-3935.rs +++ b/src/test/run-pass/issue-3935.rs @@ -10,12 +10,12 @@ #[deriving(Eq)] struct Bike { - name: ~str, + name: StrBuf, } pub fn main() { - let town_bike = Bike { name: "schwinn".to_owned() }; - let my_bike = Bike { name: "surly".to_owned() }; + let town_bike = Bike { name: "schwinn".to_strbuf() }; + let my_bike = Bike { name: "surly".to_strbuf() }; assert!(town_bike != my_bike); } diff --git a/src/test/run-pass/issue-4241.rs b/src/test/run-pass/issue-4241.rs index f3e37921ba420..0f7219d7901fa 100644 --- a/src/test/run-pass/issue-4241.rs +++ b/src/test/run-pass/issue-4241.rs @@ -24,8 +24,8 @@ enum Result { Int(int), Data(~[u8]), List(~[Result]), - Error(~str), - Status(~str) + Error(StrBuf), + Status(StrBuf) } priv fn parse_data(len: uint, io: @io::Reader) -> Result { @@ -55,7 +55,7 @@ priv fn parse_list(len: uint, io: @io::Reader) -> Result { return List(list); } -priv fn chop(s: ~str) -> ~str { +priv fn chop(s: StrBuf) -> StrBuf { s.slice(0, s.len() - 1).to_owned() } @@ -96,7 +96,7 @@ priv fn parse_response(io: @io::Reader) -> Result { } } -priv fn cmd_to_str(cmd: ~[~str]) -> ~str { +priv fn cmd_to_str(cmd: ~[StrBuf]) -> StrBuf { let mut res = "*".to_owned(); res.push_str(cmd.len().to_str()); res.push_str("\r\n"); @@ -107,7 +107,7 @@ priv fn cmd_to_str(cmd: ~[~str]) -> ~str { res } -fn query(cmd: ~[~str], sb: TcpSocketBuf) -> Result { +fn query(cmd: ~[StrBuf], sb: TcpSocketBuf) -> Result { let cmd = cmd_to_str(cmd); //println!("{}", cmd); sb.write_str(cmd); @@ -115,7 +115,7 @@ fn query(cmd: ~[~str], sb: TcpSocketBuf) -> Result { res } -fn query2(cmd: ~[~str]) -> Result { +fn query2(cmd: ~[StrBuf]) -> Result { let _cmd = cmd_to_str(cmd); io::with_str_reader("$3\r\nXXX\r\n".to_owned())(|sb| { let res = parse_response(@sb as @io::Reader); diff --git a/src/test/run-pass/issue-4541.rs b/src/test/run-pass/issue-4541.rs index f05b1932b738d..73df5d206d367 100644 --- a/src/test/run-pass/issue-4541.rs +++ b/src/test/run-pass/issue-4541.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn parse_args() -> ~str { +fn parse_args() -> StrBuf { let args = ::std::os::args(); let args = args.as_slice(); let mut n = 0; @@ -17,13 +17,13 @@ fn parse_args() -> ~str { match args[n].as_slice() { "-v" => (), s => { - return s.into_owned(); + return s.to_strbuf(); } } n += 1; } - return "".to_owned() + return "".to_strbuf() } pub fn main() { diff --git a/src/test/run-pass/issue-5008-borrowed-traitobject-method-call.rs b/src/test/run-pass/issue-5008-borrowed-traitobject-method-call.rs index 08676495e318b..57cae2fdf7166 100644 --- a/src/test/run-pass/issue-5008-borrowed-traitobject-method-call.rs +++ b/src/test/run-pass/issue-5008-borrowed-traitobject-method-call.rs @@ -16,20 +16,20 @@ It fixes itself if the &Trait is changed to @Trait. */ trait Debuggable { - fn debug_name(&self) -> ~str; + fn debug_name(&self) -> StrBuf; } #[deriving(Clone)] struct Thing { -name: ~str, + name: StrBuf, } impl Thing { - fn new() -> Thing { Thing { name: "dummy".to_owned() } } + fn new() -> Thing { Thing { name: "dummy".to_strbuf() } } } impl Debuggable for Thing { - fn debug_name(&self) -> ~str { self.name.clone() } + fn debug_name(&self) -> StrBuf { self.name.clone() } } fn print_name(x: &Debuggable) diff --git a/src/test/run-pass/issue-5353.rs b/src/test/run-pass/issue-5353.rs index 845d1a18c2a28..ade2815fd2df8 100644 --- a/src/test/run-pass/issue-5353.rs +++ b/src/test/run-pass/issue-5353.rs @@ -11,13 +11,13 @@ static INVALID_ENUM : u32 = 0; static INVALID_VALUE : u32 = 1; -fn gl_err_str(err: u32) -> ~str +fn gl_err_str(err: u32) -> StrBuf { match err { - INVALID_ENUM => { "Invalid enum".to_owned() }, - INVALID_VALUE => { "Invalid value".to_owned() }, - _ => { "Unknown error".to_owned() } + INVALID_ENUM => { "Invalid enum".to_strbuf() }, + INVALID_VALUE => { "Invalid value".to_strbuf() }, + _ => { "Unknown error".to_strbuf() } } } diff --git a/src/test/run-pass/issue-5550.rs b/src/test/run-pass/issue-5550.rs index b3d22ab1a376f..d4962784b9ace 100644 --- a/src/test/run-pass/issue-5550.rs +++ b/src/test/run-pass/issue-5550.rs @@ -11,7 +11,7 @@ #![allow(dead_assignment)] pub fn main() { - let s: ~str = "foobar".to_owned(); - let mut t: &str = s; + let s: StrBuf = "foobar".to_strbuf(); + let mut t: &str = s.as_slice(); t = t.slice(0, 3); // for master: str::view(t, 0, 3) maybe } diff --git a/src/test/run-pass/issue-5666.rs b/src/test/run-pass/issue-5666.rs index a3dc1fae7f184..2238c30f6e8cf 100644 --- a/src/test/run-pass/issue-5666.rs +++ b/src/test/run-pass/issue-5666.rs @@ -10,23 +10,23 @@ struct Dog { - name : ~str + name : StrBuf } trait Barks { - fn bark(&self) -> ~str; + fn bark(&self) -> StrBuf; } impl Barks for Dog { - fn bark(&self) -> ~str { - return format!("woof! (I'm {})", self.name); + fn bark(&self) -> StrBuf { + return format!("woof! (I'm {})", self.name).to_strbuf(); } } pub fn main() { - let snoopy = box Dog{name: "snoopy".to_owned()}; - let bubbles = box Dog{name: "bubbles".to_owned()}; + let snoopy = box Dog{name: "snoopy".to_strbuf()}; + let bubbles = box Dog{name: "bubbles".to_strbuf()}; let barker = [snoopy as Box, bubbles as Box]; for pup in barker.iter() { diff --git a/src/test/run-pass/issue-8506.rs b/src/test/run-pass/issue-8506.rs index 1c3e0f367078e..ecf066d86bce2 100644 --- a/src/test/run-pass/issue-8506.rs +++ b/src/test/run-pass/issue-8506.rs @@ -12,7 +12,7 @@ enum Either { One, - Other(~str,~str) + Other(StrBuf,StrBuf) } static one : Either = One; diff --git a/src/test/run-pass/issue-8578.rs b/src/test/run-pass/issue-8578.rs index fcc9278b4c5cc..383eede5c14af 100644 --- a/src/test/run-pass/issue-8578.rs +++ b/src/test/run-pass/issue-8578.rs @@ -9,7 +9,7 @@ // except according to those terms. pub struct UninterpretedOption_NamePart { - name_part: Option<~str>, + name_part: Option, } impl<'a> UninterpretedOption_NamePart { diff --git a/src/test/run-pass/issue-8898.rs b/src/test/run-pass/issue-8898.rs index 54e0c30c1d21f..77edc07ace0d6 100644 --- a/src/test/run-pass/issue-8898.rs +++ b/src/test/run-pass/issue-8898.rs @@ -10,8 +10,8 @@ #![feature(managed_boxes)] -fn assert_repr_eq(obj : T, expected : ~str) { - assert_eq!(expected, format!("{:?}", obj)); +fn assert_repr_eq(obj : T, expected : StrBuf) { + assert_eq!(expected, format_strbuf!("{:?}", obj)); } pub fn main() { @@ -21,10 +21,10 @@ pub fn main() { let slice = x.slice(0,1); let z = @x; - assert_repr_eq(abc, "[1, 2, 3]".to_owned()); - assert_repr_eq(tf, "[true, false]".to_owned()); - assert_repr_eq(x, "[(), ()]".to_owned()); - assert_repr_eq(slice, "&[()]".to_owned()); - assert_repr_eq(&x, "&[(), ()]".to_owned()); - assert_repr_eq(z, "@[(), ()]".to_owned()); + assert_repr_eq(abc, "[1, 2, 3]".to_strbuf()); + assert_repr_eq(tf, "[true, false]".to_strbuf()); + assert_repr_eq(x, "[(), ()]".to_strbuf()); + assert_repr_eq(slice, "&[()]".to_strbuf()); + assert_repr_eq(&x, "&[(), ()]".to_strbuf()); + assert_repr_eq(z, "@[(), ()]".to_strbuf()); } diff --git a/src/test/run-pass/issue-9047.rs b/src/test/run-pass/issue-9047.rs index 70b6eec83afa6..0cdceb2351746 100644 --- a/src/test/run-pass/issue-9047.rs +++ b/src/test/run-pass/issue-9047.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn decode() -> ~str { +fn decode() -> StrBuf { 'outer: loop { let mut ch_start: uint; break 'outer; } - "".to_owned() + "".to_strbuf() } pub fn main() { diff --git a/src/test/run-pass/issue-9259.rs b/src/test/run-pass/issue-9259.rs index b03213272cb16..8cdd5d31002a0 100644 --- a/src/test/run-pass/issue-9259.rs +++ b/src/test/run-pass/issue-9259.rs @@ -9,14 +9,14 @@ // except according to those terms. struct A<'a> { - a: &'a [~str], - b: Option<&'a [~str]>, + a: &'a [StrBuf], + b: Option<&'a [StrBuf]>, } pub fn main() { - let b = &["foo".to_owned()]; + let b = &["foo".to_strbuf()]; let a = A { - a: &["test".to_owned()], + a: &["test".to_strbuf()], b: Some(b), }; assert_eq!(a.b.get_ref()[0].as_slice(), "foo"); diff --git a/src/test/run-pass/issue-9394-inherited-trait-calls.rs b/src/test/run-pass/issue-9394-inherited-trait-calls.rs index af8be3a7f11c7..cd9154f27489d 100644 --- a/src/test/run-pass/issue-9394-inherited-trait-calls.rs +++ b/src/test/run-pass/issue-9394-inherited-trait-calls.rs @@ -9,62 +9,62 @@ // except according to those terms. trait Base: Base2 + Base3{ - fn foo(&self) -> ~str; - fn foo1(&self) -> ~str; - fn foo2(&self) -> ~str{ - "base foo2".to_owned() + fn foo(&self) -> StrBuf; + fn foo1(&self) -> StrBuf; + fn foo2(&self) -> StrBuf{ + "base foo2".to_strbuf() } } trait Base2: Base3{ - fn baz(&self) -> ~str; + fn baz(&self) -> StrBuf; } trait Base3{ - fn root(&self) -> ~str; + fn root(&self) -> StrBuf; } trait Super: Base{ - fn bar(&self) -> ~str; + fn bar(&self) -> StrBuf; } struct X; impl Base for X { - fn foo(&self) -> ~str{ - "base foo".to_owned() + fn foo(&self) -> StrBuf{ + "base foo".to_strbuf() } - fn foo1(&self) -> ~str{ - "base foo1".to_owned() + fn foo1(&self) -> StrBuf{ + "base foo1".to_strbuf() } } impl Base2 for X { - fn baz(&self) -> ~str{ - "base2 baz".to_owned() + fn baz(&self) -> StrBuf{ + "base2 baz".to_strbuf() } } impl Base3 for X { - fn root(&self) -> ~str{ - "base3 root".to_owned() + fn root(&self) -> StrBuf{ + "base3 root".to_strbuf() } } impl Super for X { - fn bar(&self) -> ~str{ - "super bar".to_owned() + fn bar(&self) -> StrBuf{ + "super bar".to_strbuf() } } pub fn main() { let n = X; let s = &n as &Super; - assert_eq!(s.bar(),"super bar".to_owned()); - assert_eq!(s.foo(),"base foo".to_owned()); - assert_eq!(s.foo1(),"base foo1".to_owned()); - assert_eq!(s.foo2(),"base foo2".to_owned()); - assert_eq!(s.baz(),"base2 baz".to_owned()); - assert_eq!(s.root(),"base3 root".to_owned()); + assert_eq!(s.bar(),"super bar".to_strbuf()); + assert_eq!(s.foo(),"base foo".to_strbuf()); + assert_eq!(s.foo1(),"base foo1".to_strbuf()); + assert_eq!(s.foo2(),"base foo2".to_strbuf()); + assert_eq!(s.baz(),"base2 baz".to_strbuf()); + assert_eq!(s.root(),"base3 root".to_strbuf()); } diff --git a/src/test/run-pass/issue-9446.rs b/src/test/run-pass/issue-9446.rs index b4e814e6248f9..319e67b67a154 100644 --- a/src/test/run-pass/issue-9446.rs +++ b/src/test/run-pass/issue-9446.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Wrapper(~str); +struct Wrapper(StrBuf); impl Wrapper { - pub fn new(wrapped: ~str) -> Wrapper { + pub fn new(wrapped: StrBuf) -> Wrapper { Wrapper(wrapped) } @@ -28,12 +28,12 @@ impl Drop for Wrapper { pub fn main() { { // This runs without complaint. - let x = Wrapper::new("Bob".to_owned()); + let x = Wrapper::new("Bob".to_strbuf()); x.say_hi(); } { // This fails to compile, circa 0.8-89-gc635fba. // error: internal compiler error: drop_ty_immediate: non-box ty - Wrapper::new("Bob".to_owned()).say_hi(); + Wrapper::new("Bob".to_strbuf()).say_hi(); } } diff --git a/src/test/run-pass/istr.rs b/src/test/run-pass/istr.rs index 7201ce31bcd5f..e4e7b052cf375 100644 --- a/src/test/run-pass/istr.rs +++ b/src/test/run-pass/istr.rs @@ -11,37 +11,27 @@ use std::strbuf::StrBuf; fn test_stack_assign() { - let s: ~str = "a".to_owned(); + let s: StrBuf = "a".to_strbuf(); println!("{}", s.clone()); - let t: ~str = "a".to_owned(); + let t: StrBuf = "a".to_strbuf(); assert!(s == t); - let u: ~str = "b".to_owned(); + let u: StrBuf = "b".to_strbuf(); assert!((s != u)); } -fn test_heap_lit() { "a big string".to_owned(); } +fn test_heap_lit() { "a big string".to_strbuf(); } fn test_heap_assign() { - let s: ~str = "a big ol' string".to_owned(); - let t: ~str = "a big ol' string".to_owned(); + let s: StrBuf = "a big ol' string".to_strbuf(); + let t: StrBuf = "a big ol' string".to_strbuf(); assert!(s == t); - let u: ~str = "a bad ol' string".to_owned(); + let u: StrBuf = "a bad ol' string".to_strbuf(); assert!((s != u)); } -fn test_heap_log() { let s = "a big ol' string".to_owned(); println!("{}", s); } - -fn test_stack_add() { - assert_eq!("a".to_owned() + "b", "ab".to_owned()); - let s: ~str = "a".to_owned(); - assert_eq!(s + s, "aa".to_owned()); - assert_eq!("".to_owned() + "", "".to_owned()); -} - -fn test_stack_heap_add() { assert!(("a".to_owned() + "bracadabra" == "abracadabra".to_owned())); } - -fn test_heap_add() { - assert_eq!("this should".to_owned() + " totally work", "this should totally work".to_owned()); +fn test_heap_log() { + let s = "a big ol' string".to_strbuf(); + println!("{}", s); } fn test_append() { @@ -67,8 +57,5 @@ pub fn main() { test_heap_lit(); test_heap_assign(); test_heap_log(); - test_stack_add(); - test_stack_heap_add(); - test_heap_add(); test_append(); } diff --git a/src/test/run-pass/last-use-in-block.rs b/src/test/run-pass/last-use-in-block.rs index 8117c5657e989..1eedaed98bc32 100644 --- a/src/test/run-pass/last-use-in-block.rs +++ b/src/test/run-pass/last-use-in-block.rs @@ -10,7 +10,7 @@ // Issue #1818 -fn lp(s: ~str, f: |~str| -> T) -> T { +fn lp(s: StrBuf, f: |StrBuf| -> T) -> T { while false { let r = f(s); return (r); @@ -18,8 +18,8 @@ fn lp(s: ~str, f: |~str| -> T) -> T { fail!(); } -fn apply(s: ~str, f: |~str| -> T) -> T { - fn g(s: ~str, f: |~str| -> T) -> T {f(s)} +fn apply(s: StrBuf, f: |StrBuf| -> T) -> T { + fn g(s: StrBuf, f: |StrBuf| -> T) -> T {f(s)} g(s, |v| { let r = f(v); r }) } diff --git a/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs b/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs index d51ce1538efc7..e9e6ab02e9eb2 100644 --- a/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs +++ b/src/test/run-pass/log-knows-the-names-of-variants-in-std.rs @@ -12,29 +12,23 @@ #[deriving(Clone)] enum foo { a(uint), - b(~str), + b(StrBuf), } -fn check_log(exp: ~str, v: T) { - assert_eq!(exp, format!("{:?}", v)); +fn check_log(exp: StrBuf, v: T) { + assert_eq!(exp, format_strbuf!("{:?}", v)); } pub fn main() { let mut x = Some(a(22u)); - let exp = "Some(a(22u))".to_owned(); - let act = format!("{:?}", x); - assert_eq!(act, exp); - check_log(exp, x); - - x = Some(b("hi".to_owned())); - let exp = "Some(b(~\"hi\"))".to_owned(); - let act = format!("{:?}", x); + let exp = "Some(a(22u))".to_strbuf(); + let act = format_strbuf!("{:?}", x); assert_eq!(act, exp); check_log(exp, x); x = None; - let exp = "None".to_owned(); - let act = format!("{:?}", x); + let exp = "None".to_strbuf(); + let act = format_strbuf!("{:?}", x); assert_eq!(act, exp); check_log(exp, x); } diff --git a/src/test/run-pass/log-knows-the-names-of-variants.rs b/src/test/run-pass/log-knows-the-names-of-variants.rs index 404c227c2e2cf..46bdb5eb7660d 100644 --- a/src/test/run-pass/log-knows-the-names-of-variants.rs +++ b/src/test/run-pass/log-knows-the-names-of-variants.rs @@ -10,7 +10,7 @@ enum foo { a(uint), - b(~str), + b(StrBuf), c, } @@ -19,8 +19,7 @@ enum bar { } pub fn main() { - assert_eq!("a(22u)".to_owned(), format!("{:?}", a(22u))); - assert_eq!("b(~\"hi\")".to_owned(), format!("{:?}", b("hi".to_owned()))); - assert_eq!("c".to_owned(), format!("{:?}", c)); - assert_eq!("d".to_owned(), format!("{:?}", d)); + assert_eq!("a(22u)".to_strbuf(), format_strbuf!("{:?}", a(22u))); + assert_eq!("c".to_strbuf(), format_strbuf!("{:?}", c)); + assert_eq!("d".to_strbuf(), format_strbuf!("{:?}", d)); } diff --git a/src/test/run-pass/match-borrowed_str.rs b/src/test/run-pass/match-borrowed_str.rs index 3bbd33378d0c5..db1db8067a862 100644 --- a/src/test/run-pass/match-borrowed_str.rs +++ b/src/test/run-pass/match-borrowed_str.rs @@ -10,49 +10,49 @@ #![allow(unnecessary_allocation)] -fn f1(ref_string: &str) -> ~str { +fn f1(ref_string: &str) -> StrBuf { match ref_string { - "a" => "found a".to_owned(), - "b" => "found b".to_owned(), - _ => "not found".to_owned() + "a" => "found a".to_strbuf(), + "b" => "found b".to_strbuf(), + _ => "not found".to_strbuf() } } -fn f2(ref_string: &str) -> ~str { +fn f2(ref_string: &str) -> StrBuf { match ref_string { - "a" => "found a".to_owned(), - "b" => "found b".to_owned(), - s => format!("not found ({})", s) + "a" => "found a".to_strbuf(), + "b" => "found b".to_strbuf(), + s => format_strbuf!("not found ({})", s) } } -fn g1(ref_1: &str, ref_2: &str) -> ~str { +fn g1(ref_1: &str, ref_2: &str) -> StrBuf { match (ref_1, ref_2) { - ("a", "b") => "found a,b".to_owned(), - ("b", "c") => "found b,c".to_owned(), - _ => "not found".to_owned() + ("a", "b") => "found a,b".to_strbuf(), + ("b", "c") => "found b,c".to_strbuf(), + _ => "not found".to_strbuf() } } -fn g2(ref_1: &str, ref_2: &str) -> ~str { +fn g2(ref_1: &str, ref_2: &str) -> StrBuf { match (ref_1, ref_2) { - ("a", "b") => "found a,b".to_owned(), - ("b", "c") => "found b,c".to_owned(), - (s1, s2) => format!("not found ({}, {})", s1, s2) + ("a", "b") => "found a,b".to_strbuf(), + ("b", "c") => "found b,c".to_strbuf(), + (s1, s2) => format_strbuf!("not found ({}, {})", s1, s2) } } pub fn main() { - assert_eq!(f1("b".to_owned()), "found b".to_owned()); - assert_eq!(f1("c"), "not found".to_owned()); - assert_eq!(f1("d"), "not found".to_owned()); - assert_eq!(f2("b".to_owned()), "found b".to_owned()); - assert_eq!(f2("c"), "not found (c)".to_owned()); - assert_eq!(f2("d"), "not found (d)".to_owned()); - assert_eq!(g1("b".to_owned(), "c".to_owned()), "found b,c".to_owned()); - assert_eq!(g1("c", "d"), "not found".to_owned()); - assert_eq!(g1("d", "e"), "not found".to_owned()); - assert_eq!(g2("b".to_owned(), "c".to_owned()), "found b,c".to_owned()); - assert_eq!(g2("c", "d"), "not found (c, d)".to_owned()); - assert_eq!(g2("d", "e"), "not found (d, e)".to_owned()); + assert_eq!(f1("b"), "found b".to_strbuf()); + assert_eq!(f1("c"), "not found".to_strbuf()); + assert_eq!(f1("d"), "not found".to_strbuf()); + assert_eq!(f2("b"), "found b".to_strbuf()); + assert_eq!(f2("c"), "not found (c)".to_strbuf()); + assert_eq!(f2("d"), "not found (d)".to_strbuf()); + assert_eq!(g1("b", "c"), "found b,c".to_strbuf()); + assert_eq!(g1("c", "d"), "not found".to_strbuf()); + assert_eq!(g1("d", "e"), "not found".to_strbuf()); + assert_eq!(g2("b", "c"), "found b,c".to_strbuf()); + assert_eq!(g2("c", "d"), "not found (c, d)".to_strbuf()); + assert_eq!(g2("d", "e"), "not found (d, e)".to_strbuf()); } diff --git a/src/test/run-pass/match-str.rs b/src/test/run-pass/match-str.rs index e1ae9a6a73a54..e3060a6b4be67 100644 --- a/src/test/run-pass/match-str.rs +++ b/src/test/run-pass/match-str.rs @@ -13,13 +13,13 @@ pub fn main() { match "test" { "not-test" => fail!(), "test" => (), _ => fail!() } - enum t { tag1(~str), tag2, } + enum t { tag1(StrBuf), tag2, } - match tag1("test".to_owned()) { + match tag1("test".to_strbuf()) { tag2 => fail!(), - tag1(ref s) if "test" != *s => fail!(), - tag1(ref s) if "test" == *s => (), + tag1(ref s) if "test" != s.as_slice() => fail!(), + tag1(ref s) if "test" == s.as_slice() => (), _ => fail!() } diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 1011734a2adf3..8b3cb76817ec4 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -37,15 +37,18 @@ impl option_monad for Option { } } -fn transform(x: Option) -> Option<~str> { - x.bind(|n| Some(*n + 1) ).bind(|n| Some(n.to_str()) ) +fn transform(x: Option) -> Option { + x.bind(|n| Some(*n + 1) ).bind(|n| Some(n.to_str().to_strbuf()) ) } pub fn main() { - assert_eq!(transform(Some(10)), Some("11".to_owned())); + assert_eq!(transform(Some(10)), Some("11".to_strbuf())); assert_eq!(transform(None), None); - assert!((vec!("hi".to_owned())) - .bind(|x| vec!(x.clone(), *x + "!") ) - .bind(|x| vec!(x.clone(), *x + "?") ) == - vec!("hi".to_owned(), "hi?".to_owned(), "hi!".to_owned(), "hi!?".to_owned())); + assert!((vec!("hi".to_strbuf())) + .bind(|x| vec!(x.clone(), format_strbuf!("{}!", x)) ) + .bind(|x| vec!(x.clone(), format_strbuf!("{}?", x)) ) == + vec!("hi".to_strbuf(), + "hi?".to_strbuf(), + "hi!".to_strbuf(), + "hi!?".to_strbuf())); } diff --git a/src/test/run-pass/move-self.rs b/src/test/run-pass/move-self.rs index e31e312f4fb30..276aaa3b63f64 100644 --- a/src/test/run-pass/move-self.rs +++ b/src/test/run-pass/move-self.rs @@ -9,7 +9,7 @@ // except according to those terms. struct S { - x: ~str + x: StrBuf } impl S { @@ -23,6 +23,6 @@ impl S { } pub fn main() { - let x = S { x: "Hello!".to_owned() }; + let x = S { x: "Hello!".to_strbuf() }; x.foo(); } diff --git a/src/test/run-pass/nullable-pointer-iotareduction.rs b/src/test/run-pass/nullable-pointer-iotareduction.rs index 728c0154a90e9..1618f11914bcd 100644 --- a/src/test/run-pass/nullable-pointer-iotareduction.rs +++ b/src/test/run-pass/nullable-pointer-iotareduction.rs @@ -76,7 +76,7 @@ pub fn main() { check_type!(&17: &int); check_type!(box 18: Box); check_type!(@19: @int); - check_type!("foo".to_owned(): ~str); + check_type!("foo".to_strbuf(): StrBuf); check_type!(vec!(20, 22): Vec ); let mint: uint = unsafe { mem::transmute(main) }; check_type!(main: fn(), |pthing| { diff --git a/src/test/run-pass/nullable-pointer-size.rs b/src/test/run-pass/nullable-pointer-size.rs index 0ca8efb3fdc91..2309984a1f11c 100644 --- a/src/test/run-pass/nullable-pointer-size.rs +++ b/src/test/run-pass/nullable-pointer-size.rs @@ -40,6 +40,5 @@ pub fn main() { check_type!(&'static int); check_type!(Box); check_type!(@int); - check_type!(~str); check_type!(extern fn()); } diff --git a/src/test/run-pass/packed-struct-generic-size.rs b/src/test/run-pass/packed-struct-generic-size.rs index b297fc7e13f77..80f37a0fa3d0c 100644 --- a/src/test/run-pass/packed-struct-generic-size.rs +++ b/src/test/run-pass/packed-struct-generic-size.rs @@ -21,7 +21,4 @@ pub fn main() { assert_eq!(mem::size_of::>(), 3); assert_eq!(mem::size_of::>(), 11); - - assert_eq!(mem::size_of:: >>(), - 1 + mem::size_of::<~str>() + mem::size_of:: >()); } diff --git a/src/test/run-pass/packed-struct-size.rs b/src/test/run-pass/packed-struct-size.rs index fc081408229d9..1781f162bc498 100644 --- a/src/test/run-pass/packed-struct-size.rs +++ b/src/test/run-pass/packed-struct-size.rs @@ -25,11 +25,10 @@ struct S5 { } #[packed] -struct S13_str { +struct S13 { a: i64, b: f32, c: u8, - d: ~str } enum Foo { @@ -61,7 +60,7 @@ static TEST_S3_Foo: S3_Foo = S3_Foo { a: 1, b: 2, c: Baz }; pub fn main() { assert_eq!(mem::size_of::(), 4); assert_eq!(mem::size_of::(), 5); - assert_eq!(mem::size_of::(), 13 + mem::size_of::<~str>()); + assert_eq!(mem::size_of::(), 13); assert_eq!(mem::size_of::(), 3 + mem::size_of::()); assert_eq!(mem::size_of::(), 7 + mem::size_of::>()); } diff --git a/src/test/run-pass/packed-tuple-struct-size.rs b/src/test/run-pass/packed-tuple-struct-size.rs index 059d92b477cec..9036df0bbd1e9 100644 --- a/src/test/run-pass/packed-tuple-struct-size.rs +++ b/src/test/run-pass/packed-tuple-struct-size.rs @@ -19,7 +19,7 @@ struct S4(u8,[u8, .. 3]); struct S5(u8, u32); #[packed] -struct S13_str(i64, f32, u8, ~str); +struct S13(i64, f32, u8); enum Foo { Bar = 1, @@ -37,8 +37,7 @@ pub fn main() { assert_eq!(mem::size_of::(), 5); - assert_eq!(mem::size_of::(), - 13 + mem::size_of::<~str>()); + assert_eq!(mem::size_of::(), 13); assert_eq!(mem::size_of::(), 3 + mem::size_of::()); diff --git a/src/test/run-pass/rec-auto.rs b/src/test/run-pass/rec-auto.rs index b0cd9e60ed70b..19b5268001d1c 100644 --- a/src/test/run-pass/rec-auto.rs +++ b/src/test/run-pass/rec-auto.rs @@ -14,10 +14,10 @@ // Issue #50. -struct X { foo: ~str, bar: ~str } +struct X { foo: StrBuf, bar: StrBuf } pub fn main() { - let x = X {foo: "hello".to_owned(), bar: "world".to_owned()}; + let x = X {foo: "hello".to_strbuf(), bar: "world".to_strbuf()}; println!("{}", x.foo.clone()); println!("{}", x.bar.clone()); } diff --git a/src/test/run-pass/reexported-static-methods-cross-crate.rs b/src/test/run-pass/reexported-static-methods-cross-crate.rs index 213665245a836..17ed80da03c97 100644 --- a/src/test/run-pass/reexported-static-methods-cross-crate.rs +++ b/src/test/run-pass/reexported-static-methods-cross-crate.rs @@ -20,5 +20,5 @@ pub fn main() { assert_eq!(42, Foo::foo()); assert_eq!(84, Baz::bar()); assert!(Boz::boz(1)); - assert_eq!("bort()".to_owned(), Bort::bort()); + assert_eq!("bort()".to_strbuf(), Bort::bort()); } diff --git a/src/test/run-pass/reflect-visit-type.rs b/src/test/run-pass/reflect-visit-type.rs index a131b21957dea..d05bc5600889b 100644 --- a/src/test/run-pass/reflect-visit-type.rs +++ b/src/test/run-pass/reflect-visit-type.rs @@ -13,37 +13,37 @@ use std::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Disr, Opaque}; struct MyVisitor { - types: Vec<~str> , + types: Vec , } impl TyVisitor for MyVisitor { fn visit_bot(&mut self) -> bool { - self.types.push("bot".to_owned()); + self.types.push("bot".to_strbuf()); println!("visited bot type"); true } fn visit_nil(&mut self) -> bool { - self.types.push("nil".to_owned()); + self.types.push("nil".to_strbuf()); println!("visited nil type"); true } fn visit_bool(&mut self) -> bool { - self.types.push("bool".to_owned()); + self.types.push("bool".to_strbuf()); println!("visited bool type"); true } fn visit_int(&mut self) -> bool { - self.types.push("int".to_owned()); + self.types.push("int".to_strbuf()); println!("visited int type"); true } fn visit_i8(&mut self) -> bool { - self.types.push("i8".to_owned()); + self.types.push("i8".to_strbuf()); println!("visited i8 type"); true } fn visit_i16(&mut self) -> bool { - self.types.push("i16".to_owned()); + self.types.push("i16".to_strbuf()); println!("visited i16 type"); true } @@ -76,9 +76,9 @@ impl TyVisitor for MyVisitor { fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true } fn visit_evec_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool { - self.types.push("[".to_owned()); + self.types.push("[".to_strbuf()); unsafe { visit_tydesc(inner, &mut *self as &mut TyVisitor); } - self.types.push("]".to_owned()); + self.types.push("]".to_strbuf()); true } fn visit_evec_slice(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true } @@ -155,7 +155,7 @@ pub fn main() { println!("type: {}", (*s).clone()); } - let vec_types: Vec<~str> = v.types.clone().move_iter().collect(); - assert_eq!(vec_types, vec!("bool".to_owned(), "int".to_owned(), - "i8".to_owned(), "i16".to_owned())); + let vec_types: Vec = v.types.clone().move_iter().collect(); + assert_eq!(vec_types, vec!("bool".to_strbuf(), "int".to_strbuf(), + "i8".to_strbuf(), "i16".to_strbuf())); } diff --git a/src/test/run-pass/repeated-vector-syntax.rs b/src/test/run-pass/repeated-vector-syntax.rs index 9538a097ab4c9..38f0f12267ba5 100644 --- a/src/test/run-pass/repeated-vector-syntax.rs +++ b/src/test/run-pass/repeated-vector-syntax.rs @@ -10,11 +10,6 @@ #![feature(managed_boxes)] -#[deriving(Clone)] -struct Foo { - a: ~str, -} - pub fn main() { let x = [ [true], ..512 ]; let y = [ 0, ..1 ]; diff --git a/src/test/run-pass/ret-bang.rs b/src/test/run-pass/ret-bang.rs index 23b40972cde79..fab8998afbe75 100644 --- a/src/test/run-pass/ret-bang.rs +++ b/src/test/run-pass/ret-bang.rs @@ -11,10 +11,14 @@ -fn my_err(s: ~str) -> ! { println!("{:?}", s); fail!(); } +fn my_err(s: StrBuf) -> ! { println!("{}", s); fail!(); } fn okay(i: uint) -> int { - if i == 3u { my_err("I don't like three".to_owned()); } else { return 42; } + if i == 3u { + my_err("I don't like three".to_strbuf()); + } else { + return 42; + } } pub fn main() { okay(4u); } diff --git a/src/test/run-pass/send_str_treemap.rs b/src/test/run-pass/send_str_treemap.rs index e4a935eae7f43..b6dcf06cae04f 100644 --- a/src/test/run-pass/send_str_treemap.rs +++ b/src/test/run-pass/send_str_treemap.rs @@ -61,8 +61,8 @@ pub fn main() { assert_eq!(map.find(&Owned("def".to_owned())), Some(&d)); assert!(map.pop(&Slice("foo")).is_some()); - assert_eq!(map.move_iter().map(|(k, v)| k.to_str() + v.to_str()) - .collect::>() + assert_eq!(map.move_iter().map(|(k, v)| format_strbuf!("{}{}", k, v)) + .collect::>() .concat(), "abc50bcd51cde52def53".to_owned()); } diff --git a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs index e0a0a7357fcdc..7f5e92e71f2f4 100644 --- a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs +++ b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs @@ -41,7 +41,7 @@ type ty_ = uint; #[deriving(Clone)] struct Path_ { global: bool, - idents: Vec<~str> , + idents: Vec , types: Vec<@ty>, } @@ -59,7 +59,7 @@ pub fn main() { let t: @ty = @Spanned { data: 3u, span: sp }; let p_: Path_ = Path_ { global: true, - idents: vec!("hi".to_owned()), + idents: vec!("hi".to_strbuf()), types: vec!(t), }; let p: path = Spanned { data: p_, span: sp }; diff --git a/src/test/run-pass/spawn-fn.rs b/src/test/run-pass/spawn-fn.rs index 17427be0597dc..dff99cbe366ba 100644 --- a/src/test/run-pass/spawn-fn.rs +++ b/src/test/run-pass/spawn-fn.rs @@ -10,15 +10,19 @@ use std::task; -fn x(s: ~str, n: int) { +fn x(s: StrBuf, n: int) { println!("{:?}", s); println!("{:?}", n); } pub fn main() { - task::spawn(proc() x("hello from first spawned fn".to_owned(), 65) ); - task::spawn(proc() x("hello from second spawned fn".to_owned(), 66) ); - task::spawn(proc() x("hello from third spawned fn".to_owned(), 67) ); + task::spawn(proc() x("hello from first spawned fn".to_strbuf(), 65) ); + task::spawn(proc() x("hello from second spawned fn".to_strbuf(), 66) ); + task::spawn(proc() x("hello from third spawned fn".to_strbuf(), 67) ); let mut i: int = 30; - while i > 0 { i = i - 1; println!("parent sleeping"); task::deschedule(); } + while i > 0 { + i = i - 1; + println!("parent sleeping"); + task::deschedule(); + } } diff --git a/src/test/run-pass/spawn-types.rs b/src/test/run-pass/spawn-types.rs index 830dce1d3cb2e..b2fc1d272e8c5 100644 --- a/src/test/run-pass/spawn-types.rs +++ b/src/test/run-pass/spawn-types.rs @@ -18,11 +18,11 @@ use std::task; type ctx = Sender; -fn iotask(_tx: &ctx, ip: ~str) { - assert_eq!(ip, "localhost".to_owned()); +fn iotask(_tx: &ctx, ip: StrBuf) { + assert_eq!(ip, "localhost".to_strbuf()); } pub fn main() { let (tx, _rx) = channel::(); - task::spawn(proc() iotask(&tx, "localhost".to_owned()) ); + task::spawn(proc() iotask(&tx, "localhost".to_strbuf()) ); } diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 9eb04d5dac129..2bf3510bce1be 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -21,16 +21,18 @@ mod a { mod b { use plus; - impl plus for ~str { fn plus(&self) -> int { 200 } } + impl plus for StrBuf { fn plus(&self) -> int { 200 } } } trait uint_utils { - fn str(&self) -> ~str; + fn str(&self) -> StrBuf; fn multi(&self, f: |uint|); } impl uint_utils for uint { - fn str(&self) -> ~str { self.to_str() } + fn str(&self) -> StrBuf { + self.to_str().to_strbuf() + } fn multi(&self, f: |uint|) { let mut c = 0u; while c < *self { f(c); c += 1u; } @@ -57,9 +59,9 @@ impl vec_utils for Vec { pub fn main() { assert_eq!(10u.plus(), 30); - assert_eq!(("hi".to_owned()).plus(), 200); + assert_eq!(("hi".to_strbuf()).plus(), 200); - assert_eq!((vec!(1)).length_().str(), "1".to_owned()); + assert_eq!((vec!(1)).length_().str(), "1".to_strbuf()); let vect = vec!(3, 4).map_(|a| *a + 4); assert_eq!(*vect.get(0), 7); let vect = (vec!(3, 4)).map_::(|a| *a as uint + 4u); diff --git a/src/test/run-pass/static-method-xcrate.rs b/src/test/run-pass/static-method-xcrate.rs index 3c482d2f91bfb..7cf1a15ab3ec3 100644 --- a/src/test/run-pass/static-method-xcrate.rs +++ b/src/test/run-pass/static-method-xcrate.rs @@ -15,8 +15,8 @@ extern crate static_methods_crate; use static_methods_crate::read; pub fn main() { - let result: int = read("5".to_owned()); + let result: int = read("5".to_strbuf()); assert_eq!(result, 5); - assert_eq!(read::readMaybe("false".to_owned()), Some(false)); - assert_eq!(read::readMaybe("foo".to_owned()), None::); + assert_eq!(read::readMaybe("false".to_strbuf()), Some(false)); + assert_eq!(read::readMaybe("foo".to_strbuf()), None::); } diff --git a/src/test/run-pass/str-concat.rs b/src/test/run-pass/str-concat.rs index 7fcf54bf26b14..cecde7f8838d8 100644 --- a/src/test/run-pass/str-concat.rs +++ b/src/test/run-pass/str-concat.rs @@ -12,9 +12,9 @@ pub fn main() { - let a: ~str = "hello".to_owned(); - let b: ~str = "world".to_owned(); - let s: ~str = a + b; + let a: StrBuf = "hello".to_strbuf(); + let b: StrBuf = "world".to_strbuf(); + let s: StrBuf = format_strbuf!("{}{}", a, b); println!("{}", s.clone()); - assert_eq!(s[9], 'd' as u8); + assert_eq!(s.as_slice()[9], 'd' as u8); } diff --git a/src/test/run-pass/str-multiline.rs b/src/test/run-pass/str-multiline.rs index fd74237c50d41..e42c89e67f4e5 100644 --- a/src/test/run-pass/str-multiline.rs +++ b/src/test/run-pass/str-multiline.rs @@ -9,13 +9,13 @@ // except according to those terms. pub fn main() { - let a: ~str = "this \ -is a test".to_owned(); - let b: ~str = + let a: StrBuf = "this \ +is a test".to_strbuf(); + let b: StrBuf = "this \ is \ another \ - test".to_owned(); - assert_eq!(a, "this is a test".to_owned()); - assert_eq!(b, "this is another test".to_owned()); + test".to_strbuf(); + assert_eq!(a, "this is a test".to_strbuf()); + assert_eq!(b, "this is another test".to_strbuf()); } diff --git a/src/test/run-pass/string-self-append.rs b/src/test/run-pass/string-self-append.rs index 8a5d2d83ac642..619ee761e9c6a 100644 --- a/src/test/run-pass/string-self-append.rs +++ b/src/test/run-pass/string-self-append.rs @@ -10,13 +10,13 @@ pub fn main() { // Make sure we properly handle repeated self-appends. - let mut a: ~str = "A".to_owned(); + let mut a: StrBuf = "A".to_strbuf(); let mut i = 20; let mut expected_len = 1u; while i > 0 { println!("{}", a.len()); assert_eq!(a.len(), expected_len); - a = a + a; // FIXME(#3387)---can't write a += a + a = format_strbuf!("{}{}", a, a); i -= 1; expected_len *= 2u; } diff --git a/src/test/run-pass/struct-literal-dtor.rs b/src/test/run-pass/struct-literal-dtor.rs index d4c7f951b4e85..6f1eec8346a92 100644 --- a/src/test/run-pass/struct-literal-dtor.rs +++ b/src/test/run-pass/struct-literal-dtor.rs @@ -9,7 +9,7 @@ // except according to those terms. struct foo { - x: ~str, + x: StrBuf, } impl Drop for foo { @@ -19,5 +19,7 @@ impl Drop for foo { } pub fn main() { - let _z = foo { x: "Hello".to_owned() }; + let _z = foo { + x: "Hello".to_strbuf() + }; } diff --git a/src/test/run-pass/struct-order-of-eval-1.rs b/src/test/run-pass/struct-order-of-eval-1.rs index cba4d337f2994..e48ad05ef582f 100644 --- a/src/test/run-pass/struct-order-of-eval-1.rs +++ b/src/test/run-pass/struct-order-of-eval-1.rs @@ -8,9 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct S { f0: ~str, f1: int } +struct S { f0: StrBuf, f1: int } pub fn main() { - let s = "Hello, world!".to_owned(); - let _s = S { f0: s.to_owned(), ..S { f0: s, f1: 23 } }; + let s = "Hello, world!".to_strbuf(); + let _s = S { + f0: s.to_strbuf(), + ..S { + f0: s, + f1: 23 + } + }; } diff --git a/src/test/run-pass/struct-order-of-eval-2.rs b/src/test/run-pass/struct-order-of-eval-2.rs index d93252381780f..9b2414325a58b 100644 --- a/src/test/run-pass/struct-order-of-eval-2.rs +++ b/src/test/run-pass/struct-order-of-eval-2.rs @@ -8,9 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct S { f0: ~str, f1: ~str } +struct S { + f0: StrBuf, + f1: StrBuf, +} pub fn main() { - let s = "Hello, world!".to_owned(); - let _s = S { f1: s.to_owned(), f0: s }; + let s = "Hello, world!".to_strbuf(); + let _s = S { + f1: s.to_strbuf(), + f0: s + }; } diff --git a/src/test/run-pass/swap-overlapping.rs b/src/test/run-pass/swap-overlapping.rs index 2e10c9347784e..706f5787c4e59 100644 --- a/src/test/run-pass/swap-overlapping.rs +++ b/src/test/run-pass/swap-overlapping.rs @@ -15,7 +15,7 @@ use std::ptr; pub fn main() { let mut test = TestDescAndFn { desc: TestDesc { - name: DynTestName("test".to_owned()), + name: DynTestName("test".to_strbuf()), should_fail: false }, testfn: DynTestFn(proc() ()), @@ -30,7 +30,7 @@ fn do_swap(test: &mut TestDescAndFn) { } pub enum TestName { - DynTestName(~str) + DynTestName(StrBuf) } pub enum TestFn { diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source-utils.rs index a50c447f0ebb8..017b17d0e9c2f 100644 --- a/src/test/run-pass/syntax-extension-source-utils.rs +++ b/src/test/run-pass/syntax-extension-source-utils.rs @@ -15,7 +15,7 @@ pub mod m1 { pub mod m2 { - pub fn where_am_i() -> ~str { (module_path!()).to_owned() } + pub fn where_am_i() -> StrBuf { (module_path!()).to_strbuf() } } } @@ -26,16 +26,19 @@ pub fn main() { //assert!((col!() == 11)); assert_eq!(indirect_line!(), 27); assert!((file!().to_owned().ends_with("syntax-extension-source-utils.rs"))); - assert_eq!(stringify!((2*3) + 5).to_owned(), "( 2 * 3 ) + 5".to_owned()); - assert!(include!("syntax-extension-source-utils-files/includeme.fragment").to_owned() - == "victory robot 6".to_owned()); + assert_eq!(stringify!((2*3) + 5).to_strbuf(), "( 2 * 3 ) + 5".to_strbuf()); + assert!(include!("syntax-extension-source-utils-files/includeme.\ + fragment").to_strbuf() + == "victory robot 6".to_strbuf()); assert!( - include_str!("syntax-extension-source-utils-files/includeme.fragment").to_owned() + include_str!("syntax-extension-source-utils-files/includeme.\ + fragment").to_strbuf() + .as_slice() .starts_with("/* this is for ")); assert!( include_bin!("syntax-extension-source-utils-files/includeme.fragment") [1] == (42 as u8)); // '*' // The Windows tests are wrapped in an extra module for some reason - assert!((m1::m2::where_am_i().ends_with("m1::m2"))); + assert!((m1::m2::where_am_i().as_slice().ends_with("m1::m2"))); } diff --git a/src/test/run-pass/tag-variant-disr-val.rs b/src/test/run-pass/tag-variant-disr-val.rs index e31b289f541a2..40c5f62398689 100644 --- a/src/test/run-pass/tag-variant-disr-val.rs +++ b/src/test/run-pass/tag-variant-disr-val.rs @@ -27,17 +27,17 @@ impl Eq for color { } pub fn main() { - test_color(red, 0xff0000, "red".to_owned()); - test_color(green, 0x00ff00, "green".to_owned()); - test_color(blue, 0x0000ff, "blue".to_owned()); - test_color(black, 0x000000, "black".to_owned()); - test_color(white, 0xFFFFFF, "white".to_owned()); - test_color(imaginary, -1, "imaginary".to_owned()); - test_color(purple, 2, "purple".to_owned()); - test_color(orange, 4, "orange".to_owned()); + test_color(red, 0xff0000, "red".to_strbuf()); + test_color(green, 0x00ff00, "green".to_strbuf()); + test_color(blue, 0x0000ff, "blue".to_strbuf()); + test_color(black, 0x000000, "black".to_strbuf()); + test_color(white, 0xFFFFFF, "white".to_strbuf()); + test_color(imaginary, -1, "imaginary".to_strbuf()); + test_color(purple, 2, "purple".to_strbuf()); + test_color(orange, 4, "orange".to_strbuf()); } -fn test_color(color: color, val: int, name: ~str) { +fn test_color(color: color, val: int, name: StrBuf) { //assert!(unsafe::transmute(color) == val); assert_eq!(color as int, val); assert_eq!(color as f64, val as f64); @@ -45,27 +45,27 @@ fn test_color(color: color, val: int, name: ~str) { assert!(get_color_if(color) == name); } -fn get_color_alt(color: color) -> ~str { +fn get_color_alt(color: color) -> StrBuf { match color { - red => {"red".to_owned()} - green => {"green".to_owned()} - blue => {"blue".to_owned()} - black => {"black".to_owned()} - white => {"white".to_owned()} - imaginary => {"imaginary".to_owned()} - purple => {"purple".to_owned()} - orange => {"orange".to_owned()} + red => {"red".to_strbuf()} + green => {"green".to_strbuf()} + blue => {"blue".to_strbuf()} + black => {"black".to_strbuf()} + white => {"white".to_strbuf()} + imaginary => {"imaginary".to_strbuf()} + purple => {"purple".to_strbuf()} + orange => {"orange".to_strbuf()} } } -fn get_color_if(color: color) -> ~str { - if color == red {"red".to_owned()} - else if color == green {"green".to_owned()} - else if color == blue {"blue".to_owned()} - else if color == black {"black".to_owned()} - else if color == white {"white".to_owned()} - else if color == imaginary {"imaginary".to_owned()} - else if color == purple {"purple".to_owned()} - else if color == orange {"orange".to_owned()} - else {"unknown".to_owned()} +fn get_color_if(color: color) -> StrBuf { + if color == red {"red".to_strbuf()} + else if color == green {"green".to_strbuf()} + else if color == blue {"blue".to_strbuf()} + else if color == black {"black".to_strbuf()} + else if color == white {"white".to_strbuf()} + else if color == imaginary {"imaginary".to_strbuf()} + else if color == purple {"purple".to_strbuf()} + else if color == orange {"orange".to_strbuf()} + else {"unknown".to_strbuf()} } diff --git a/src/test/run-pass/tail-call-arg-leak.rs b/src/test/run-pass/tail-call-arg-leak.rs index fab5bb02afadd..e90fe27823b64 100644 --- a/src/test/run-pass/tail-call-arg-leak.rs +++ b/src/test/run-pass/tail-call-arg-leak.rs @@ -12,6 +12,8 @@ // use of tail calls causes arg slot leaks, issue #160. -fn inner(dummy: ~str, b: bool) { if b { return inner(dummy, false); } } +fn inner(dummy: StrBuf, b: bool) { if b { return inner(dummy, false); } } -pub fn main() { inner("hi".to_owned(), true); } +pub fn main() { + inner("hi".to_strbuf(), true); +} diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs index 9bd5110cccf9c..b298f2edf010c 100644 --- a/src/test/run-pass/task-comm-10.rs +++ b/src/test/run-pass/task-comm-10.rs @@ -11,18 +11,18 @@ use std::task; -fn start(tx: &Sender>) { +fn start(tx: &Sender>) { let (tx2, rx) = channel(); tx.send(tx2); let mut a; let mut b; a = rx.recv(); - assert!(a == "A".to_owned()); - println!("{:?}", a); + assert!(a == "A".to_strbuf()); + println!("{}", a); b = rx.recv(); - assert!(b == "B".to_owned()); - println!("{:?}", b); + assert!(b == "B".to_strbuf()); + println!("{}", b); } pub fn main() { @@ -30,7 +30,7 @@ pub fn main() { let _child = task::spawn(proc() { start(&tx) }); let mut c = rx.recv(); - c.send("A".to_owned()); - c.send("B".to_owned()); + c.send("A".to_strbuf()); + c.send("B".to_strbuf()); task::deschedule(); } diff --git a/src/test/run-pass/task-life-0.rs b/src/test/run-pass/task-life-0.rs index b0974676d07e7..378effa8a1893 100644 --- a/src/test/run-pass/task-life-0.rs +++ b/src/test/run-pass/task-life-0.rs @@ -11,9 +11,9 @@ use std::task; pub fn main() { - task::spawn(proc() child("Hello".to_owned()) ); + task::spawn(proc() child("Hello".to_strbuf()) ); } -fn child(_s: ~str) { +fn child(_s: StrBuf) { } diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index 98dd3772a4f92..b5ed021ec6a78 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -25,43 +25,54 @@ trait Pet { struct Catte { num_whiskers: uint, - name: ~str, + name: StrBuf, } struct Dogge { bark_decibels: uint, tricks_known: uint, - name: ~str, + name: StrBuf, } struct Goldfyshe { swim_speed: uint, - name: ~str, + name: StrBuf, } impl Pet for Catte { - fn name(&self, blk: |&str|) { blk(self.name) } + fn name(&self, blk: |&str|) { blk(self.name.as_slice()) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 } } impl Pet for Dogge { - fn name(&self, blk: |&str|) { blk(self.name) } + fn name(&self, blk: |&str|) { blk(self.name.as_slice()) } fn num_legs(&self) -> uint { 4 } fn of_good_pedigree(&self) -> bool { self.bark_decibels < 70 || self.tricks_known > 20 } } impl Pet for Goldfyshe { - fn name(&self, blk: |&str|) { blk(self.name) } + fn name(&self, blk: |&str|) { blk(self.name.as_slice()) } fn num_legs(&self) -> uint { 0 } fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 } } pub fn main() { - let catte = Catte { num_whiskers: 7, name: "alonzo_church".to_owned() }; - let dogge1 = Dogge { bark_decibels: 100, tricks_known: 42, name: "alan_turing".to_owned() }; - let dogge2 = Dogge { bark_decibels: 55, tricks_known: 11, name: "albert_einstein".to_owned() }; - let fishe = Goldfyshe { swim_speed: 998, name: "alec_guinness".to_owned() }; + let catte = Catte { num_whiskers: 7, name: "alonzo_church".to_strbuf() }; + let dogge1 = Dogge { + bark_decibels: 100, + tricks_known: 42, + name: "alan_turing".to_strbuf(), + }; + let dogge2 = Dogge { + bark_decibels: 55, + tricks_known: 11, + name: "albert_einstein".to_strbuf(), + }; + let fishe = Goldfyshe { + swim_speed: 998, + name: "alec_guinness".to_strbuf(), + }; let arc = Arc::new(vec!(box catte as Box, box dogge1 as Box, box fishe as Box, diff --git a/src/test/run-pass/trait-cast.rs b/src/test/run-pass/trait-cast.rs index 3d303bf1e5b3b..d6aaefe868f3f 100644 --- a/src/test/run-pass/trait-cast.rs +++ b/src/test/run-pass/trait-cast.rs @@ -22,33 +22,38 @@ struct TreeR { } trait to_str { - fn to_str_(&self) -> ~str; + fn to_str_(&self) -> StrBuf; } impl to_str for Option { - fn to_str_(&self) -> ~str { + fn to_str_(&self) -> StrBuf { match *self { - None => { "none".to_owned() } - Some(ref t) => { "some(".to_owned() + t.to_str_() + ")".to_owned() } + None => { "none".to_strbuf() } + Some(ref t) => format_strbuf!("some({})", t.to_str_()), } } } impl to_str for int { - fn to_str_(&self) -> ~str { self.to_str() } + fn to_str_(&self) -> StrBuf { + self.to_str().to_strbuf() + } } impl to_str for Tree { - fn to_str_(&self) -> ~str { + fn to_str_(&self) -> StrBuf { let Tree(t) = *self; let this = t.borrow(); let (l, r) = (this.left, this.right); let val = &this.val; - format!("[{}, {}, {}]", val.to_str_(), l.to_str_(), r.to_str_()) + format_strbuf!("[{}, {}, {}]", + val.to_str_(), + l.to_str_(), + r.to_str_()) } } -fn foo(x: T) -> ~str { x.to_str_() } +fn foo(x: T) -> StrBuf { x.to_str_() } pub fn main() { let t1 = Tree(@RefCell::new(TreeR{left: None, @@ -57,7 +62,8 @@ pub fn main() { let t2 = Tree(@RefCell::new(TreeR{left: Some(t1), right: Some(t1), val: box 2 as Box})); - let expected = "[2, some([1, none, none]), some([1, none, none])]".to_owned(); + let expected = + "[2, some([1, none, none]), some([1, none, none])]".to_strbuf(); assert!(t2.to_str_() == expected); assert!(foo(t2) == expected); diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index 4b745ba5e3eeb..269c1d4094ebb 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -11,16 +11,16 @@ trait to_str { - fn to_string(&self) -> ~str; + fn to_string(&self) -> StrBuf; } impl to_str for int { - fn to_string(&self) -> ~str { self.to_str() } + fn to_string(&self) -> StrBuf { self.to_str().to_strbuf() } } -impl to_str for ~str { - fn to_string(&self) -> ~str { self.clone() } +impl to_str for StrBuf { + fn to_string(&self) -> StrBuf { self.clone() } } impl to_str for () { - fn to_string(&self) -> ~str { "()".to_owned() } + fn to_string(&self) -> StrBuf { "()".to_strbuf() } } trait map { @@ -37,17 +37,17 @@ impl map for Vec { } } -fn foo>(x: T) -> Vec<~str> { - x.map(|_e| "hi".to_owned() ) +fn foo>(x: T) -> Vec { + x.map(|_e| "hi".to_strbuf() ) } -fn bar>(x: T) -> Vec<~str> { +fn bar>(x: T) -> Vec { x.map(|_e| _e.to_string() ) } pub fn main() { - assert_eq!(foo(vec!(1)), vec!("hi".to_owned())); - assert_eq!(bar:: >(vec!(4, 5)), vec!("4".to_owned(), "5".to_owned())); - assert_eq!(bar::<~str, Vec<~str> >(vec!("x".to_owned(), "y".to_owned())), - vec!("x".to_owned(), "y".to_owned())); - assert_eq!(bar::<(), Vec<()>>(vec!(())), vec!("()".to_owned())); + assert_eq!(foo(vec!(1)), vec!("hi".to_strbuf())); + assert_eq!(bar:: >(vec!(4, 5)), vec!("4".to_strbuf(), "5".to_strbuf())); + assert_eq!(bar:: >(vec!("x".to_strbuf(), "y".to_strbuf())), + vec!("x".to_strbuf(), "y".to_strbuf())); + assert_eq!(bar::<(), Vec<()>>(vec!(())), vec!("()".to_strbuf())); } diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index 794f810165dcb..5d22199e4a540 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -11,30 +11,34 @@ trait to_str { - fn to_string(&self) -> ~str; + fn to_string(&self) -> StrBuf; } impl to_str for int { - fn to_string(&self) -> ~str { self.to_str() } + fn to_string(&self) -> StrBuf { self.to_str().to_strbuf() } } impl to_str for Vec { - fn to_string(&self) -> ~str { - format!("[{}]", self.iter().map(|e| e.to_string()).collect::>().connect(", ")) + fn to_string(&self) -> StrBuf { + format_strbuf!("[{}]", + self.iter() + .map(|e| e.to_string()) + .collect::>() + .connect(", ")) } } pub fn main() { - assert!(1.to_string() == "1".to_owned()); - assert!((vec!(2, 3, 4)).to_string() == "[2, 3, 4]".to_owned()); + assert!(1.to_string() == "1".to_strbuf()); + assert!((vec!(2, 3, 4)).to_string() == "[2, 3, 4]".to_strbuf()); - fn indirect(x: T) -> ~str { - x.to_string() + "!" + fn indirect(x: T) -> StrBuf { + format_strbuf!("{}!", x.to_string()) } - assert!(indirect(vec!(10, 20)) == "[10, 20]!".to_owned()); + assert!(indirect(vec!(10, 20)) == "[10, 20]!".to_strbuf()); - fn indirect2(x: T) -> ~str { + fn indirect2(x: T) -> StrBuf { indirect(x) } - assert!(indirect2(vec!(1)) == "[1]!".to_owned()); + assert!(indirect2(vec!(1)) == "[1]!".to_strbuf()); } diff --git a/src/test/run-pass/traits-default-method-macro.rs b/src/test/run-pass/traits-default-method-macro.rs index 2a60e774645fd..db5be5f938ae7 100644 --- a/src/test/run-pass/traits-default-method-macro.rs +++ b/src/test/run-pass/traits-default-method-macro.rs @@ -10,8 +10,8 @@ trait Foo { - fn bar(&self) -> ~str { - format!("test") + fn bar(&self) -> StrBuf { + format_strbuf!("test") } } @@ -24,5 +24,5 @@ impl Foo for Baz { pub fn main() { let q = Quux; - assert_eq!(q.bar(), "test".to_owned()); + assert_eq!(q.bar(), "test".to_strbuf()); } diff --git a/src/test/run-pass/utf8.rs b/src/test/run-pass/utf8.rs index debb1c3812a80..a12483c1d7812 100644 --- a/src/test/run-pass/utf8.rs +++ b/src/test/run-pass/utf8.rs @@ -24,27 +24,27 @@ pub fn main() { assert_eq!(pi as int, '\u03a0' as int); assert_eq!('\x0a' as int, '\n' as int); - let bhutan: ~str = "འབྲུག་ཡུལ།".to_owned(); - let japan: ~str = "日本".to_owned(); - let uzbekistan: ~str = "Ўзбекистон".to_owned(); - let austria: ~str = "Österreich".to_owned(); - - let bhutan_e: ~str = - "\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d".to_owned(); - let japan_e: ~str = "\u65e5\u672c".to_owned(); - let uzbekistan_e: ~str = - "\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d".to_owned(); - let austria_e: ~str = "\u00d6sterreich".to_owned(); + let bhutan: StrBuf = "འབྲུག་ཡུལ།".to_strbuf(); + let japan: StrBuf = "日本".to_strbuf(); + let uzbekistan: StrBuf = "Ўзбекистон".to_strbuf(); + let austria: StrBuf = "Österreich".to_strbuf(); + + let bhutan_e: StrBuf = + "\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d".to_strbuf(); + let japan_e: StrBuf = "\u65e5\u672c".to_strbuf(); + let uzbekistan_e: StrBuf = + "\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d".to_strbuf(); + let austria_e: StrBuf = "\u00d6sterreich".to_strbuf(); let oo: char = 'Ö'; assert_eq!(oo as int, 0xd6); - fn check_str_eq(a: ~str, b: ~str) { + fn check_str_eq(a: StrBuf, b: StrBuf) { let mut i: int = 0; - for ab in a.bytes() { + for ab in a.as_slice().bytes() { println!("{}", i); println!("{}", ab); - let bb: u8 = b[i as uint]; + let bb: u8 = b.as_slice()[i as uint]; println!("{}", bb); assert_eq!(ab, bb); i += 1; diff --git a/src/test/run-pass/utf8_chars.rs b/src/test/run-pass/utf8_chars.rs index a418cd0ae022d..2e0e1af43b4eb 100644 --- a/src/test/run-pass/utf8_chars.rs +++ b/src/test/run-pass/utf8_chars.rs @@ -13,15 +13,15 @@ use std::str; pub fn main() { // Chars of 1, 2, 3, and 4 bytes let chs: Vec = vec!('e', 'é', '€', '\U00010000'); - let s: ~str = str::from_chars(chs.as_slice()); - let schs: Vec = s.chars().collect(); + let s: StrBuf = str::from_chars(chs.as_slice()).to_strbuf(); + let schs: Vec = s.as_slice().chars().collect(); assert!(s.len() == 10u); - assert!(s.char_len() == 4u); + assert!(s.as_slice().char_len() == 4u); assert!(schs.len() == 4u); - assert!(str::from_chars(schs.as_slice()) == s); - assert!(s.char_at(0u) == 'e'); - assert!(s.char_at(1u) == 'é'); + assert!(str::from_chars(schs.as_slice()).to_strbuf() == s); + assert!(s.as_slice().char_at(0u) == 'e'); + assert!(s.as_slice().char_at(1u) == 'é'); assert!((str::is_utf8(s.as_bytes()))); // invalid prefix diff --git a/src/test/run-pass/variant-attributes.rs b/src/test/run-pass/variant-attributes.rs index 2b200c8af308a..e26c592a06487 100644 --- a/src/test/run-pass/variant-attributes.rs +++ b/src/test/run-pass/variant-attributes.rs @@ -34,6 +34,6 @@ enum crew_of_enterprise_d { geordi_la_forge, } -fn boldly_go(_crew_member: crew_of_enterprise_d, _where: ~str) { } +fn boldly_go(_crew_member: crew_of_enterprise_d, _where: StrBuf) { } -pub fn main() { boldly_go(worf, "where no one has gone before".to_owned()); } +pub fn main() { boldly_go(worf, "where no one has gone before".to_strbuf()); } diff --git a/src/test/run-pass/vec-tail-matching.rs b/src/test/run-pass/vec-tail-matching.rs index 0703955f21169..8d2f29d9b0977 100644 --- a/src/test/run-pass/vec-tail-matching.rs +++ b/src/test/run-pass/vec-tail-matching.rs @@ -10,29 +10,29 @@ struct Foo { - string: ~str + string: StrBuf } pub fn main() { let x = [ - 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() } ]; match x { [ref first, ..tail] => { - assert!(first.string == "foo".to_owned()); + assert!(first.string == "foo".to_strbuf()); assert_eq!(tail.len(), 2); - assert!(tail[0].string == "bar".to_owned()); - assert!(tail[1].string == "baz".to_owned()); + assert!(tail[0].string == "bar".to_strbuf()); + assert!(tail[1].string == "baz".to_strbuf()); match tail { [Foo { .. }, _, Foo { .. }, .. _tail] => { unreachable!(); } [Foo { string: ref a }, Foo { string: ref b }] => { - assert_eq!("bar", a.slice(0, a.len())); - assert_eq!("baz", b.slice(0, b.len())); + assert_eq!("bar", a.as_slice().slice(0, a.len())); + assert_eq!("baz", b.as_slice().slice(0, b.len())); } _ => { unreachable!();