diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index aa042ea1ae4..ac1727ffdb7 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -651,25 +651,27 @@ fn cmd_install(c: cargo) unsafe { if str::starts_with(target, "uuid:") { let uuid = rest(target, 5u); - 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, - str::byte_len(uuid)); - install_uuid_specific(c, wd, source, uuid); - } else { - install_uuid(c, wd, uuid); + alt str::index(uuid, '/') { + option::some(idx) { + let source = str::slice(uuid, 0u, idx); + uuid = str::slice(uuid, idx + 1u, str::char_len(uuid)); + install_uuid_specific(c, wd, source, uuid); + } + option::none { + install_uuid(c, wd, uuid); + } } } else { let name = target; - 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, - str::byte_len(name)); - install_named_specific(c, wd, source, name); - } else { - install_named(c, wd, name); + alt str::index(name, '/') { + option::some(idx) { + let source = str::slice(name, 0u, idx); + name = str::slice(name, idx + 1u, str::char_len(name)); + install_named_specific(c, wd, source, name); + } + option::none { + install_named(c, wd, name); + } } } } diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 4f32ad4a31f..5fa7841c972 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -109,14 +109,16 @@ 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_byte(output_path, '.' as u8); - let stem; - if dot_pos < 0 { - stem = output_path; - } else { stem = str::unsafe::slice_bytes(output_path, 0u, - dot_pos as uint); } + let stem = alt str::index(output_path, '.') { + option::some(dot_pos) { + str::slice(output_path, 0u, dot_pos) + } + option::none { output_path } + }; + ret stem + "." + extension; } + fn run_passes(sess: session, llmod: ModuleRef, output: str) { let opts = sess.opts; if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); } diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 27f968b1156..cb2590e1951 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -119,16 +119,13 @@ fn get_line(fm: filemap, line: int) -> str unsafe { let end: uint; if line as uint < vec::len(fm.lines) - 1u { end = fm.lines[line + 1].byte - fm.start_pos.byte; + ret str::unsafe::slice_bytes(*fm.src, begin, end); } else { // If we're not done parsing the file, we're at the limit of what's // 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_bytes(*fm.src, begin, end); - let newline = str::index_byte(rest, '\n' as u8); - if newline != -1 { end = begin + (newline as uint); } + ret str::splitn_char(*fm.src, '\n', 1u)[0]; } - ret str::unsafe::slice_bytes(*fm.src, begin, end); } fn lookup_byte_offset(cm: codemap::codemap, chpos: uint) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 06a49b8d339..9ff1fcfb59e 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -70,7 +70,7 @@ export lines_iter, // Searching - //index, + index, //rindex, index_byte, rindex_byte, diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 33674fe67f3..8288501defc 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -230,16 +230,14 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe { let i_arg = option::none::; if cur[1] == '-' as u8 { let tail = str::unsafe::slice_bytes(cur, 2u, curlen); - let eq = str::index_byte(tail, '=' as u8); - if eq == -1 { + let tail_eq = str::splitn_char(tail, '=', 1u); + if vec::len(tail_eq) <= 1u { names = [long(tail)]; } else { names = - [long(str::unsafe::slice_bytes(tail,0u,eq as uint))]; + [long(tail_eq[0])]; i_arg = - option::some::(str::unsafe::slice_bytes(tail, - (eq as uint) + 1u, - curlen - 2u)); + option::some::(tail_eq[1]); } } else { let j = 1u;