@@ -993,7 +993,7 @@ pub mod raw {
993993 use cast;
994994 use libc;
995995 use ptr;
996- use str:: is_utf8;
996+ use str:: { is_utf8, OwnedStr } ;
997997 use vec;
998998 use vec:: MutableVector ;
999999 use unstable:: raw:: Slice ;
@@ -1002,7 +1002,7 @@ pub mod raw {
10021002 pub unsafe fn from_buf_len ( buf : * u8 , len : uint ) -> ~str {
10031003 let mut v: ~[ u8 ] = vec:: with_capacity ( len) ;
10041004 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) ;
10061006
10071007 assert ! ( is_utf8( v) ) ;
10081008 :: cast:: transmute ( v)
@@ -1109,7 +1109,7 @@ pub mod raw {
11091109 let len = s. len ( ) ;
11101110 assert ! ( ( len > 0 u) ) ;
11111111 let b = s[ len - 1 u] ;
1112- set_len ( s , len - 1 u ) ;
1112+ s . set_len ( len - 1 ) ;
11131113 return b;
11141114 }
11151115
@@ -1130,16 +1130,6 @@ pub mod raw {
11301130 cast:: transmute ( s)
11311131 }
11321132
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-
11431133 /// Sets the length of a string
11441134 ///
11451135 /// This will explicitly set the size of the string, without actually
@@ -1339,7 +1329,7 @@ impl Mutable for ~str {
13391329 #[inline]
13401330 fn clear(&mut self) {
13411331 unsafe {
1342- raw:: set_len(self, 0)
1332+ self. set_len(0)
13431333 }
13441334 }
13451335}
@@ -2293,7 +2283,7 @@ impl<'a> StrSlice<'a> for &'a str {
22932283 let mut v = vec:: with_capacity( len) ;
22942284
22952285 v. as_mut_buf( |dst, _| ptr:: copy_memory( dst, src, len) ) ;
2296- vec :: raw :: set_len( & mut v , len) ;
2286+ v . set_len( len) ;
22972287 :: cast:: transmute( v)
22982288 }
22992289 } )
@@ -2598,6 +2588,13 @@ pub trait OwnedStr {
25982588 /// The caller must make sure any mutations to this buffer keep the string
25992589 /// valid UTF-8!
26002590 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) ;
26012598}
26022599
26032600impl OwnedStr for ~str {
@@ -2629,7 +2626,7 @@ impl OwnedStr for ~str {
26292626 c. encode_utf8( slc)
26302627 } )
26312628 } ) ;
2632- raw :: set_len( self , cur_len + used) ;
2629+ self . set_len( cur_len + used) ;
26332630 }
26342631 }
26352632
@@ -2638,7 +2635,7 @@ impl OwnedStr for ~str {
26382635 let end = self . len( ) ;
26392636 assert!( end > 0 u) ;
26402637 let CharRange { ch, next} = self . char_range_at_reverse( end) ;
2641- unsafe { raw :: set_len( self , next) ; }
2638+ unsafe { self . set_len( next) ; }
26422639 return ch;
26432640 }
26442641
@@ -2689,7 +2686,7 @@ impl OwnedStr for ~str {
26892686 fn truncate( & mut self , len: uint) {
26902687 assert!( len <= self . len( ) ) ;
26912688 assert!( self . is_char_boundary( len) ) ;
2692- unsafe { raw :: set_len( self , len) ; }
2689+ unsafe { self . set_len( len) ; }
26932690 }
26942691
26952692 #[ inline]
@@ -2703,6 +2700,11 @@ impl OwnedStr for ~str {
27032700 raw:: as_owned_vec( self ) . as_mut_buf( f)
27042701 }
27052702 }
2703+
2704+ #[ inline]
2705+ unsafe fn set_len( & mut self , new_len: uint) {
2706+ raw:: as_owned_vec( self ) . set_len( new_len)
2707+ }
27062708}
27072709
27082710impl Clone for ~str {
0 commit comments