Skip to content

(core::str) mark push/pop/shift byte functions unsafe, rename len functions, and fix replace #1824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 13, 2012
Merged
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
8 changes: 4 additions & 4 deletions src/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/comp/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/comp/driver/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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; }

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::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()]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/comp/middle/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::byte_len(s) as ctypes::c_uint)
llvm::LLVMMDString(sbuf, str::len_bytes(s) as ctypes::c_uint)
})
}
fn lltag(lltag: int) -> ValueRef {
Expand Down Expand Up @@ -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
};
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 @@ -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"),
Expand All @@ -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)
};
}

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 @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/comp/syntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ 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::byte_len_range(*fm.src, line_offset, col);
let col_offset = str::substr_len_bytes(*fm.src, line_offset, col);
ret {fm: fm, pos: line_offset + col_offset};
}

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 @@ -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 {
Expand Down
30 changes: 15 additions & 15 deletions src/comp/syntax/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -149,15 +149,15 @@ fn scan_exponent(rdr: reader) -> option<str> {
let c = rdr.curr;
let rslt = "";
if c == 'e' || c == 'E' {
str::push_byte(rslt, c as u8);
str::push_char(rslt, c);
rdr.bump();
c = rdr.curr;
if c == '-' || c == '+' {
str::push_byte(rslt, c as u8);
str::push_char(rslt, c);
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>; }
Expand All @@ -170,7 +170,7 @@ fn scan_digits(rdr: reader, radix: uint) -> str {
if c == '_' { rdr.bump(); cont; }
alt char::maybe_digit(c) {
some(d) if (d as uint) < radix {
str::push_byte(rslt, c as u8);
str::push_char(rslt, c);
rdr.bump();
}
_ { break; }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -472,11 +472,11 @@ fn next_token_inner(rdr: reader) -> token::token {
let escaped = rdr.curr;
rdr.bump();
alt escaped {
'n' { str::push_byte(accum_str, '\n' as u8); }
'r' { str::push_byte(accum_str, '\r' as u8); }
't' { str::push_byte(accum_str, '\t' as u8); }
'\\' { str::push_byte(accum_str, '\\' as u8); }
'"' { str::push_byte(accum_str, '"' as u8); }
'n' { str::push_char(accum_str, '\n'); }
'r' { str::push_char(accum_str, '\r'); }
't' { str::push_char(accum_str, '\t'); }
'\\' { str::push_char(accum_str, '\\'); }
'"' { str::push_char(accum_str, '"'); }
'\n' { consume_whitespace(rdr); }
'x' {
str::push_char(accum_str, scan_numeric_escape(rdr, 2u));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion src/comp/syntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn to_str(r: reader, t: token) -> str {
// FIXME: escape.
let tmp = "'";
str::push_char(tmp, c as char);
str::push_byte(tmp, '\'' as u8);
str::push_char(tmp, '\'');
ret tmp;
}
LIT_INT(i, t) {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/syntax/print/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/comp/syntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions src/fuzzer/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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), }
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/libcore/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Loading