Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/comp/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
metas: provided_metas,
dep_hashes: [str]) -> str {
fn len_and_str(s: str) -> str {
ret #fmt["%u_%s", str::len_bytes(s), s];
ret #fmt["%u_%s", str::len(s), s];
}

fn len_and_str_lit(l: ast::lit) -> str {
Expand Down Expand Up @@ -478,7 +478,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
}

fn truncated_sha1_result(sha: sha1) -> str unsafe {
ret str::unsafe::slice_bytes(sha.result_str(), 0u, 16u);
ret str::slice(sha.result_str(), 0u, 16u);
}


Expand Down Expand Up @@ -520,7 +520,7 @@ fn mangle(ss: path) -> str {

for s in ss {
alt s { path_name(s) | path_mod(s) {
n += #fmt["%u%s", str::len_bytes(s), s];
n += #fmt["%u%s", str::len(s), s];
} }
}
n += "E"; // End name-sequence.
Expand Down Expand Up @@ -567,13 +567,12 @@ fn link_binary(sess: session,
// Converts a library file name into a cc -l argument
fn unlib(config: @session::config, filename: str) -> str unsafe {
let rmlib = fn@(filename: str) -> str {
let found = str::find_bytes(filename, "lib");
let found = str::find(filename, "lib");
if config.os == session::os_macos ||
(config.os == session::os_linux ||
config.os == session::os_freebsd) &&
option::is_some(found) && option::get(found) == 0u {
ret str::unsafe::slice_bytes(filename, 3u,
str::len_bytes(filename));
ret str::slice(filename, 3u, str::len(filename));
} else { ret filename; }
};
fn rmext(filename: str) -> str {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import rustc::driver::diagnostic;
fn version(argv0: str) {
let vers = "unknown version";
let env_vers = #env["CFG_VERSION"];
if str::len_bytes(env_vers) != 0u { vers = env_vers; }
if str::len(env_vers) != 0u { vers = env_vers; }
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
io::stdout().write_str(#fmt["host: %s\n", host_triple()]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ fn C_u8(i: uint) -> ValueRef { ret C_integral(T_i8(), i as u64, False); }
// our boxed-and-length-annotated strings.
fn C_cstr(cx: crate_ctxt, s: str) -> ValueRef {
let sc = str::as_buf(s) {|buf|
llvm::LLVMConstString(buf, str::len_bytes(s) as unsigned, False)
llvm::LLVMConstString(buf, str::len(s) as unsigned, False)
};
let g =
str::as_buf(cx.names("str"),
Expand All @@ -791,7 +791,7 @@ fn C_cstr(cx: crate_ctxt, s: str) -> ValueRef {
// Returns a Plain Old LLVM String:
fn C_postr(s: str) -> ValueRef {
ret str::as_buf(s) {|buf|
llvm::LLVMConstString(buf, str::len_bytes(s) as unsigned, False)
llvm::LLVMConstString(buf, str::len(s) as unsigned, False)
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/comp/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const DW_ATE_unsigned_char: int = 0x08;

fn llstr(s: str) -> ValueRef {
str::as_buf(s, {|sbuf|
llvm::LLVMMDString(sbuf, str::len_bytes(s) as ctypes::c_uint)
llvm::LLVMMDString(sbuf, str::len(s) as ctypes::c_uint)
})
}
fn lltag(lltag: int) -> ValueRef {
Expand Down Expand Up @@ -167,8 +167,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_bytes(full_path, str::len_bytes(work_dir),
str::len_bytes(full_path))
str::slice(full_path, str::len(work_dir), str::len(full_path))
} else {
full_path
};
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn trans_vec(bcx: block, args: [@ast::expr], id: ast::node_id,
}

fn trans_str(bcx: block, s: str, dest: dest) -> block {
let veclen = str::len_bytes(s) + 1u; // +1 for \0
let veclen = str::len(s) + 1u; // +1 for \0
let {bcx: bcx, val: sptr, _} =
alloc(bcx, ty::mk_str(bcx.tcx()), veclen);

Expand Down
11 changes: 5 additions & 6 deletions src/comp/syntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {

fn get_line(fm: filemap, line: int) -> str unsafe {
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
let end = alt str::byte_index_from(*fm.src, '\n' as u8, begin,
str::len(*fm.src)) {
let end = alt str::index_from(*fm.src, '\n', begin, str::len(*fm.src)) {
some(e) { e }
none { str::len(*fm.src) }
};
str::unsafe::slice_bytes(*fm.src, begin, end)
str::slice(*fm.src, begin, end)
}

fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
Expand All @@ -172,21 +171,21 @@ fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
let {fm,line} = lookup_line(cm,chpos,lookup);
let line_offset = fm.lines[line].byte - fm.start_pos.byte;
let col = chpos - fm.lines[line].ch;
let col_offset = str::substr_len_bytes(*fm.src, line_offset, col);
let col_offset = str::substr_len(*fm.src, line_offset, col);
ret {fm: fm, pos: line_offset + col_offset};
}

fn span_to_snippet(sp: span, cm: codemap::codemap) -> str {
let begin = lookup_byte_offset(cm,sp.lo);
let end = lookup_byte_offset(cm,sp.hi);
assert begin.fm == end.fm;
ret str::slice(*begin.fm.src, begin.pos, end.pos);
ret str::slice_chars(*begin.fm.src, begin.pos, end.pos);
}

fn get_snippet(cm: codemap::codemap, fidx: uint, lo: uint, hi: uint) -> str
{
let fm = cm.files[fidx];
ret str::slice(*fm.src, lo, hi)
ret str::slice_chars(*fm.src, lo, hi)
}

fn get_filemap(cm: codemap, filename: str) -> filemap {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/syntax/ext/qquote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn finish<T: qq_helper>
if (j < g_len && i == cx.gather[j].lo) {
assert ch == '$';
let repl = #fmt("$%u ", j);
state = skip(str::len(repl));
state = skip(str::len_chars(repl));
str2 += repl;
}
alt state {
Expand Down
16 changes: 8 additions & 8 deletions src/comp/syntax/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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_bytes(*self.src, start - 1u, self.pos - 1u);
ret str::slice(*self.src, start - 1u, self.pos - 1u);
}
fn next() -> char {
if self.pos < self.len {
Expand Down Expand Up @@ -64,7 +64,7 @@ fn new_reader(cm: codemap::codemap,
itr: @interner::interner<str>) -> reader {
let r = @{cm: cm,
span_diagnostic: span_diagnostic,
src: filemap.src, len: str::len_bytes(*filemap.src),
src: filemap.src, len: str::len(*filemap.src),
mutable col: 0u, mutable pos: 0u, mutable curr: -1 as char,
mutable chpos: filemap.start_pos.ch, mutable strs: [],
filemap: filemap, interner: itr};
Expand Down Expand Up @@ -163,7 +163,7 @@ fn scan_exponent(rdr: reader) -> option<str> {
rdr.bump();
}
let exponent = scan_digits(rdr, 10u);
if str::len_bytes(exponent) > 0u {
if str::len(exponent) > 0u {
ret some(rslt + exponent);
} else { rdr.fatal("scan_exponent: bad fp literal"); }
} else { ret none::<str>; }
Expand Down Expand Up @@ -226,7 +226,7 @@ fn scan_number(c: char, rdr: reader) -> token::token {
tp = if signed { either::left(ast::ty_i64) }
else { either::right(ast::ty_u64) };
}
if str::len_bytes(num_str) == 0u {
if str::len(num_str) == 0u {
rdr.fatal("no valid digits found for number");
}
let parsed = option::get(u64::from_str(num_str, base as u64));
Expand Down Expand Up @@ -273,7 +273,7 @@ fn scan_number(c: char, rdr: reader) -> token::token {
ret token::LIT_FLOAT(interner::intern(*rdr.interner, num_str),
ast::ty_f);
} else {
if str::len_bytes(num_str) == 0u {
if str::len(num_str) == 0u {
rdr.fatal("no valid digits found for number");
}
let parsed = option::get(u64::from_str(num_str, base as u64));
Expand Down Expand Up @@ -610,8 +610,8 @@ fn trim_whitespace_prefix_and_push_line(&lines: [str],
s: str, col: uint) unsafe {
let s1;
if all_whitespace(s, 0u, col) {
if col < str::len_bytes(s) {
s1 = str::unsafe::slice_bytes(s, col, str::len_bytes(s));
if col < str::len(s) {
s1 = str::slice(s, col, str::len(s));
} else { s1 = ""; }
} else { s1 = s; }
log(debug, "pushing line: " + s1);
Expand Down Expand Up @@ -651,7 +651,7 @@ fn read_block_comment(rdr: reader, code_to_the_left: bool) -> cmnt {
}
}
}
if str::len_bytes(curr_line) != 0u {
if str::len(curr_line) != 0u {
trim_whitespace_prefix_and_push_line(lines, curr_line, col);
}
let style = if code_to_the_left { trailing } else { isolated };
Expand Down
4 changes: 2 additions & 2 deletions src/comp/syntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
popen(s);
fn print_arg(s: ps, input: ast::arg) {
print_arg_mode(s, input.mode);
if str::len_bytes(input.ident) > 0u {
if str::len(input.ident) > 0u {
word_space(s, input.ident + ":");
}
print_type(s, input.ty);
Expand Down Expand Up @@ -1647,7 +1647,7 @@ fn print_string(s: ps, st: str) {

fn escape_str(st: str, to_escape: char) -> str {
let out: str = "";
let len = str::len_bytes(st);
let len = str::len(st);
let i = 0u;
while i < len {
alt st[i] as char {
Expand Down
4 changes: 2 additions & 2 deletions src/comp/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
}
}

fn ty_to_short_str(cx: ctxt, typ: t) -> str unsafe {
fn ty_to_short_str(cx: ctxt, typ: t) -> str {
let s = encoder::encoded_ty(cx, typ);
if str::len_bytes(s) >= 32u { s = str::unsafe::slice_bytes(s, 0u, 32u); }
if str::len(s) >= 32u { s = str::slice(s, 0u, 32u); }
ret s;
}

Expand Down
10 changes: 5 additions & 5 deletions src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ fn load_errors(testfile: str) -> [expected_error] {
fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
let error_tag = "//!";
let idx;
alt str::find_bytes(line, error_tag) {
alt str::find(line, error_tag) {
option::none { ret []; }
option::some(nn) { idx = (nn as uint) + str::len_bytes(error_tag); }
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
}

// "//!^^^ kind msg" denotes a message expected
// three lines above current line:
let adjust_line = 0u;
let len = str::len_bytes(line);
let len = str::len(line);
while idx < len && line[idx] == ('^' as u8) {
adjust_line += 1u;
idx += 1u;
Expand All @@ -43,11 +43,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_bytes(line, start_kind, idx));
let kind = str::to_lower(str::slice(line, start_kind, idx));

// Extract msg:
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
let msg = str::unsafe::slice_bytes(line, idx, len);
let msg = str::slice(line, idx, len);

#debug("line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg);

Expand Down
8 changes: 3 additions & 5 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ fn parse_name_directive(line: str, directive: str) -> bool {
fn parse_name_value_directive(line: str,
directive: str) -> option<str> unsafe {
let keycolon = directive + ":";
alt str::find_bytes(line, keycolon) {
alt str::find(line, keycolon) {
option::some(colon) {
let value =
str::unsafe::slice_bytes(line,
colon + str::len_bytes(keycolon),
str::len_bytes(line));
let value = str::slice(line, colon + str::len(keycolon),
str::len(line));
#debug("%s: %s", directive, value);
option::some(value)
}
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzer/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fn removeDirIfExists(filename: str) {
fn check_running(exe_filename: str) -> happiness {
let p = std::run::program_output("/Users/jruderman/scripts/timed_run_rust_program.py", [exe_filename]);
let comb = p.out + "\n" + p.err;
if str::len_bytes(comb) > 1u {
if str::len(comb) > 1u {
log(error, "comb comb comb: " + comb);
}

Expand Down
22 changes: 11 additions & 11 deletions src/libcore/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,24 @@ mod ct {

fn parse_fmt_string(s: str, error: error_fn) -> [piece] unsafe {
let pieces: [piece] = [];
let lim = str::len_bytes(s);
let lim = str::len(s);
let buf = "";
fn flush_buf(buf: str, &pieces: [piece]) -> str {
if str::len_bytes(buf) > 0u {
if str::len(buf) > 0u {
let piece = piece_string(buf);
pieces += [piece];
}
ret "";
}
let i = 0u;
while i < lim {
let curr = str::unsafe::slice_bytes(s, i, i+1u);
let curr = str::slice(s, i, i+1u);
if str::eq(curr, "%") {
i += 1u;
if i >= lim {
error("unterminated conversion at end of string");
}
let curr2 = str::unsafe::slice_bytes(s, i, i+1u);
let curr2 = str::slice(s, i, i+1u);
if str::eq(curr2, "%") {
buf += curr2;
i += 1u;
Expand Down Expand Up @@ -225,7 +225,7 @@ mod ct {
fn parse_type(s: str, i: uint, lim: uint, error: error_fn) ->
{ty: ty, next: uint} unsafe {
if i >= lim { error("missing type in conversion"); }
let tstr = str::unsafe::slice_bytes(s, i, i+1u);
let tstr = str::slice(s, i, i+1u);
// TODO: Do we really want two signed types here?
// How important is it to be printf compatible?
let t =
Expand Down Expand Up @@ -325,7 +325,7 @@ mod rt {
alt cv.precision {
count_implied { s }
count_is(max) {
if max as uint < str::len(s) {
if max as uint < str::len_chars(s) {
str::substr(s, 0u, max as uint)
} else { s }
}
Expand Down Expand Up @@ -368,7 +368,7 @@ mod rt {
""
} else {
let s = uint::to_str(num, radix);
let len = str::len(s);
let len = str::len_chars(s);
if len < prec {
let diff = prec - len;
let pad = str_init_elt(diff, '0');
Expand Down Expand Up @@ -400,7 +400,7 @@ mod rt {
uwidth = width as uint;
}
}
let strlen = str::len(s);
let strlen = str::len_chars(s);
if uwidth <= strlen { ret s; }
let padchar = ' ';
let diff = uwidth - strlen;
Expand Down Expand Up @@ -433,13 +433,13 @@ mod rt {
// zeros. It may make sense to convert zero padding to a precision
// instead.

if signed && zero_padding && str::len_bytes(s) > 0u {
if signed && zero_padding && str::len(s) > 0u {
let head = s[0];
if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 {
let headstr = str::from_bytes([head]);
// FIXME: not UTF-8 safe
let bytelen = str::len_bytes(s);
let numpart = str::unsafe::slice_bytes(s, 1u, bytelen);
let bytelen = str::len(s);
let numpart = str::slice(s, 1u, bytelen);
ret headstr + padstr + numpart;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ number represented by [num].
fn from_str(num: str) -> option<float> {
let pos = 0u; //Current byte position in the string.
//Used to walk the string in O(n).
let len = str::len_bytes(num); //Length of the string, in bytes.
let len = str::len(num); //Length of the string, in bytes.

if len == 0u { ret none; }
let total = 0f; //Accumulated result
Expand Down
Loading