@@ -154,14 +154,6 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
154
154
lhs. push_str ( rhs)
155
155
}
156
156
157
- /// Concatenate two strings together
158
- #[ inline( always) ]
159
- pub fn append ( lhs : ~str , rhs : & str ) -> ~str {
160
- let mut v = lhs;
161
- v. push_str_no_overallocate ( rhs) ;
162
- v
163
- }
164
-
165
157
#[ allow( missing_doc) ]
166
158
pub trait StrVector {
167
159
pub fn concat ( & self ) -> ~str ;
@@ -1515,8 +1507,6 @@ pub mod raw {
1515
1507
#[cfg(not(test))]
1516
1508
pub mod traits {
1517
1509
use ops::Add;
1518
- use str::append;
1519
-
1520
1510
impl<'self> Add<&'self str,~str> for ~str {
1521
1511
#[inline(always)]
1522
1512
fn add(&self, rhs: & &'self str) -> ~str {
@@ -2100,6 +2090,7 @@ pub trait OwnedStr {
2100
2090
fn push_str_no_overallocate(&mut self, rhs: &str);
2101
2091
fn push_str(&mut self, rhs: &str);
2102
2092
fn push_char(&mut self, c: char);
2093
+ fn append(&self, rhs: &str) -> ~str; // FIXME #4850: this should consume self.
2103
2094
fn reserve(&mut self, n: uint);
2104
2095
fn reserve_at_least(&mut self, n: uint);
2105
2096
}
@@ -2197,6 +2188,14 @@ impl OwnedStr for ~str {
2197
2188
raw::set_len(self, new_len);
2198
2189
}
2199
2190
}
2191
+ /// Concatenate two strings together.
2192
+ #[inline]
2193
+ fn append(&self, rhs: &str) -> ~str {
2194
+ // FIXME #4850: this should consume self, but that causes segfaults
2195
+ let mut v = self.clone();
2196
+ v.push_str_no_overallocate(rhs);
2197
+ v
2198
+ }
2200
2199
2201
2200
/**
2202
2201
* Reserves capacity for exactly `n` bytes in the given string, not including
@@ -2396,6 +2395,27 @@ mod tests {
2396
2395
assert_eq ! ( "ประเทศไทย中华Việt Nam" . rfind( |c: char | c == '华' ) , Some ( 30 u) ) ;
2397
2396
}
2398
2397
2398
+ #[ test]
2399
+ fn test_push_str ( ) {
2400
+ let mut s = ~"";
2401
+ s. push_str ( "" ) ;
2402
+ assert_eq ! ( s. slice_from( 0 ) , "" ) ;
2403
+ s. push_str ( "abc" ) ;
2404
+ assert_eq ! ( s. slice_from( 0 ) , "abc" ) ;
2405
+ s. push_str ( "ประเทศไทย中华Việt Nam" ) ;
2406
+ assert_eq ! ( s. slice_from( 0 ) , "abcประเทศไทย中华Việt Nam" ) ;
2407
+ }
2408
+ #[ test]
2409
+ fn test_append ( ) {
2410
+ let mut s = ~"";
2411
+ s = s. append ( "" ) ;
2412
+ assert_eq ! ( s. slice_from( 0 ) , "" ) ;
2413
+ s = s. append ( "abc" ) ;
2414
+ assert_eq ! ( s. slice_from( 0 ) , "abc" ) ;
2415
+ s = s. append ( "ประเทศไทย中华Việt Nam" ) ;
2416
+ assert_eq ! ( s. slice_from( 0 ) , "abcประเทศไทย中华Việt Nam" ) ;
2417
+ }
2418
+
2399
2419
#[ test]
2400
2420
fn test_pop_char( ) {
2401
2421
let mut data = ~"ประเทศไทย中华";
0 commit comments