Rename (again) str::unsafe::slice -> str::unsafe::slice_bytes and
str::unsafe::safe_slice -> str::unsafe::slice_bytes_safe_range
This commit is contained in:
parent
01c01f68af
commit
8f367ebfeb
@ -596,8 +596,8 @@ fn cmd_install(c: cargo, argv: [str]) unsafe {
|
||||
let uuid = rest(target, 5u);
|
||||
let idx = str::index(uuid, '/' as u8);
|
||||
if idx != -1 {
|
||||
let source = str::unsafe::slice(uuid, 0u, idx as uint);
|
||||
uuid = str::unsafe::slice(uuid, idx as uint + 1u,
|
||||
let source = str::unsafe::slice_bytes(uuid, 0u, idx as uint);
|
||||
uuid = str::unsafe::slice_bytes(uuid, idx as uint + 1u,
|
||||
str::byte_len(uuid));
|
||||
install_uuid_specific(c, wd, source, uuid);
|
||||
} else {
|
||||
@ -607,8 +607,8 @@ fn cmd_install(c: cargo, argv: [str]) unsafe {
|
||||
let name = target;
|
||||
let idx = str::index(name, '/' as u8);
|
||||
if idx != -1 {
|
||||
let source = str::unsafe::slice(name, 0u, idx as uint);
|
||||
name = str::unsafe::slice(name, idx as uint + 1u,
|
||||
let source = str::unsafe::slice_bytes(name, 0u, idx as uint);
|
||||
name = str::unsafe::slice_bytes(name, idx as uint + 1u,
|
||||
str::byte_len(name));
|
||||
install_named_specific(c, wd, source, name);
|
||||
} else {
|
||||
|
@ -570,7 +570,7 @@ fn link_binary(sess: session,
|
||||
(config.os == session::os_linux ||
|
||||
config.os == session::os_freebsd) &&
|
||||
str::find(filename, "lib") == 0 {
|
||||
ret str::unsafe::slice(filename, 3u,
|
||||
ret str::unsafe::slice_bytes(filename, 3u,
|
||||
str::byte_len(filename));
|
||||
} else { ret filename; }
|
||||
};
|
||||
|
@ -168,7 +168,7 @@ fn create_compile_unit(cx: @crate_ctxt, full_path: str)
|
||||
|
||||
let work_dir = cx.sess.working_dir;
|
||||
let file_path = if str::starts_with(full_path, work_dir) {
|
||||
str::unsafe::slice(full_path, str::byte_len(work_dir),
|
||||
str::unsafe::slice_bytes(full_path, str::byte_len(work_dir),
|
||||
str::byte_len(full_path))
|
||||
} else {
|
||||
full_path
|
||||
|
@ -118,11 +118,11 @@ fn get_line(fm: filemap, line: int) -> str unsafe {
|
||||
// parsed. If we just slice the rest of the string, we'll print out
|
||||
// the remainder of the file, which is undesirable.
|
||||
end = str::byte_len(*fm.src);
|
||||
let rest = str::unsafe::slice(*fm.src, begin, end);
|
||||
let rest = str::unsafe::slice_bytes(*fm.src, begin, end);
|
||||
let newline = str::index(rest, '\n' as u8);
|
||||
if newline != -1 { end = begin + (newline as uint); }
|
||||
}
|
||||
ret str::unsafe::slice(*fm.src, begin, end);
|
||||
ret str::unsafe::slice_bytes(*fm.src, begin, end);
|
||||
}
|
||||
|
||||
fn get_filemap(cm: codemap, filename: str) -> filemap {
|
||||
|
@ -27,7 +27,7 @@ impl reader for reader {
|
||||
fn get_str_from(start: uint) -> str unsafe {
|
||||
// I'm pretty skeptical about this subtraction. What if there's a
|
||||
// multi-byte character before the mark?
|
||||
ret str::unsafe::slice(*self.src, start - 1u, self.pos - 1u);
|
||||
ret str::unsafe::slice_bytes(*self.src, start - 1u, self.pos - 1u);
|
||||
}
|
||||
fn next() -> char {
|
||||
if self.pos < self.len {
|
||||
@ -584,7 +584,7 @@ fn trim_whitespace_prefix_and_push_line(&lines: [str],
|
||||
let s1;
|
||||
if all_whitespace(s, 0u, col) {
|
||||
if col < str::byte_len(s) {
|
||||
s1 = str::unsafe::slice(s, col, str::byte_len(s));
|
||||
s1 = str::unsafe::slice_bytes(s, col, str::byte_len(s));
|
||||
} else { s1 = ""; }
|
||||
} else { s1 = s; }
|
||||
log(debug, "pushing line: " + s1);
|
||||
|
@ -41,11 +41,11 @@ fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
|
||||
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||
let start_kind = idx;
|
||||
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
|
||||
let kind = str::to_lower(str::unsafe::slice(line, start_kind, idx));
|
||||
let kind = str::to_lower(str::unsafe::slice_bytes(line, start_kind, idx));
|
||||
|
||||
// Extract msg:
|
||||
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||
let msg = str::unsafe::slice(line, idx, len);
|
||||
let msg = str::unsafe::slice_bytes(line, idx, len);
|
||||
|
||||
#debug("line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg);
|
||||
|
||||
|
@ -109,7 +109,7 @@ fn parse_name_value_directive(line: str,
|
||||
if str::find(line, keycolon) >= 0 {
|
||||
let colon = str::find(line, keycolon) as uint;
|
||||
let value =
|
||||
str::unsafe::slice(line, colon + str::byte_len(keycolon),
|
||||
str::unsafe::slice_bytes(line, colon + str::byte_len(keycolon),
|
||||
str::byte_len(line));
|
||||
#debug("%s: %s", directive, value);
|
||||
option::some(value)
|
||||
|
@ -286,7 +286,7 @@ fn check_variants_T<T: copy>(
|
||||
fn last_part(filename: str) -> str unsafe {
|
||||
let ix = str::rindex(filename, 47u8 /* '/' */);
|
||||
assert ix >= 0;
|
||||
str::unsafe::slice(filename, ix as uint + 1u, str::byte_len(filename) - 3u)
|
||||
str::unsafe::slice_bytes(filename, ix as uint + 1u, str::byte_len(filename) - 3u)
|
||||
}
|
||||
|
||||
enum happiness { passed, cleanly_rejected(str), known_bug(str), failed(str), }
|
||||
|
@ -38,8 +38,6 @@ export
|
||||
chars,
|
||||
substr,
|
||||
char_slice,
|
||||
//slice,
|
||||
//safe_slice,
|
||||
split,
|
||||
splitn,
|
||||
split_str,
|
||||
@ -425,7 +423,7 @@ Failure:
|
||||
If `begin` + `len` is is greater than the byte length of the string
|
||||
*/
|
||||
fn substr(s: str, begin: uint, len: uint) -> str unsafe {
|
||||
ret unsafe::slice(s, begin, begin + len);
|
||||
ret unsafe::slice_bytes(s, begin, begin + len);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -446,48 +444,6 @@ fn char_slice(s: str, begin: uint, end: uint) -> str {
|
||||
from_chars(vec::slice(chars(s), begin, end))
|
||||
}
|
||||
|
||||
/*
|
||||
Function: slice
|
||||
|
||||
Takes a bytewise slice from a string. Returns the substring from
|
||||
[`begin`..`end`).
|
||||
|
||||
This function is not unicode-safe.
|
||||
|
||||
Failure:
|
||||
|
||||
- If begin is greater than end.
|
||||
- If end is greater than the length of the string.
|
||||
|
||||
FIXME: rename to slice_byte or slice_byte_unsafe
|
||||
*/
|
||||
fn slice(s: str, begin: uint, end: uint) -> str unsafe {
|
||||
// FIXME: Typestate precondition
|
||||
assert (begin <= end);
|
||||
assert (end <= byte_len(s));
|
||||
|
||||
let v: [u8] = ::unsafe::reinterpret_cast(s);
|
||||
let v2 = vec::slice(v, begin, end);
|
||||
::unsafe::leak(v);
|
||||
v2 += [0u8];
|
||||
let s2: str = ::unsafe::reinterpret_cast(v2);
|
||||
::unsafe::leak(v2);
|
||||
ret s2;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: safe_slice
|
||||
|
||||
FIXME: make sure char_slice / slice / byte_slice
|
||||
have these preconditions and assertions
|
||||
FIXME: this shouldn't be mistaken for a UTF-8 safe slice
|
||||
*/
|
||||
fn safe_slice(s: str, begin: uint, end: uint) : uint::le(begin, end) -> str {
|
||||
// would need some magic to make this a precondition
|
||||
assert (end <= byte_len(s));
|
||||
ret slice(s, begin, end);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: split
|
||||
|
||||
@ -712,7 +668,7 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe {
|
||||
if byte_len(s) == 0u {
|
||||
ret "";
|
||||
} else if starts_with(s, from) {
|
||||
ret to + replace(unsafe::slice(s, byte_len(from), byte_len(s)),
|
||||
ret to + replace(unsafe::slice_bytes(s, byte_len(from), byte_len(s)),
|
||||
from, to);
|
||||
} else {
|
||||
let idx = find(s, from);
|
||||
@ -1348,8 +1304,8 @@ mod unsafe {
|
||||
// UNSAFE
|
||||
from_bytes,
|
||||
from_byte,
|
||||
slice,
|
||||
safe_slice;
|
||||
slice_bytes,
|
||||
slice_bytes_safe_range;
|
||||
|
||||
// Function: unsafe::from_bytes
|
||||
//
|
||||
@ -1371,19 +1327,15 @@ mod unsafe {
|
||||
/*
|
||||
Function: slice
|
||||
|
||||
Takes a bytewise slice from a string. Returns the substring from
|
||||
[`begin`..`end`).
|
||||
|
||||
This function is not unicode-safe.
|
||||
Takes a bytewise (not UTF-8) slice from a string.
|
||||
Returns the substring from [`begin`..`end`).
|
||||
|
||||
Failure:
|
||||
|
||||
- If begin is greater than end.
|
||||
- If end is greater than the length of the string.
|
||||
|
||||
FIXME: rename to byte_slice
|
||||
*/
|
||||
unsafe fn slice(s: str, begin: uint, end: uint) -> str unsafe {
|
||||
unsafe fn slice_bytes(s: str, begin: uint, end: uint) -> str unsafe {
|
||||
// FIXME: Typestate precondition
|
||||
assert (begin <= end);
|
||||
assert (end <= byte_len(s));
|
||||
@ -1398,15 +1350,15 @@ mod unsafe {
|
||||
}
|
||||
|
||||
/*
|
||||
Function: safe_slice
|
||||
Function: slice_bytes_safe_range
|
||||
|
||||
FIXME: rename to safe_range_byte_slice
|
||||
Like slice_bytes, with a precondition
|
||||
*/
|
||||
unsafe fn safe_slice(s: str, begin: uint, end: uint)
|
||||
unsafe fn slice_bytes_safe_range(s: str, begin: uint, end: uint)
|
||||
: uint::le(begin, end) -> str {
|
||||
// would need some magic to make this a precondition
|
||||
assert (end <= byte_len(s));
|
||||
ret slice(s, begin, end);
|
||||
ret slice_bytes(s, begin, end);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1653,7 +1605,7 @@ mod tests {
|
||||
ret rs;
|
||||
}
|
||||
assert (eq(half_a_million_letter_a(),
|
||||
unsafe::slice(a_million_letter_a(), 0u, 500000u)));
|
||||
unsafe::slice_bytes(a_million_letter_a(), 0u, 500000u)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -71,7 +71,7 @@ fn basename(p: path) -> path unsafe {
|
||||
}
|
||||
let len = str::byte_len(p);
|
||||
if i + 1 as uint >= len { ret p; }
|
||||
ret str::unsafe::slice(p, i + 1 as uint, len);
|
||||
ret str::unsafe::slice_bytes(p, i + 1 as uint, len);
|
||||
}
|
||||
|
||||
|
||||
|
@ -229,14 +229,15 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
|
||||
let names;
|
||||
let i_arg = option::none::<str>;
|
||||
if cur[1] == '-' as u8 {
|
||||
let tail = str::unsafe::slice(cur, 2u, curlen);
|
||||
let tail = str::unsafe::slice_bytes(cur, 2u, curlen);
|
||||
let eq = str::index(tail, '=' as u8);
|
||||
if eq == -1 {
|
||||
names = [long(tail)];
|
||||
} else {
|
||||
names = [long(str::unsafe::slice(tail, 0u, eq as uint))];
|
||||
names =
|
||||
[long(str::unsafe::slice_bytes(tail,0u,eq as uint))];
|
||||
i_arg =
|
||||
option::some::<str>(str::unsafe::slice(tail,
|
||||
option::some::<str>(str::unsafe::slice_bytes(tail,
|
||||
(eq as uint) + 1u,
|
||||
curlen - 2u));
|
||||
}
|
||||
|
@ -5,5 +5,5 @@ import str::*;
|
||||
fn main() unsafe {
|
||||
let a: uint = 4u;
|
||||
let b: uint = 1u;
|
||||
log(error, str::unsafe::safe_slice("kitties", a, b));
|
||||
log(error, str::unsafe::slice_bytes_safe_range("kitties", a, b));
|
||||
}
|
||||
|
@ -16,5 +16,5 @@ fn main() unsafe {
|
||||
// the next statement, since it's not true in the
|
||||
// prestate.
|
||||
let d <- a;
|
||||
log(debug, str::unsafe::safe_slice("kitties", b, d));
|
||||
log(debug, str::unsafe::slice_bytes_safe_range("kitties", b, d));
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ fn main() unsafe {
|
||||
let a: uint = 4u;
|
||||
let b: uint = 1u;
|
||||
check (le(a, b));
|
||||
log(error, str::unsafe::safe_slice("kitties", a, b));
|
||||
log(error, str::unsafe::slice_bytes_safe_range("kitties", a, b));
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ fn main() unsafe {
|
||||
let c: uint = 17u;
|
||||
check (le(a, b));
|
||||
c <- a;
|
||||
log(debug, str::unsafe::safe_slice("kitties", c, b));
|
||||
log(debug, str::unsafe::slice_bytes_safe_range("kitties", c, b));
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ fn main() unsafe {
|
||||
let b: uint = 4u;
|
||||
check (le(a, b));
|
||||
let c <- a;
|
||||
log(debug, str::unsafe::safe_slice("kitties", c, b));
|
||||
log(debug, str::unsafe::slice_bytes_safe_range("kitties", c, b));
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ fn main() unsafe {
|
||||
let b: uint = 1u;
|
||||
check (le(b, a));
|
||||
b <-> a;
|
||||
log(debug, str::unsafe::safe_slice("kitties", a, b));
|
||||
log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, b));
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ fn main() unsafe {
|
||||
let b: uint = 4u;
|
||||
check (le(a, b));
|
||||
let c = b;
|
||||
log(debug, str::unsafe::safe_slice("kitties", a, c));
|
||||
log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, c));
|
||||
}
|
||||
|
@ -6,5 +6,5 @@ fn main() unsafe {
|
||||
let a: uint = 1u;
|
||||
let b: uint = 4u;
|
||||
check (le(a, b));
|
||||
log(debug, str::unsafe::safe_slice("kitties", a, b));
|
||||
log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, b));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user