using str::index...
This commit is contained in:
parent
14baf88f89
commit
27161f4415
5 changed files with 33 additions and 34 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -70,7 +70,7 @@ export
|
|||
lines_iter,
|
||||
|
||||
// Searching
|
||||
//index,
|
||||
index,
|
||||
//rindex,
|
||||
index_byte,
|
||||
rindex_byte,
|
||||
|
|
|
@ -230,16 +230,14 @@ 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_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>(str::unsafe::slice_bytes(tail,
|
||||
(eq as uint) + 1u,
|
||||
curlen - 2u));
|
||||
option::some::<str>(tail_eq[1]);
|
||||
}
|
||||
} else {
|
||||
let j = 1u;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue