@@ -993,7 +993,7 @@ pub mod raw {
993
993
use cast;
994
994
use libc;
995
995
use ptr;
996
- use str:: is_utf8;
996
+ use str:: { is_utf8, OwnedStr } ;
997
997
use vec;
998
998
use vec:: MutableVector ;
999
999
use unstable:: raw:: Slice ;
@@ -1002,7 +1002,7 @@ pub mod raw {
1002
1002
pub unsafe fn from_buf_len ( buf : * u8 , len : uint ) -> ~str {
1003
1003
let mut v: ~[ u8 ] = vec:: with_capacity ( len) ;
1004
1004
v. as_mut_buf ( |vbuf, _len| ptr:: copy_memory ( vbuf, buf as * u8 , len) ) ;
1005
- vec :: raw :: set_len ( & mut v , len) ;
1005
+ v . set_len ( len) ;
1006
1006
1007
1007
assert ! ( is_utf8( v) ) ;
1008
1008
:: cast:: transmute ( v)
@@ -1109,7 +1109,7 @@ pub mod raw {
1109
1109
let len = s. len ( ) ;
1110
1110
assert ! ( ( len > 0 u) ) ;
1111
1111
let b = s[ len - 1 u] ;
1112
- set_len ( s , len - 1 u ) ;
1112
+ s . set_len ( len - 1 ) ;
1113
1113
return b;
1114
1114
}
1115
1115
@@ -1130,16 +1130,6 @@ pub mod raw {
1130
1130
cast:: transmute ( s)
1131
1131
}
1132
1132
1133
- /// Sets the length of a string
1134
- ///
1135
- /// This will explicitly set the size of the string, without actually
1136
- /// modifying its buffers, so it is up to the caller to ensure that
1137
- /// the string is actually the specified size.
1138
- #[ inline]
1139
- pub unsafe fn set_len ( s : & mut ~str , new_len : uint ) {
1140
- vec:: raw:: set_len ( as_owned_vec ( s) , new_len)
1141
- }
1142
-
1143
1133
/// Sets the length of a string
1144
1134
///
1145
1135
/// This will explicitly set the size of the string, without actually
@@ -1339,7 +1329,7 @@ impl Mutable for ~str {
1339
1329
#[inline]
1340
1330
fn clear(&mut self) {
1341
1331
unsafe {
1342
- raw:: set_len(self, 0)
1332
+ self. set_len(0)
1343
1333
}
1344
1334
}
1345
1335
}
@@ -2293,7 +2283,7 @@ impl<'a> StrSlice<'a> for &'a str {
2293
2283
let mut v = vec:: with_capacity( len) ;
2294
2284
2295
2285
v. as_mut_buf( |dst, _| ptr:: copy_memory( dst, src, len) ) ;
2296
- vec :: raw :: set_len( & mut v , len) ;
2286
+ v . set_len( len) ;
2297
2287
:: cast:: transmute( v)
2298
2288
}
2299
2289
} )
@@ -2598,6 +2588,13 @@ pub trait OwnedStr {
2598
2588
/// The caller must make sure any mutations to this buffer keep the string
2599
2589
/// valid UTF-8!
2600
2590
fn as_mut_buf<T >( & mut self , f: |* mut u8 , uint| -> T ) -> T ;
2591
+
2592
+ /// Sets the length of a string
2593
+ ///
2594
+ /// This will explicitly set the size of the string, without actually
2595
+ /// modifying its buffers, so it is up to the caller to ensure that
2596
+ /// the string is actually the specified size.
2597
+ unsafe fn set_len( & mut self , new_len: uint) ;
2601
2598
}
2602
2599
2603
2600
impl OwnedStr for ~str {
@@ -2629,7 +2626,7 @@ impl OwnedStr for ~str {
2629
2626
c. encode_utf8( slc)
2630
2627
} )
2631
2628
} ) ;
2632
- raw :: set_len( self , cur_len + used) ;
2629
+ self . set_len( cur_len + used) ;
2633
2630
}
2634
2631
}
2635
2632
@@ -2638,7 +2635,7 @@ impl OwnedStr for ~str {
2638
2635
let end = self . len( ) ;
2639
2636
assert!( end > 0 u) ;
2640
2637
let CharRange { ch, next} = self . char_range_at_reverse( end) ;
2641
- unsafe { raw :: set_len( self , next) ; }
2638
+ unsafe { self . set_len( next) ; }
2642
2639
return ch;
2643
2640
}
2644
2641
@@ -2689,7 +2686,7 @@ impl OwnedStr for ~str {
2689
2686
fn truncate( & mut self , len: uint) {
2690
2687
assert!( len <= self . len( ) ) ;
2691
2688
assert!( self . is_char_boundary( len) ) ;
2692
- unsafe { raw :: set_len( self , len) ; }
2689
+ unsafe { self . set_len( len) ; }
2693
2690
}
2694
2691
2695
2692
#[ inline]
@@ -2703,6 +2700,11 @@ impl OwnedStr for ~str {
2703
2700
raw:: as_owned_vec( self ) . as_mut_buf( f)
2704
2701
}
2705
2702
}
2703
+
2704
+ #[ inline]
2705
+ unsafe fn set_len( & mut self , new_len: uint) {
2706
+ raw:: as_owned_vec( self ) . set_len( new_len)
2707
+ }
2706
2708
}
2707
2709
2708
2710
impl Clone for ~str {
0 commit comments