@@ -114,7 +114,7 @@ export
114
114
escape_default,
115
115
escape_unicode,
116
116
117
- unsafe ,
117
+ raw ,
118
118
extensions,
119
119
StrSlice ,
120
120
UniqueStr ;
@@ -132,12 +132,12 @@ Section: Creating a string
132
132
*/
133
133
pure fn from_bytes ( vv : & [ const u8 ] ) -> ~str {
134
134
assert is_utf8 ( vv) ;
135
- return unsafe { unsafe :: from_bytes ( vv) } ;
135
+ return unsafe { raw :: from_bytes ( vv) } ;
136
136
}
137
137
138
138
/// Copy a slice into a new unique str
139
139
pure fn from_slice ( s : & str ) -> ~str {
140
- unsafe { unsafe :: slice_bytes ( s, 0 , len ( s) ) }
140
+ unsafe { raw :: slice_bytes ( s, 0 , len ( s) ) }
141
141
}
142
142
143
143
/**
@@ -219,7 +219,7 @@ fn push_char(&s: ~str, ch: char) {
219
219
}
220
220
}
221
221
222
- unsafe :: set_len ( s, new_len) ;
222
+ raw :: set_len ( s, new_len) ;
223
223
}
224
224
}
225
225
@@ -254,7 +254,7 @@ fn push_str_no_overallocate(&lhs: ~str, rhs: &str) {
254
254
ptr:: memcpy ( dst, rbuf, rlen) ;
255
255
}
256
256
}
257
- unsafe :: set_len( lhs, llen + rlen) ;
257
+ raw :: set_len( lhs, llen + rlen) ;
258
258
}
259
259
}
260
260
/// Appends a string slice to the back of a string
@@ -271,7 +271,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
271
271
ptr:: memcpy ( dst, rbuf, rlen) ;
272
272
}
273
273
}
274
- unsafe :: set_len( lhs, llen + rlen) ;
274
+ raw :: set_len( lhs, llen + rlen) ;
275
275
}
276
276
}
277
277
@@ -318,7 +318,7 @@ fn pop_char(&s: ~str) -> char {
318
318
let end = len ( s) ;
319
319
assert end > 0 u;
320
320
let { ch, prev} = char_range_at_reverse ( s, end) ;
321
- unsafe { unsafe :: set_len ( s, prev) ; }
321
+ unsafe { raw :: set_len ( s, prev) ; }
322
322
return ch;
323
323
}
324
324
@@ -331,7 +331,7 @@ fn pop_char(&s: ~str) -> char {
331
331
*/
332
332
fn shift_char ( & s: ~str ) -> char {
333
333
let { ch, next} = char_range_at ( s, 0 u) ;
334
- s = unsafe { unsafe :: slice_bytes ( s, next, len ( s) ) } ;
334
+ s = unsafe { raw :: slice_bytes ( s, next, len ( s) ) } ;
335
335
return ch;
336
336
}
337
337
@@ -347,7 +347,7 @@ fn shift_char(&s: ~str) -> char {
347
347
#[ inline]
348
348
fn view_shift_char ( s : & a/str ) -> ( char , & a/str ) {
349
349
let { ch, next} = char_range_at ( s, 0 u) ;
350
- let next_s = unsafe { unsafe :: view_bytes ( s, next, len ( s) ) } ;
350
+ let next_s = unsafe { raw :: view_bytes ( s, next, len ( s) ) } ;
351
351
return ( ch, next_s) ;
352
352
}
353
353
@@ -368,7 +368,7 @@ pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str {
368
368
369
369
match find ( s, |c| !chars_to_trim. contains ( c) ) {
370
370
None => ~"",
371
- Some ( first) => unsafe { unsafe :: slice_bytes ( s, first, s. len ( ) ) }
371
+ Some ( first) => unsafe { raw :: slice_bytes ( s, first, s. len ( ) ) }
372
372
}
373
373
}
374
374
@@ -388,7 +388,7 @@ pure fn trim_right_chars(s: &str, chars_to_trim: &[char]) -> ~str {
388
388
None => ~"",
389
389
Some ( last) => {
390
390
let { next, _} = char_range_at ( s, last) ;
391
- unsafe { unsafe :: slice_bytes ( s, 0 u, next) }
391
+ unsafe { raw :: slice_bytes ( s, 0 u, next) }
392
392
}
393
393
}
394
394
}
@@ -410,7 +410,7 @@ pure fn trim_chars(s: &str, chars_to_trim: &[char]) -> ~str {
410
410
pure fn trim_left ( s : & str ) -> ~str {
411
411
match find ( s, |c| !char:: is_whitespace ( c) ) {
412
412
None => ~"",
413
- Some ( first) => unsafe { unsafe :: slice_bytes ( s, first, len ( s) ) }
413
+ Some ( first) => unsafe { raw :: slice_bytes ( s, first, len ( s) ) }
414
414
}
415
415
}
416
416
@@ -420,7 +420,7 @@ pure fn trim_right(s: &str) -> ~str {
420
420
None => ~"",
421
421
Some ( last) => {
422
422
let { next, _} = char_range_at ( s, last) ;
423
- unsafe { unsafe :: slice_bytes ( s, 0 u, next) }
423
+ unsafe { raw :: slice_bytes ( s, 0 u, next) }
424
424
}
425
425
}
426
426
}
@@ -482,7 +482,7 @@ pure fn substr(s: &str, begin: uint, n: uint) -> ~str {
482
482
pure fn slice ( s : & str , begin : uint , end : uint ) -> ~str {
483
483
assert is_char_boundary ( s, begin) ;
484
484
assert is_char_boundary ( s, end) ;
485
- unsafe { unsafe :: slice_bytes ( s, begin, end) }
485
+ unsafe { raw :: slice_bytes ( s, begin, end) }
486
486
}
487
487
488
488
/**
@@ -494,7 +494,7 @@ pure fn slice(s: &str, begin: uint, end: uint) -> ~str {
494
494
pure fn view ( s : & a/str , begin : uint , end : uint ) -> & a/str {
495
495
assert is_char_boundary ( s, begin) ;
496
496
assert is_char_boundary ( s, end) ;
497
- unsafe { unsafe :: view_bytes ( s, begin, end) }
497
+ unsafe { raw :: view_bytes ( s, begin, end) }
498
498
}
499
499
500
500
/// Splits a string into substrings at each occurrence of a given character
@@ -527,15 +527,15 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
527
527
if s[ i] == b {
528
528
if allow_empty || start < i unchecked {
529
529
vec:: push ( result,
530
- unsafe { unsafe :: slice_bytes ( s, start, i) } ) ;
530
+ unsafe { raw :: slice_bytes ( s, start, i) } ) ;
531
531
}
532
532
start = i + 1 u;
533
533
done += 1 u;
534
534
}
535
535
i += 1 u;
536
536
}
537
537
if allow_empty || start < l {
538
- unsafe { vec:: push ( result, unsafe :: slice_bytes ( s, start, l) ) } ;
538
+ unsafe { vec:: push ( result, raw :: slice_bytes ( s, start, l) ) } ;
539
539
}
540
540
move result
541
541
} else {
@@ -570,15 +570,15 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
570
570
let { ch, next} = char_range_at ( s, i) ;
571
571
if sepfn ( ch) {
572
572
if allow_empty || start < i unchecked {
573
- vec:: push ( result, unsafe { unsafe :: slice_bytes ( s, start, i) } ) ;
573
+ vec:: push ( result, unsafe { raw :: slice_bytes ( s, start, i) } ) ;
574
574
}
575
575
start = next;
576
576
done += 1 u;
577
577
}
578
578
i = next;
579
579
}
580
580
if allow_empty || start < l unchecked {
581
- vec:: push ( result, unsafe { unsafe :: slice_bytes ( s, start, l) } ) ;
581
+ vec:: push ( result, unsafe { raw :: slice_bytes ( s, start, l) } ) ;
582
582
}
583
583
move result
584
584
}
@@ -632,7 +632,7 @@ pure fn iter_between_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) {
632
632
pure fn split_str ( s : & a/str , sep : & b/str ) -> ~[ ~str ] {
633
633
let mut result = ~[ ] ;
634
634
do iter_between_matches ( s, sep) |from, to| {
635
- unsafe { vec:: push ( result, unsafe :: slice_bytes ( s, from, to) ) ; }
635
+ unsafe { vec:: push ( result, raw :: slice_bytes ( s, from, to) ) ; }
636
636
}
637
637
move result
638
638
}
@@ -641,7 +641,7 @@ pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] {
641
641
let mut result = ~[ ] ;
642
642
do iter_between_matches ( s, sep) |from, to| {
643
643
if to > from {
644
- unsafe { vec:: push ( result, unsafe :: slice_bytes ( s, from, to) ) ; }
644
+ unsafe { vec:: push ( result, raw :: slice_bytes ( s, from, to) ) ; }
645
645
}
646
646
}
647
647
move result
@@ -661,7 +661,7 @@ pure fn lines_any(s: &str) -> ~[~str] {
661
661
let l = len ( s) ;
662
662
let mut cp = copy s;
663
663
if l > 0 u && s[ l - 1 u] == '\r' as u8 {
664
- unsafe { unsafe :: set_len ( cp, l - 1 u) ; }
664
+ unsafe { raw :: set_len ( cp, l - 1 u) ; }
665
665
}
666
666
move cp
667
667
} )
@@ -703,7 +703,7 @@ pure fn replace(s: &str, from: &str, to: &str) -> ~str {
703
703
let mut result = ~"", first = true ;
704
704
do iter_between_matches ( s, from) |start, end| {
705
705
if first { first = false ; } else { unchecked { push_str( result, to) ; } }
706
- unsafe { push_str ( result, unsafe :: slice_bytes ( s, start, end) ) ; }
706
+ unsafe { push_str ( result, raw :: slice_bytes ( s, start, end) ) ; }
707
707
}
708
708
move result
709
709
}
@@ -1963,7 +1963,7 @@ pure fn escape_unicode(s: &str) -> ~str {
1963
1963
}
1964
1964
1965
1965
/// Unsafe operations
1966
- mod unsafe {
1966
+ mod raw {
1967
1967
export
1968
1968
from_buf,
1969
1969
from_buf_len,
@@ -2029,7 +2029,7 @@ mod unsafe {
2029
2029
}
2030
2030
2031
2031
/// Converts a byte to a string.
2032
- unsafe fn from_byte ( u : u8 ) -> ~str { unsafe :: from_bytes ( [ u] ) }
2032
+ unsafe fn from_byte ( u : u8 ) -> ~str { raw :: from_bytes ( [ u] ) }
2033
2033
2034
2034
/**
2035
2035
* Takes a bytewise (not UTF-8) slice from a string.
@@ -2112,7 +2112,7 @@ mod unsafe {
2112
2112
let len = len ( s) ;
2113
2113
assert ( len > 0 u) ;
2114
2114
let b = s[ 0 ] ;
2115
- s = unsafe { unsafe :: slice_bytes ( s, 1 u, len) } ;
2115
+ s = unsafe { raw :: slice_bytes ( s, 1 u, len) } ;
2116
2116
return b;
2117
2117
}
2118
2118
@@ -2646,9 +2646,9 @@ mod tests {
2646
2646
#[ test]
2647
2647
fn test_unsafe_slice ( ) {
2648
2648
unsafe {
2649
- assert ~"ab" == unsafe :: slice_bytes ( ~"abc", 0 u, 2 u) ;
2650
- assert ~"bc" == unsafe :: slice_bytes ( ~"abc", 1 u, 3 u) ;
2651
- assert ~"" == unsafe :: slice_bytes ( ~"abc", 1 u, 1 u) ;
2649
+ assert ~"ab" == raw :: slice_bytes ( ~"abc", 0 u, 2 u) ;
2650
+ assert ~"bc" == raw :: slice_bytes ( ~"abc", 1 u, 3 u) ;
2651
+ assert ~"" == raw :: slice_bytes ( ~"abc", 1 u, 1 u) ;
2652
2652
fn a_million_letter_a ( ) -> ~str {
2653
2653
let mut i = 0 ;
2654
2654
let mut rs = ~"";
@@ -2662,7 +2662,7 @@ mod tests {
2662
2662
return rs;
2663
2663
}
2664
2664
assert half_a_million_letter_a ( ) ==
2665
- unsafe :: slice_bytes ( a_million_letter_a ( ) , 0 u, 500000 u) ;
2665
+ raw :: slice_bytes ( a_million_letter_a ( ) , 0 u, 500000 u) ;
2666
2666
}
2667
2667
}
2668
2668
@@ -2881,23 +2881,23 @@ mod tests {
2881
2881
#[ test]
2882
2882
fn test_shift_byte ( ) {
2883
2883
let mut s = ~"ABC ";
2884
- let b = unsafe { unsafe :: shift_byte ( s) } ;
2884
+ let b = unsafe { raw :: shift_byte ( s) } ;
2885
2885
assert ( s == ~"BC ") ;
2886
2886
assert ( b == 65u8 ) ;
2887
2887
}
2888
2888
2889
2889
#[ test]
2890
2890
fn test_pop_byte ( ) {
2891
2891
let mut s = ~"ABC ";
2892
- let b = unsafe { unsafe :: pop_byte ( s) } ;
2892
+ let b = unsafe { raw :: pop_byte ( s) } ;
2893
2893
assert ( s == ~"AB ") ;
2894
2894
assert ( b == 67u8 ) ;
2895
2895
}
2896
2896
2897
2897
#[ test]
2898
2898
fn test_unsafe_from_bytes ( ) {
2899
2899
let a = ~[ 65u8 , 65u8 , 65u8 , 65u8 , 65u8 , 65u8 , 65u8 ] ;
2900
- let b = unsafe { unsafe :: from_bytes ( a) } ;
2900
+ let b = unsafe { raw :: from_bytes ( a) } ;
2901
2901
assert ( b == ~"AAAAAAA ") ;
2902
2902
}
2903
2903
@@ -2941,7 +2941,7 @@ mod tests {
2941
2941
unsafe {
2942
2942
let a = ~[ 65u8 , 65u8 , 65u8 , 65u8 , 65u8 , 65u8 , 65u8 , 0u8 ] ;
2943
2943
let b = vec:: raw:: to_ptr ( a) ;
2944
- let c = unsafe :: from_buf ( b) ;
2944
+ let c = raw :: from_buf ( b) ;
2945
2945
assert ( c == ~"AAAAAAA ") ;
2946
2946
}
2947
2947
}
@@ -2979,7 +2979,7 @@ mod tests {
2979
2979
unsafe {
2980
2980
let s = ~"hello";
2981
2981
let sb = as_buf ( s, |b, _l| b) ;
2982
- let s_cstr = unsafe :: from_buf ( sb) ;
2982
+ let s_cstr = raw :: from_buf ( sb) ;
2983
2983
assert s_cstr == s;
2984
2984
}
2985
2985
}
0 commit comments