提交 780f8277 编写于 作者: M Marijn Haverbeke

Finish cleanup of core::str

Closes #1849
上级 1d2b4b97
......@@ -109,13 +109,10 @@ fn is_object_or_assembly_or_exe(ot: output_type) -> bool {
// 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 stem = alt str::index(output_path, '.') {
option::some(dot_pos) {
str::slice(output_path, 0u, dot_pos)
}
option::none { output_path }
};
let stem = alt str::find_char(output_path, '.') {
some(dot_pos) { str::slice(output_path, 0u, dot_pos) }
none { output_path }
};
ret stem + "." + extension;
}
......@@ -566,7 +563,7 @@ 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(filename, "lib");
let found = str::find_str(filename, "lib");
if config.os == session::os_macos ||
(config.os == session::os_linux ||
config.os == session::os_freebsd) &&
......
......@@ -157,7 +157,7 @@ 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::index_from(*fm.src, '\n', begin, str::len(*fm.src)) {
let end = alt str::find_char_from(*fm.src, '\n', begin) {
some(e) { e }
none { str::len(*fm.src) }
};
......@@ -165,14 +165,12 @@ fn get_line(fm: filemap, line: int) -> str unsafe {
}
fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
-> {fm: filemap, pos: uint}
{
fn lookup(pos: file_pos) -> uint { ret pos.ch; }
let {fm,line} = lookup_line(cm,chpos,lookup);
-> {fm: filemap, pos: uint} {
let {fm, line} = lookup_line(cm, chpos, {|pos| pos.ch});
let line_offset = fm.lines[line].byte - fm.start_pos.byte;
let col = chpos - fm.lines[line].ch;
let col_offset = str::substr_len(*fm.src, line_offset, col);
ret {fm: fm, pos: line_offset + col_offset};
let col_offset = str::count_bytes(*fm.src, line_offset, col);
{fm: fm, pos: line_offset + col_offset}
}
fn span_to_snippet(sp: span, cm: codemap::codemap) -> str {
......
......@@ -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_chars(repl));
state = skip(str::char_len(repl));
str2 += repl;
}
alt state {
......
......@@ -25,7 +25,7 @@ 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(line, error_tag) {
alt str::find_str(line, error_tag) {
option::none { ret []; }
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
}
......
......@@ -106,7 +106,7 @@ 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(line, keycolon) {
alt str::find_str(line, keycolon) {
option::some(colon) {
let value = str::slice(line, colon + str::len(keycolon),
str::len(line));
......
......@@ -198,7 +198,7 @@ fn check_error_patterns(props: test_props,
let next_err_idx = 0u;
let next_err_pat = props.error_patterns[next_err_idx];
for line: str in str::split_byte(procres.stderr, '\n' as u8) {
for line: str in str::split_char(procres.stderr, '\n') {
if str::contains(line, next_err_pat) {
#debug("found error pattern %s", next_err_pat);
next_err_idx += 1u;
......@@ -245,7 +245,7 @@ fn check_expected_errors(expected_errors: [errors::expected_error],
// filename:line1:col1: line2:col2: *warning:* msg
// where line1:col1: is the starting point, line2:col2:
// is the ending point, and * represents ANSI color codes.
for line: str in str::split_byte(procres.stderr, '\n' as u8) {
for line: str in str::split_char(procres.stderr, '\n') {
let was_expected = false;
vec::iteri(expected_errors) {|i, ee|
if !found_flags[i] {
......@@ -350,7 +350,7 @@ fn is_whitespace(s: str) -> bool {
}
alt argstr {
option::some(s) { rm_whitespace(str::split_byte(s, ' ' as u8)) }
option::some(s) { rm_whitespace(str::split_char(s, ' ')) }
option::none { [] }
}
}
......@@ -410,12 +410,10 @@ fn make_out_name(config: config, testfile: str, extension: str) -> str {
fn output_base_name(config: config, testfile: str) -> str {
let base = config.build_base;
let filename =
{
let parts = str::split_byte(fs::basename(testfile), '.' as u8);
parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
str::connect(parts, ".")
};
let filename = {
let parts = str::split_char(fs::basename(testfile), '.');
str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ".")
};
#fmt["%s%s.%s", base, filename, config.stage_id]
}
......
......@@ -320,16 +320,14 @@ fn conv_char(cv: conv, c: char) -> str {
fn conv_str(cv: conv, s: str) -> str unsafe {
// For strings, precision is the maximum characters
// displayed
let unpadded =
alt cv.precision {
count_implied { s }
count_is(max) {
if max as uint < str::len_chars(s) {
str::substr(s, 0u, max as uint)
} else { s }
}
};
let unpadded = alt cv.precision {
count_implied { s }
count_is(max) {
if max as uint < str::char_len(s) {
str::substr(s, 0u, max as uint)
} else { s }
}
};
ret pad(cv, unpadded, pad_nozero);
}
fn conv_float(cv: conv, f: float) -> str {
......@@ -368,7 +366,7 @@ fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> str {
""
} else {
let s = uint::to_str(num, radix);
let len = str::len_chars(s);
let len = str::char_len(s);
if len < prec {
let diff = prec - len;
let pad = str_init_elt(diff, '0');
......@@ -400,7 +398,7 @@ fn pad(cv: conv, s: str, mode: pad_mode) -> str unsafe {
uwidth = width as uint;
}
}
let strlen = str::len_chars(s);
let strlen = str::char_len(s);
if uwidth <= strlen { ret s; }
let padchar = ' ';
let diff = uwidth - strlen;
......
此差异已折叠。
......@@ -33,19 +33,15 @@
type path = str;
fn splitDirnameBasename (pp: path) -> {dirname: str, basename: str} {
let ii;
alt str::rindex(pp, os_fs::path_sep) {
option::some(xx) { ii = xx; }
option::none {
alt str::rindex(pp, os_fs::alt_path_sep) {
option::some(xx) { ii = xx; }
option::none { ret {dirname: ".", basename: pp}; }
}
}
alt str::rfind(pp, {|ch|
ch == os_fs::path_sep || ch == os_fs::alt_path_sep
}) {
some(i) {
{dirname: str::slice(pp, 0u, i),
basename: str::slice(pp, i + 1u, str::len(pp))}
}
none { {dirname: ".", basename: pp} }
}
ret {dirname: str::slice(pp, 0u, ii),
basename: str::slice(pp, ii + 1u, str::len(pp))};
}
/*
......
......@@ -3,10 +3,6 @@
import float;
import map;
import core::option;
import option::{some, none};
import str;
import vec;
export json;
export to_str;
......
......@@ -743,7 +743,7 @@ fn of_str(str: @str) -> @node {
*/
fn of_substr(str: @str, byte_start: uint, byte_len: uint) -> @node {
ret of_substr_unsafer(str, byte_start, byte_len,
str::substr_len_chars(*str, byte_start, byte_len));
str::count_chars(*str, byte_start, byte_len));
}
/*
......@@ -795,7 +795,7 @@ fn of_substr_unsafer(str: @str, byte_start: uint, byte_len: uint,
if i == 0u { first_leaf_char_len }
else { hint_max_leaf_char_len };
let chunk_byte_len =
str::substr_len(*str, offset, chunk_char_len);
str::count_bytes(*str, offset, chunk_char_len);
nodes[i] = @leaf({
byte_offset: offset,
byte_len: chunk_byte_len,
......@@ -998,7 +998,7 @@ fn sub_bytes(node: @node, byte_offset: uint, byte_len: uint) -> @node {
alt(*node) {
node::leaf(x) {
let char_len =
str::substr_len_chars(*x.content, byte_offset, byte_len);
str::count_chars(*x.content, byte_offset, byte_len);
ret @leaf({byte_offset: byte_offset,
byte_len: byte_len,
char_len: char_len,
......@@ -1059,9 +1059,9 @@ fn sub_chars(node: @node, char_offset: uint, char_len: uint) -> @node {
ret node;
}
let byte_offset =
str::substr_len(*x.content, 0u, char_offset);
str::count_bytes(*x.content, 0u, char_offset);
let byte_len =
str::substr_len(*x.content, byte_offset, char_len);
str::count_bytes(*x.content, byte_offset, char_len);
ret @leaf({byte_offset: byte_offset,
byte_len: byte_len,
char_len: char_len,
......@@ -1138,9 +1138,9 @@ fn cmp(a: @node, b: @node) -> int {
fn loop_chars(node: @node, it: fn(char) -> bool) -> bool {
ret loop_leaves(node, {|leaf|
ret str::substr_all(*leaf.content,
leaf.byte_offset,
leaf.byte_len, it)
ret str::all_between(*leaf.content,
leaf.byte_offset,
leaf.byte_len, it)
})
}
......@@ -1373,7 +1373,7 @@ fn of_string1() {
let sample = @"0123456789ABCDE";
let r = of_str(sample);
assert char_len(r) == str::len_chars(*sample);
assert char_len(r) == str::char_len(*sample);
assert rope_to_string(r) == *sample;
}
......@@ -1384,7 +1384,7 @@ fn of_string2() {
while i < 10 { *buf = *buf + *buf; i+=1;}
let sample = @*buf;
let r = of_str(sample);
assert char_len(r) == str::len_chars(*sample);
assert char_len(r) == str::char_len(*sample);
assert rope_to_string(r) == *sample;
let string_iter = 0u;
......@@ -1427,7 +1427,7 @@ fn iter1() {
}
}
assert len == str::len_chars(*sample);
assert len == str::char_len(*sample);
}
#[test]
......
......@@ -282,7 +282,7 @@ fn mk_doc(source: str) -> doc::cratedoc {
astsrv::from_str(source) {|srv|
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
mk_pass(str::trim)(srv, doc)
mk_pass({|s| str::trim(s)})(srv, doc)
}
}
}
\ No newline at end of file
......@@ -56,10 +56,10 @@ mod c { }\
fn d() { }"
);
let idx_a = option::get(str::find(markdown, "# Module `a`"));
let idx_b = option::get(str::find(markdown, "## Function `b`"));
let idx_c = option::get(str::find(markdown, "# Module `c`"));
let idx_d = option::get(str::find(markdown, "## Function `d`"));
let idx_a = option::get(str::find_str(markdown, "# Module `a`"));
let idx_b = option::get(str::find_str(markdown, "## Function `b`"));
let idx_c = option::get(str::find_str(markdown, "# Module `c`"));
let idx_d = option::get(str::find_str(markdown, "## Function `d`"));
assert idx_b < idx_d;
assert idx_d < idx_a;
......
......@@ -10,7 +10,7 @@
export mk_pass;
fn mk_pass() -> pass {
desc_pass::mk_pass(str::trim)
desc_pass::mk_pass({|s| str::trim(s)})
}
#[test]
......
......@@ -33,7 +33,7 @@ fn read_grid(f: io::reader) -> grid_t {
let g = vec::init_fn(10u, {|_i| vec::init_elt_mut(10u, 0 as u8) });
while !f.eof() {
let comps = str::split_byte(str::trim(f.read_line()), ',' as u8);
let comps = str::split_char(str::trim(f.read_line()), ',');
if vec::len(comps) >= 3u {
let row = option::get(uint::from_str(comps[0])) as u8;
let col = option::get(uint::from_str(comps[1])) as u8;
......
......@@ -3,7 +3,8 @@
import str::*;
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 4u;
let b: uint = 1u;
log(error, str::unsafe::slice_bytes_safe_range("kitties", a, b));
log(error, foo(a, b));
}
// error-pattern:Unsatisfied precondition constraint (for example, uint::le
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 1u;
let b: uint = 4u;
let c: uint = 5u;
......@@ -13,5 +14,5 @@ fn main() unsafe {
// the next statement, since it's not true in the
// prestate.
let d <- a;
log(debug, str::unsafe::slice_bytes_safe_range("kitties", b, d));
log(debug, foo(b, d));
}
// error-pattern:Predicate uint::le(a, b) failed
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 4u;
let b: uint = 1u;
check (uint::le(a, b));
log(error, str::unsafe::slice_bytes_safe_range("kitties", a, b));
log(error, foo(a, b));
}
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 1u;
let b: uint = 4u;
let c: uint = 17u;
check (uint::le(a, b));
c <- a;
log(debug, str::unsafe::slice_bytes_safe_range("kitties", c, b));
log(debug, foo(c, b));
}
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 1u;
let b: uint = 4u;
check (uint::le(a, b));
let c <- a;
log(debug, str::unsafe::slice_bytes_safe_range("kitties", c, b));
log(debug, foo(c, b));
}
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 4u;
let b: uint = 1u;
check (uint::le(b, a));
b <-> a;
log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, b));
log(debug, foo(a, b));
}
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 1u;
let b: uint = 4u;
check (uint::le(a, b));
check uint::le(a, b);
let c = b;
log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, c));
log(debug, foo(a, c));
}
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 1u;
let b: uint = 4u;
check (uint::le(a, b));
log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, b));
log(debug, foo(a, b));
}
......@@ -8,8 +8,8 @@ fn main() {
let s: str = str::from_chars(chs);
assert (str::len(s) == 10u);
assert (str::len_chars(s) == 4u);
assert (vec::len::<char>(str::chars(s)) == 4u);
assert (str::char_len(s) == 4u);
assert (vec::len(str::chars(s)) == 4u);
assert (str::eq(str::from_chars(str::chars(s)), s));
assert (str::char_at(s, 0u) == 'e');
assert (str::char_at(s, 1u) == 'é');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册