Permalink
Browse files

(core::str) rename byte_len -> len_bytes and rename char_len -> len

  • Loading branch information...
1 parent 944f5a6 commit 2b4f5136a52041a88fbf3a03f627e9c00869f182 @killerswan killerswan committed Feb 12, 2012
View
@@ -174,10 +174,10 @@ fn print(s: str) {
}
fn rest(s: str, start: uint) -> str {
- if (start >= str::char_len(s)) {
+ if (start >= str::len(s)) {
""
} else {
- str::slice(s, start, str::char_len(s))
+ str::slice(s, start, str::len(s))
}
}
@@ -654,7 +654,7 @@ fn cmd_install(c: cargo) unsafe {
alt str::index(uuid, '/') {
option::some(idx) {
let source = str::slice(uuid, 0u, idx);
- uuid = str::slice(uuid, idx + 1u, str::char_len(uuid));
+ uuid = str::slice(uuid, idx + 1u, str::len(uuid));
install_uuid_specific(c, wd, source, uuid);
}
option::none {
@@ -666,7 +666,7 @@ fn cmd_install(c: cargo) unsafe {
alt str::index(name, '/') {
option::some(idx) {
let source = str::slice(name, 0u, idx);
- name = str::slice(name, idx + 1u, str::char_len(name));
+ name = str::slice(name, idx + 1u, str::len(name));
install_named_specific(c, wd, source, name);
}
option::none {
View
@@ -396,7 +396,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::byte_len(s), s];
+ ret #fmt["%u_%s", str::len_bytes(s), s];
}
fn len_and_str_lit(l: ast::lit) -> str {
@@ -521,7 +521,7 @@ fn mangle(ss: path) -> str {
for s in ss {
alt s { path_name(s) | path_mod(s) {
- n += #fmt["%u%s", str::byte_len(s), s];
+ n += #fmt["%u%s", str::len_bytes(s), s];
} }
}
n += "E"; // End name-sequence.
@@ -573,7 +573,7 @@ fn link_binary(sess: session,
config.os == session::os_freebsd) &&
str::find(filename, "lib") == 0 {
ret str::unsafe::slice_bytes(filename, 3u,
- str::byte_len(filename));
+ str::len_bytes(filename));
} else { ret filename; }
};
fn rmext(filename: str) -> str {
@@ -210,7 +210,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
if elided {
let last_line = display_lines[vec::len(display_lines) - 1u];
let s = #fmt["%s:%u ", fm.name, last_line + 1u];
- let indent = str::char_len(s);
+ let indent = str::len(s);
let out = "";
while indent > 0u { out += " "; indent -= 1u; }
out += "...\n";
@@ -228,7 +228,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
while num > 0u { num /= 10u; digits += 1u; }
// indent past |name:## | and the 0-offset column location
- let left = str::char_len(fm.name) + digits + lo.col + 3u;
+ let left = str::len(fm.name) + digits + lo.col + 3u;
let s = "";
while left > 0u { str::push_char(s, ' '); left -= 1u; }
View
@@ -13,7 +13,7 @@ import rustc::driver::diagnostic;
fn version(argv0: str) {
let vers = "unknown version";
let env_vers = #env["CFG_VERSION"];
- if str::byte_len(env_vers) != 0u { vers = env_vers; }
+ if str::len_bytes(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()]);
}
@@ -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::byte_len(s) as ctypes::c_uint)
+ llvm::LLVMMDString(sbuf, str::len_bytes(s) as ctypes::c_uint)
})
}
fn lltag(lltag: int) -> ValueRef {
@@ -167,8 +167,8 @@ 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::byte_len(work_dir),
- str::byte_len(full_path))
+ str::unsafe::slice_bytes(full_path, str::len_bytes(work_dir),
+ str::len_bytes(full_path))
} else {
full_path
};
@@ -767,7 +767,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::byte_len(s) as unsigned, False)
+ llvm::LLVMConstString(buf, str::len_bytes(s) as unsigned, False)
};
let g =
str::as_buf(cx.names("str"),
@@ -781,7 +781,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::byte_len(s) as unsigned, False)
+ llvm::LLVMConstString(buf, str::len_bytes(s) as unsigned, False)
};
}
@@ -130,7 +130,7 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id,
}
fn trans_str(bcx: @block_ctxt, s: str, dest: dest) -> @block_ctxt {
- let veclen = str::byte_len(s) + 1u; // +1 for \0
+ let veclen = str::len_bytes(s) + 1u; // +1 for \0
let {bcx: bcx, val: sptr, _} =
alloc(bcx, ty::mk_str(bcx_tcx(bcx)), veclen);
@@ -202,7 +202,7 @@ fn expand_qquote<N: qq_helper>
if (j < g_len && i == cx.gather[j].lo) {
assert ch == '$';
let repl = #fmt("$%u ", j);
- state = skip(str::char_len(repl));
+ state = skip(str::len(repl));
str2 += repl;
}
alt state {
@@ -58,7 +58,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::byte_len(*filemap.src),
+ src: filemap.src, len: str::len_bytes(*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};
@@ -157,7 +157,7 @@ fn scan_exponent(rdr: reader) -> option<str> {
rdr.bump();
}
let exponent = scan_digits(rdr, 10u);
- if str::byte_len(exponent) > 0u {
+ if str::len_bytes(exponent) > 0u {
ret some(rslt + exponent);
} else { rdr.fatal("scan_exponent: bad fp literal"); }
} else { ret none::<str>; }
@@ -220,7 +220,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::byte_len(num_str) == 0u {
+ if str::len_bytes(num_str) == 0u {
rdr.fatal("no valid digits found for number");
}
let parsed = u64::from_str(num_str, base as u64);
@@ -267,7 +267,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::byte_len(num_str) == 0u {
+ if str::len_bytes(num_str) == 0u {
rdr.fatal("no valid digits found for number");
}
let parsed = u64::from_str(num_str, base as u64);
@@ -604,8 +604,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::byte_len(s) {
- s1 = str::unsafe::slice_bytes(s, col, str::byte_len(s));
+ if col < str::len_bytes(s) {
+ s1 = str::unsafe::slice_bytes(s, col, str::len_bytes(s));
} else { s1 = ""; }
} else { s1 = s; }
log(debug, "pushing line: " + s1);
@@ -645,7 +645,7 @@ fn read_block_comment(rdr: reader, code_to_the_left: bool) -> cmnt {
}
}
}
- if str::byte_len(curr_line) != 0u {
+ if str::len_bytes(curr_line) != 0u {
trim_whitespace_prefix_and_push_line(lines, curr_line, col);
}
let style = if code_to_the_left { trailing } else { isolated };
@@ -491,7 +491,7 @@ fn end(p: printer) { p.pretty_print(END); }
fn eof(p: printer) { p.pretty_print(EOF); }
fn word(p: printer, wrd: str) {
- p.pretty_print(STRING(wrd, str::char_len(wrd) as int));
+ p.pretty_print(STRING(wrd, str::len(wrd) as int));
}
fn huge_word(p: printer, wrd: str) {
@@ -201,7 +201,7 @@ fn head(s: ps, w: str) {
// outer-box is consistent
cbox(s, indent_unit);
// head-box is inconsistent
- ibox(s, str::char_len(w) + 1u);
+ ibox(s, str::len(w) + 1u);
// keyword that starts the head
word_nbsp(s, w);
}
@@ -1458,7 +1458,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::byte_len(input.ident) > 0u {
+ if str::len_bytes(input.ident) > 0u {
word_space(s, input.ident + ":");
}
print_type(s, input.ty);
@@ -1640,7 +1640,7 @@ fn print_string(s: ps, st: str) {
fn escape_str(st: str, to_escape: char) -> str {
let out: str = "";
- let len = str::byte_len(st);
+ let len = str::len_bytes(st);
let i = 0u;
while i < len {
alt st[i] as char {
View
@@ -132,7 +132,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
fn ty_to_short_str(cx: ctxt, typ: t) -> str unsafe {
let s = encoder::encoded_ty(cx, typ);
- if str::byte_len(s) >= 32u { s = str::unsafe::slice_bytes(s, 0u, 32u); }
+ if str::len_bytes(s) >= 32u { s = str::unsafe::slice_bytes(s, 0u, 32u); }
ret s;
}
@@ -26,12 +26,12 @@ fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
let error_tag = "//!";
let idx0 = str::find(line, error_tag);
if idx0 < 0 { ret []; }
- let idx = (idx0 as uint) + str::byte_len(error_tag);
+ let idx = (idx0 as uint) + str::len_bytes(error_tag);
// "//!^^^ kind msg" denotes a message expected
// three lines above current line:
let adjust_line = 0u;
- let len = str::byte_len(line);
+ let len = str::len_bytes(line);
while idx < len && line[idx] == ('^' as u8) {
adjust_line += 1u;
idx += 1u;
@@ -109,8 +109,8 @@ 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_bytes(line, colon + str::byte_len(keycolon),
- str::byte_len(line));
+ str::unsafe::slice_bytes(line, colon + str::len_bytes(keycolon),
+ str::len_bytes(line));
#debug("%s: %s", directive, value);
option::some(value)
} else { option::none }
View
@@ -285,7 +285,7 @@ fn check_variants_T<T: copy>(
fn last_part(filename: str) -> str {
let ix = option::get(str::rindex(filename, '/'));
- str::slice(filename, ix + 1u, str::char_len(filename) - 3u)
+ str::slice(filename, ix + 1u, str::len(filename) - 3u)
}
enum happiness { passed, cleanly_rejected(str), known_bug(str), failed(str), }
@@ -333,7 +333,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::byte_len(comb) > 1u {
+ if str::len_bytes(comb) > 1u {
log(error, "comb comb comb: " + comb);
}
View
@@ -82,10 +82,10 @@ mod ct {
fn parse_fmt_string(s: str, error: error_fn) -> [piece] unsafe {
let pieces: [piece] = [];
- let lim = str::byte_len(s);
+ let lim = str::len_bytes(s);
let buf = "";
fn flush_buf(buf: str, &pieces: [piece]) -> str {
- if str::byte_len(buf) > 0u {
+ if str::len_bytes(buf) > 0u {
let piece = piece_string(buf);
pieces += [piece];
}
@@ -325,7 +325,7 @@ mod rt {
alt cv.precision {
count_implied { s }
count_is(max) {
- if max as uint < str::char_len(s) {
+ if max as uint < str::len(s) {
str::substr(s, 0u, max as uint)
} else { s }
}
@@ -368,7 +368,7 @@ mod rt {
""
} else {
let s = uint::to_str(num, radix);
- let len = str::char_len(s);
+ let len = str::len(s);
if len < prec {
let diff = prec - len;
let pad = str_init_elt(diff, '0');
@@ -400,7 +400,7 @@ mod rt {
uwidth = width as uint;
}
}
- let strlen = str::char_len(s);
+ let strlen = str::len(s);
if uwidth <= strlen { ret s; }
let padchar = ' ';
let diff = uwidth - strlen;
@@ -433,12 +433,12 @@ mod rt {
// zeros. It may make sense to convert zero padding to a precision
// instead.
- if signed && zero_padding && str::byte_len(s) > 0u {
+ if signed && zero_padding && str::len_bytes(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::byte_len(s);
+ let bytelen = str::len_bytes(s);
let numpart = str::unsafe::slice_bytes(s, 1u, bytelen);
ret headstr + padstr + numpart;
}
View
@@ -128,7 +128,7 @@ fn from_str(num: str) -> float {
let pos = 0u; //Current byte position in the string.
//Used to walk the string in O(n).
- let len = str::byte_len(num); //Length of the string, in bytes.
+ let len = str::len_bytes(num); //Length of the string, in bytes.
if len == 0u { ret 0.; }
let total = 0f; //Accumulated result
Oops, something went wrong.

0 comments on commit 2b4f513

Please sign in to comment.