@@ -424,7 +424,7 @@ Failure:
424
424
425
425
If `begin` + `len` is is greater than the byte length of the string
426
426
*/
427
- fn substr ( s : str , begin : uint , len : uint ) -> str {
427
+ fn substr ( s : str , begin : uint , len : uint ) -> str unsafe {
428
428
ret unsafe:: slice ( s, begin, begin + len) ;
429
429
}
430
430
@@ -706,13 +706,14 @@ Returns:
706
706
707
707
The original string with all occurances of `from` replaced with `to`
708
708
*/
709
- fn replace( s : str , from : str , to : str ) : is_not_empty ( from ) -> str {
709
+ fn replace( s : str , from : str , to : str ) : is_not_empty ( from ) -> str unsafe {
710
710
// FIXME (694): Shouldn't have to check this
711
711
check ( is_not_empty ( from) ) ;
712
712
if byte_len ( s) == 0 u {
713
713
ret "" ;
714
714
} else if starts_with ( s, from) {
715
- ret to + replace ( unsafe :: slice ( s, byte_len ( from) , byte_len ( s) ) , from, to) ;
715
+ ret to + replace ( unsafe :: slice ( s, byte_len ( from) , byte_len ( s) ) ,
716
+ from, to) ;
716
717
} else {
717
718
let idx = find ( s, from) ;
718
719
if idx == -1 {
@@ -1401,7 +1402,8 @@ mod unsafe {
1401
1402
1402
1403
FIXME: rename to safe_range_byte_slice
1403
1404
*/
1404
- unsafe fn safe_slice ( s : str , begin : uint , end : uint ) : uint:: le( begin , end ) -> str {
1405
+ unsafe fn safe_slice ( s : str , begin : uint , end : uint )
1406
+ : uint:: le( begin , end ) -> str {
1405
1407
// would need some magic to make this a precondition
1406
1408
assert ( end <= byte_len ( s) ) ;
1407
1409
ret slice( s, begin, end) ;
@@ -1634,7 +1636,7 @@ mod tests {
1634
1636
}
1635
1637
1636
1638
#[ test]
1637
- fn test_slice ( ) {
1639
+ fn test_unsafe_slice ( ) unsafe {
1638
1640
assert ( eq ( "ab" , slice ( "abc" , 0 u, 2 u) ) ) ;
1639
1641
assert ( eq ( "bc" , slice ( "abc" , 1 u, 3 u) ) ) ;
1640
1642
assert ( eq ( "" , slice ( "abc" , 1 u, 1 u) ) ) ;
@@ -1651,7 +1653,7 @@ mod tests {
1651
1653
ret rs;
1652
1654
}
1653
1655
assert ( eq ( half_a_million_letter_a ( ) ,
1654
- slice ( a_million_letter_a ( ) , 0 u, 500000 u) ) ) ;
1656
+ unsafe :: slice ( a_million_letter_a ( ) , 0 u, 500000 u) ) ) ;
1655
1657
}
1656
1658
1657
1659
#[ test]
0 commit comments