diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-11 12:01:45 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-12 12:21:03 +1000 |
| commit | 3c23a0a836164ed3ac1b94b526ff8f4e71571e8e (patch) | |
| tree | a067e160673e4cc9e9eff19b7b29331328a86632 /src | |
| parent | 96cd61ad034cc9e88ab6a7845c3480dbc1ea62f3 (diff) | |
| download | rust-3c23a0a836164ed3ac1b94b526ff8f4e71571e8e.tar.gz rust-3c23a0a836164ed3ac1b94b526ff8f4e71571e8e.zip | |
std: replace str::append with a method
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiletest/runtest.rs | 2 | ||||
| -rw-r--r-- | src/libstd/str.rs | 40 |
2 files changed, 31 insertions, 11 deletions
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 7159e51e3b6..6b4f1420c56 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -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"); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 9d8618e5571..e8145b37114 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -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 @@ -2397,6 +2396,27 @@ mod tests { } #[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 = ~"ประเทศไทย中华"; let cc = pop_char(&mut data); |
