core::str rename [r]index -> [r]index_bytes
This commit is contained in:
parent
4339307359
commit
a131b430a0
@ -651,7 +651,7 @@ fn cmd_install(c: cargo) unsafe {
|
||||
|
||||
if str::starts_with(target, "uuid:") {
|
||||
let uuid = rest(target, 5u);
|
||||
let idx = str::index(uuid, '/' as u8);
|
||||
let idx = str::index_byte(uuid, '/' as u8);
|
||||
if idx != -1 {
|
||||
let source = str::unsafe::slice_bytes(uuid, 0u, idx as uint);
|
||||
uuid = str::unsafe::slice_bytes(uuid, idx as uint + 1u,
|
||||
@ -662,7 +662,7 @@ fn cmd_install(c: cargo) unsafe {
|
||||
}
|
||||
} else {
|
||||
let name = target;
|
||||
let idx = str::index(name, '/' as u8);
|
||||
let idx = str::index_byte(name, '/' as u8);
|
||||
if idx != -1 {
|
||||
let source = str::unsafe::slice_bytes(name, 0u, idx as uint);
|
||||
name = str::unsafe::slice_bytes(name, idx as uint + 1u,
|
||||
|
@ -109,7 +109,7 @@ mod write {
|
||||
// Decides what to call an intermediate file, given the name of the output
|
||||
// and the extension to use.
|
||||
fn mk_intermediate_name(output_path: str, extension: str) -> str unsafe {
|
||||
let dot_pos = str::index(output_path, '.' as u8);
|
||||
let dot_pos = str::index_byte(output_path, '.' as u8);
|
||||
let stem;
|
||||
if dot_pos < 0 {
|
||||
stem = output_path;
|
||||
|
@ -125,7 +125,7 @@ fn get_line(fm: filemap, line: int) -> str unsafe {
|
||||
// the remainder of the file, which is undesirable.
|
||||
end = str::byte_len(*fm.src);
|
||||
let rest = str::unsafe::slice_bytes(*fm.src, begin, end);
|
||||
let newline = str::index(rest, '\n' as u8);
|
||||
let newline = str::index_byte(rest, '\n' as u8);
|
||||
if newline != -1 { end = begin + (newline as uint); }
|
||||
}
|
||||
ret str::unsafe::slice_bytes(*fm.src, begin, end);
|
||||
|
@ -284,7 +284,7 @@ fn check_variants_T<T: copy>(
|
||||
}
|
||||
|
||||
fn last_part(filename: str) -> str unsafe {
|
||||
let ix = str::rindex(filename, 47u8 /* '/' */);
|
||||
let ix = str::rindex_byte(filename, 47u8 /* '/' */);
|
||||
assert ix >= 0;
|
||||
str::unsafe::slice_bytes(filename, ix as uint + 1u, str::byte_len(filename) - 3u)
|
||||
}
|
||||
|
@ -70,8 +70,10 @@ export
|
||||
lines_iter,
|
||||
|
||||
// Searching
|
||||
index,
|
||||
rindex,
|
||||
//index,
|
||||
//rindex,
|
||||
index_byte,
|
||||
rindex_byte,
|
||||
find,
|
||||
contains,
|
||||
starts_with,
|
||||
@ -876,7 +878,7 @@ no match is found.
|
||||
|
||||
FIXME: UTF-8
|
||||
*/
|
||||
fn index(s: str, c: u8) -> int {
|
||||
fn index_byte(s: str, c: u8) -> int {
|
||||
let i: int = 0;
|
||||
for k: u8 in s { if k == c { ret i; } i += 1; }
|
||||
ret -1;
|
||||
@ -890,7 +892,7 @@ if no match is found.
|
||||
|
||||
FIXME: UTF-8
|
||||
*/
|
||||
fn rindex(s: str, c: u8) -> int {
|
||||
fn rindex_byte(s: str, c: u8) -> int {
|
||||
let n: int = byte_len(s) as int;
|
||||
while n >= 0 { if s[n] == c { ret n; } n -= 1; }
|
||||
ret n;
|
||||
@ -1443,12 +1445,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_index_and_rindex() {
|
||||
assert (index("hello", 'e' as u8) == 1);
|
||||
assert (index("hello", 'o' as u8) == 4);
|
||||
assert (index("hello", 'z' as u8) == -1);
|
||||
assert (rindex("hello", 'l' as u8) == 3);
|
||||
assert (rindex("hello", 'h' as u8) == 0);
|
||||
assert (rindex("hello", 'z' as u8) == -1);
|
||||
assert (index_byte("hello", 'e' as u8) == 1);
|
||||
assert (index_byte("hello", 'o' as u8) == 4);
|
||||
assert (index_byte("hello", 'z' as u8) == -1);
|
||||
assert (rindex_byte("hello", 'l' as u8) == 3);
|
||||
assert (rindex_byte("hello", 'h' as u8) == 0);
|
||||
assert (rindex_byte("hello", 'z' as u8) == -1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -44,9 +44,9 @@ The dirname of "/usr/share" will be "/usr", but the dirname of
|
||||
If the path is not prefixed with a directory, then "." is returned.
|
||||
*/
|
||||
fn dirname(p: path) -> path unsafe {
|
||||
let i: int = str::rindex(p, os_fs::path_sep as u8);
|
||||
let i: int = str::rindex_byte(p, os_fs::path_sep as u8);
|
||||
if i == -1 {
|
||||
i = str::rindex(p, os_fs::alt_path_sep as u8);
|
||||
i = str::rindex_byte(p, os_fs::alt_path_sep as u8);
|
||||
if i == -1 { ret "."; }
|
||||
}
|
||||
ret str::unsafe::slice_bytes(p, 0u, i as uint);
|
||||
@ -64,9 +64,9 @@ the provided path. If an empty path is provided or the path ends
|
||||
with a path separator then an empty path is returned.
|
||||
*/
|
||||
fn basename(p: path) -> path unsafe {
|
||||
let i: int = str::rindex(p, os_fs::path_sep as u8);
|
||||
let i: int = str::rindex_byte(p, os_fs::path_sep as u8);
|
||||
if i == -1 {
|
||||
i = str::rindex(p, os_fs::alt_path_sep as u8);
|
||||
i = str::rindex_byte(p, os_fs::alt_path_sep as u8);
|
||||
if i == -1 { ret p; }
|
||||
}
|
||||
let len = str::byte_len(p);
|
||||
|
@ -230,7 +230,7 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
|
||||
let i_arg = option::none::<str>;
|
||||
if cur[1] == '-' as u8 {
|
||||
let tail = str::unsafe::slice_bytes(cur, 2u, curlen);
|
||||
let eq = str::index(tail, '=' as u8);
|
||||
let eq = str::index_byte(tail, '=' as u8);
|
||||
if eq == -1 {
|
||||
names = [long(tail)];
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user