std: replace str::append with a method

This commit is contained in:
Huon Wilson 2013-06-11 12:01:45 +10:00
parent 96cd61ad03
commit 3c23a0a836
2 changed files with 31 additions and 11 deletions

View File

@ -254,7 +254,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
}
// write debugger script
let script_str = str::append(cmds, "\nquit\n");
let script_str = cmds.append("\nquit\n");
debug!("script_str = %s", script_str);
dump_output_file(config, testfile, script_str, "debugger.script");

View File

@ -154,14 +154,6 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
lhs.push_str(rhs)
}
/// Concatenate two strings together
#[inline(always)]
pub fn append(lhs: ~str, rhs: &str) -> ~str {
let mut v = lhs;
v.push_str_no_overallocate(rhs);
v
}
#[allow(missing_doc)]
pub trait StrVector {
pub fn concat(&self) -> ~str;
@ -1515,8 +1507,6 @@ pub mod raw {
#[cfg(not(test))]
pub mod traits {
use ops::Add;
use str::append;
impl<'self> Add<&'self str,~str> for ~str {
#[inline(always)]
fn add(&self, rhs: & &'self str) -> ~str {
@ -2100,6 +2090,7 @@ pub trait OwnedStr {
fn push_str_no_overallocate(&mut self, rhs: &str);
fn push_str(&mut self, rhs: &str);
fn push_char(&mut self, c: char);
fn append(&self, rhs: &str) -> ~str; // FIXME #4850: this should consume self.
fn reserve(&mut self, n: uint);
fn reserve_at_least(&mut self, n: uint);
}
@ -2197,6 +2188,14 @@ impl OwnedStr for ~str {
raw::set_len(self, new_len);
}
}
/// Concatenate two strings together.
#[inline]
fn append(&self, rhs: &str) -> ~str {
// FIXME #4850: this should consume self, but that causes segfaults
let mut v = self.clone();
v.push_str_no_overallocate(rhs);
v
}
/**
* Reserves capacity for exactly `n` bytes in the given string, not including
@ -2396,6 +2395,27 @@ mod tests {
assert_eq!("ประเทศไทย中华Việt Nam".rfind(|c: char| c == '华'), Some(30u));
}
#[test]
fn test_push_str() {
let mut s = ~"";
s.push_str("");
assert_eq!(s.slice_from(0), "");
s.push_str("abc");
assert_eq!(s.slice_from(0), "abc");
s.push_str("ประเทศไทย中华Việt Nam");
assert_eq!(s.slice_from(0), "abcประเทศไทย中华Việt Nam");
}
#[test]
fn test_append() {
let mut s = ~"";
s = s.append("");
assert_eq!(s.slice_from(0), "");
s = s.append("abc");
assert_eq!(s.slice_from(0), "abc");
s = s.append("ประเทศไทย中华Việt Nam");
assert_eq!(s.slice_from(0), "abcประเทศไทย中华Việt Nam");
}
#[test]
fn test_pop_char() {
let mut data = ~"ประเทศไทย中华";