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;
#[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 {
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);
}
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
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 = ~"ประเทศไทย中华";