Skip to content

Commit 308ca06

Browse files
committed
Rename str::unsafe to str::raw
1 parent 59c3c6c commit 308ca06

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

src/libcore/int-template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl T : FromStr {
170170
fn to_str(n: T, radix: uint) -> ~str {
171171
do to_str_bytes(n, radix) |slice| {
172172
do vec::as_buf(slice) |p, len| {
173-
unsafe { str::unsafe::from_buf_len(p, len) }
173+
unsafe { str::raw::from_buf_len(p, len) }
174174
}
175175
}
176176
}

src/libcore/os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
6969
let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
7070
do vec::as_mut_buf(buf) |b, sz| {
7171
if f(b, sz as size_t) unsafe {
72-
Some(str::unsafe::from_buf(b as *u8))
72+
Some(str::raw::from_buf(b as *u8))
7373
} else {
7474
None
7575
}
@@ -226,7 +226,7 @@ mod global_env {
226226
option::None::<~str>
227227
} else {
228228
let s = unsafe::reinterpret_cast(&s);
229-
option::Some::<~str>(str::unsafe::from_buf(s))
229+
option::Some::<~str>(str::raw::from_buf(s))
230230
};
231231
}
232232
}

src/libcore/str.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export
114114
escape_default,
115115
escape_unicode,
116116

117-
unsafe,
117+
raw,
118118
extensions,
119119
StrSlice,
120120
UniqueStr;
@@ -132,12 +132,12 @@ Section: Creating a string
132132
*/
133133
pure fn from_bytes(vv: &[const u8]) -> ~str {
134134
assert is_utf8(vv);
135-
return unsafe { unsafe::from_bytes(vv) };
135+
return unsafe { raw::from_bytes(vv) };
136136
}
137137

138138
/// Copy a slice into a new unique str
139139
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)) }
141141
}
142142

143143
/**
@@ -219,7 +219,7 @@ fn push_char(&s: ~str, ch: char) {
219219
}
220220
}
221221

222-
unsafe::set_len(s, new_len);
222+
raw::set_len(s, new_len);
223223
}
224224
}
225225

@@ -254,7 +254,7 @@ fn push_str_no_overallocate(&lhs: ~str, rhs: &str) {
254254
ptr::memcpy(dst, rbuf, rlen);
255255
}
256256
}
257-
unsafe::set_len(lhs, llen + rlen);
257+
raw::set_len(lhs, llen + rlen);
258258
}
259259
}
260260
/// Appends a string slice to the back of a string
@@ -271,7 +271,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
271271
ptr::memcpy(dst, rbuf, rlen);
272272
}
273273
}
274-
unsafe::set_len(lhs, llen + rlen);
274+
raw::set_len(lhs, llen + rlen);
275275
}
276276
}
277277

@@ -318,7 +318,7 @@ fn pop_char(&s: ~str) -> char {
318318
let end = len(s);
319319
assert end > 0u;
320320
let {ch, prev} = char_range_at_reverse(s, end);
321-
unsafe { unsafe::set_len(s, prev); }
321+
unsafe { raw::set_len(s, prev); }
322322
return ch;
323323
}
324324

@@ -331,7 +331,7 @@ fn pop_char(&s: ~str) -> char {
331331
*/
332332
fn shift_char(&s: ~str) -> char {
333333
let {ch, next} = char_range_at(s, 0u);
334-
s = unsafe { unsafe::slice_bytes(s, next, len(s)) };
334+
s = unsafe { raw::slice_bytes(s, next, len(s)) };
335335
return ch;
336336
}
337337

@@ -347,7 +347,7 @@ fn shift_char(&s: ~str) -> char {
347347
#[inline]
348348
fn view_shift_char(s: &a/str) -> (char, &a/str) {
349349
let {ch, next} = char_range_at(s, 0u);
350-
let next_s = unsafe { unsafe::view_bytes(s, next, len(s)) };
350+
let next_s = unsafe { raw::view_bytes(s, next, len(s)) };
351351
return (ch, next_s);
352352
}
353353

@@ -368,7 +368,7 @@ pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str {
368368

369369
match find(s, |c| !chars_to_trim.contains(c)) {
370370
None => ~"",
371-
Some(first) => unsafe { unsafe::slice_bytes(s, first, s.len()) }
371+
Some(first) => unsafe { raw::slice_bytes(s, first, s.len()) }
372372
}
373373
}
374374

@@ -388,7 +388,7 @@ pure fn trim_right_chars(s: &str, chars_to_trim: &[char]) -> ~str {
388388
None => ~"",
389389
Some(last) => {
390390
let {next, _} = char_range_at(s, last);
391-
unsafe { unsafe::slice_bytes(s, 0u, next) }
391+
unsafe { raw::slice_bytes(s, 0u, next) }
392392
}
393393
}
394394
}
@@ -410,7 +410,7 @@ pure fn trim_chars(s: &str, chars_to_trim: &[char]) -> ~str {
410410
pure fn trim_left(s: &str) -> ~str {
411411
match find(s, |c| !char::is_whitespace(c)) {
412412
None => ~"",
413-
Some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) }
413+
Some(first) => unsafe { raw::slice_bytes(s, first, len(s)) }
414414
}
415415
}
416416

@@ -420,7 +420,7 @@ pure fn trim_right(s: &str) -> ~str {
420420
None => ~"",
421421
Some(last) => {
422422
let {next, _} = char_range_at(s, last);
423-
unsafe { unsafe::slice_bytes(s, 0u, next) }
423+
unsafe { raw::slice_bytes(s, 0u, next) }
424424
}
425425
}
426426
}
@@ -482,7 +482,7 @@ pure fn substr(s: &str, begin: uint, n: uint) -> ~str {
482482
pure fn slice(s: &str, begin: uint, end: uint) -> ~str {
483483
assert is_char_boundary(s, begin);
484484
assert is_char_boundary(s, end);
485-
unsafe { unsafe::slice_bytes(s, begin, end) }
485+
unsafe { raw::slice_bytes(s, begin, end) }
486486
}
487487

488488
/**
@@ -494,7 +494,7 @@ pure fn slice(s: &str, begin: uint, end: uint) -> ~str {
494494
pure fn view(s: &a/str, begin: uint, end: uint) -> &a/str {
495495
assert is_char_boundary(s, begin);
496496
assert is_char_boundary(s, end);
497-
unsafe { unsafe::view_bytes(s, begin, end) }
497+
unsafe { raw::view_bytes(s, begin, end) }
498498
}
499499

500500
/// 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)
527527
if s[i] == b {
528528
if allow_empty || start < i unchecked {
529529
vec::push(result,
530-
unsafe { unsafe::slice_bytes(s, start, i) });
530+
unsafe { raw::slice_bytes(s, start, i) });
531531
}
532532
start = i + 1u;
533533
done += 1u;
534534
}
535535
i += 1u;
536536
}
537537
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) ) };
539539
}
540540
move result
541541
} else {
@@ -570,15 +570,15 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
570570
let {ch, next} = char_range_at(s, i);
571571
if sepfn(ch) {
572572
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)});
574574
}
575575
start = next;
576576
done += 1u;
577577
}
578578
i = next;
579579
}
580580
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) });
582582
}
583583
move result
584584
}
@@ -632,7 +632,7 @@ pure fn iter_between_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) {
632632
pure fn split_str(s: &a/str, sep: &b/str) -> ~[~str] {
633633
let mut result = ~[];
634634
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)); }
636636
}
637637
move result
638638
}
@@ -641,7 +641,7 @@ pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] {
641641
let mut result = ~[];
642642
do iter_between_matches(s, sep) |from, to| {
643643
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)); }
645645
}
646646
}
647647
move result
@@ -661,7 +661,7 @@ pure fn lines_any(s: &str) -> ~[~str] {
661661
let l = len(s);
662662
let mut cp = copy s;
663663
if l > 0u && s[l - 1u] == '\r' as u8 {
664-
unsafe { unsafe::set_len(cp, l - 1u); }
664+
unsafe { raw::set_len(cp, l - 1u); }
665665
}
666666
move cp
667667
})
@@ -703,7 +703,7 @@ pure fn replace(s: &str, from: &str, to: &str) -> ~str {
703703
let mut result = ~"", first = true;
704704
do iter_between_matches(s, from) |start, end| {
705705
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)); }
707707
}
708708
move result
709709
}
@@ -1963,7 +1963,7 @@ pure fn escape_unicode(s: &str) -> ~str {
19631963
}
19641964

19651965
/// Unsafe operations
1966-
mod unsafe {
1966+
mod raw {
19671967
export
19681968
from_buf,
19691969
from_buf_len,
@@ -2029,7 +2029,7 @@ mod unsafe {
20292029
}
20302030

20312031
/// 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]) }
20332033

20342034
/**
20352035
* Takes a bytewise (not UTF-8) slice from a string.
@@ -2112,7 +2112,7 @@ mod unsafe {
21122112
let len = len(s);
21132113
assert (len > 0u);
21142114
let b = s[0];
2115-
s = unsafe { unsafe::slice_bytes(s, 1u, len) };
2115+
s = unsafe { raw::slice_bytes(s, 1u, len) };
21162116
return b;
21172117
}
21182118

@@ -2646,9 +2646,9 @@ mod tests {
26462646
#[test]
26472647
fn test_unsafe_slice() {
26482648
unsafe {
2649-
assert ~"ab" == unsafe::slice_bytes(~"abc", 0u, 2u);
2650-
assert ~"bc" == unsafe::slice_bytes(~"abc", 1u, 3u);
2651-
assert ~"" == unsafe::slice_bytes(~"abc", 1u, 1u);
2649+
assert ~"ab" == raw::slice_bytes(~"abc", 0u, 2u);
2650+
assert ~"bc" == raw::slice_bytes(~"abc", 1u, 3u);
2651+
assert ~"" == raw::slice_bytes(~"abc", 1u, 1u);
26522652
fn a_million_letter_a() -> ~str {
26532653
let mut i = 0;
26542654
let mut rs = ~"";
@@ -2662,7 +2662,7 @@ mod tests {
26622662
return rs;
26632663
}
26642664
assert half_a_million_letter_a() ==
2665-
unsafe::slice_bytes(a_million_letter_a(), 0u, 500000u);
2665+
raw::slice_bytes(a_million_letter_a(), 0u, 500000u);
26662666
}
26672667
}
26682668

@@ -2881,23 +2881,23 @@ mod tests {
28812881
#[test]
28822882
fn test_shift_byte() {
28832883
let mut s = ~"ABC";
2884-
let b = unsafe { unsafe::shift_byte(s) };
2884+
let b = unsafe { raw::shift_byte(s) };
28852885
assert (s == ~"BC");
28862886
assert (b == 65u8);
28872887
}
28882888

28892889
#[test]
28902890
fn test_pop_byte() {
28912891
let mut s = ~"ABC";
2892-
let b = unsafe { unsafe::pop_byte(s) };
2892+
let b = unsafe { raw::pop_byte(s) };
28932893
assert (s == ~"AB");
28942894
assert (b == 67u8);
28952895
}
28962896

28972897
#[test]
28982898
fn test_unsafe_from_bytes() {
28992899
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) };
29012901
assert (b == ~"AAAAAAA");
29022902
}
29032903

@@ -2941,7 +2941,7 @@ mod tests {
29412941
unsafe {
29422942
let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
29432943
let b = vec::raw::to_ptr(a);
2944-
let c = unsafe::from_buf(b);
2944+
let c = raw::from_buf(b);
29452945
assert (c == ~"AAAAAAA");
29462946
}
29472947
}
@@ -2979,7 +2979,7 @@ mod tests {
29792979
unsafe {
29802980
let s = ~"hello";
29812981
let sb = as_buf(s, |b, _l| b);
2982-
let s_cstr = unsafe::from_buf(sb);
2982+
let s_cstr = raw::from_buf(sb);
29832983
assert s_cstr == s;
29842984
}
29852985
}

src/libcore/uint-template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn from_str_radix(buf: &str, radix: u64) -> Option<u64> {
175175
pure fn to_str(num: T, radix: uint) -> ~str {
176176
do to_str_bytes(false, num, radix) |slice| {
177177
do vec::as_buf(slice) |p, len| {
178-
unsafe { str::unsafe::from_buf_len(p, len) }
178+
unsafe { str::raw::from_buf_len(p, len) }
179179
}
180180
}
181181
}

src/libstd/uv_ll.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ unsafe fn ip4_name(src: &sockaddr_in) -> ~str {
834834
// to see if it is the string representation of
835835
// INADDR_NONE (0xffffffff or 255.255.255.255 on
836836
// many platforms)
837-
str::unsafe::from_buf(dst_buf)
837+
str::raw::from_buf(dst_buf)
838838
}
839839
}
840840
unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
@@ -852,7 +852,7 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
852852
let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr,
853853
dst_buf, size as libc::size_t);
854854
match result {
855-
0i32 => str::unsafe::from_buf(dst_buf),
855+
0i32 => str::raw::from_buf(dst_buf),
856856
_ => ~""
857857
}
858858
}
@@ -962,17 +962,17 @@ unsafe fn free_base_of_buf(buf: uv_buf_t) {
962962
unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str {
963963
let err = last_error(uv_loop);
964964
let err_ptr = ptr::addr_of(err);
965-
let err_name = str::unsafe::from_c_str(err_name(err_ptr));
966-
let err_msg = str::unsafe::from_c_str(strerror(err_ptr));
965+
let err_name = str::raw::from_c_str(err_name(err_ptr));
966+
let err_msg = str::raw::from_c_str(strerror(err_ptr));
967967
return fmt!("LIBUV ERROR: name: %s msg: %s",
968968
err_name, err_msg);
969969
}
970970

971971
unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data {
972972
let err = last_error(uv_loop);
973973
let err_ptr = ptr::addr_of(err);
974-
let err_name = str::unsafe::from_c_str(err_name(err_ptr));
975-
let err_msg = str::unsafe::from_c_str(strerror(err_ptr));
974+
let err_name = str::raw::from_c_str(err_name(err_ptr));
975+
let err_msg = str::raw::from_c_str(strerror(err_ptr));
976976
{ err_name: err_name, err_msg: err_msg }
977977
}
978978

src/rustc/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn llvm_err(sess: session, msg: ~str) -> ! unsafe {
3737
let cstr = llvm::LLVMRustGetLastError();
3838
if cstr == ptr::null() {
3939
sess.fatal(msg);
40-
} else { sess.fatal(msg + ~": " + str::unsafe::from_c_str(cstr)); }
40+
} else { sess.fatal(msg + ~": " + str::raw::from_c_str(cstr)); }
4141
}
4242
4343
fn WriteOutputFile(sess:session,

src/rustc/metadata/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn get_metadata_section(os: os,
181181
let si = mk_section_iter(of.llof);
182182
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
183183
let name_buf = llvm::LLVMGetSectionName(si.llsi);
184-
let name = unsafe { str::unsafe::from_c_str(name_buf) };
184+
let name = unsafe { str::raw::from_c_str(name_buf) };
185185
if name == meta_section_name(os) {
186186
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
187187
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;

0 commit comments

Comments
 (0)