diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 0aef3ff9e133..0acd3e4f1c8e 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -162,7 +162,7 @@ fn rest(s: str, start: uint) -> str { if (start >= str::char_len(s)) { "" } else { - str::char_slice(s, start, str::char_len(s)) + str::slice(s, start, str::char_len(s)) } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index c5e037b276d7..f632e58eea7f 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -37,7 +37,7 @@ export bytes, chars, substr, - char_slice, + slice, split, splitn, split_str, @@ -427,7 +427,7 @@ fn substr(s: str, begin: uint, len: uint) -> str unsafe { } /* -Function: char_slice +Function: slice Unicode-safe slice. Returns a slice of the given string containing the characters in the range [`begin`..`end`). `begin` and `end` are @@ -438,9 +438,9 @@ Failure: - If begin is greater than end - If end is greater than the character length of the string -FIXME: rename to slice(), make faster by avoiding char conversion +FIXME: make faster by avoiding char conversion */ -fn char_slice(s: str, begin: uint, end: uint) -> str { +fn slice(s: str, begin: uint, end: uint) -> str { from_chars(vec::slice(chars(s), begin, end)) } @@ -620,7 +620,7 @@ fn windowed(nn: uint, ss: str) -> [str] { let ii = 0u; while ii+nn <= len { - let w = char_slice( ss, ii, ii+nn ); + let w = slice( ss, ii, ii+nn ); vec::push(ww,w); ii += 1u; } @@ -675,8 +675,8 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe { if idx == -1 { ret s; } - ret char_slice(s, 0u, idx as uint) + to + - replace(char_slice(s, idx as uint + char_len(from), char_len(s)), + ret slice(s, 0u, idx as uint) + to + + replace(slice(s, idx as uint + char_len(from), char_len(s)), from, to); } } @@ -1658,17 +1658,17 @@ mod tests { } #[test] - fn test_char_slice() { - assert (eq("ab", char_slice("abc", 0u, 2u))); - assert (eq("bc", char_slice("abc", 1u, 3u))); - assert (eq("", char_slice("abc", 1u, 1u))); - assert (eq("\u65e5", char_slice("\u65e5\u672c", 0u, 1u))); + fn test_slice() { + assert (eq("ab", slice("abc", 0u, 2u))); + assert (eq("bc", slice("abc", 1u, 3u))); + assert (eq("", slice("abc", 1u, 1u))); + assert (eq("\u65e5", slice("\u65e5\u672c", 0u, 1u))); let data = "ประเทศไทย中华"; - assert (eq("ป", char_slice(data, 0u, 1u))); - assert (eq("ร", char_slice(data, 1u, 2u))); - assert (eq("华", char_slice(data, 10u, 11u))); - assert (eq("", char_slice(data, 1u, 1u))); + assert (eq("ป", slice(data, 0u, 1u))); + assert (eq("ร", slice(data, 1u, 2u))); + assert (eq("华", slice(data, 10u, 11u))); + assert (eq("", slice(data, 1u, 1u))); fn a_million_letter_X() -> str { let i = 0; @@ -1683,7 +1683,7 @@ mod tests { ret rs; } assert (eq(half_a_million_letter_X(), - char_slice(a_million_letter_X(), 0u, 500000u))); + slice(a_million_letter_X(), 0u, 500000u))); } #[test] diff --git a/src/libstd/json.rs b/src/libstd/json.rs index cf0c236afeb7..bb1d0fb64b6b 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -71,7 +71,7 @@ fn to_str(j: json) -> str { fn rest(s: str) -> str { assert(str::char_len(s) >= 1u); - str::char_slice(s, 1u, str::char_len(s)) + str::slice(s, 1u, str::char_len(s)) } fn from_str_str(s: str) -> (option, str) { @@ -99,7 +99,7 @@ fn from_str_str(s: str) -> (option, str) { cont; } else if (c == '"') { ret (some(string(res)), - str::char_slice(s, pos, str::char_len(s))); + str::slice(s, pos, str::char_len(s))); } res = res + str::from_char(c); } @@ -200,12 +200,12 @@ fn from_str_float(s: str) -> (option, str) { } '.' { break; } _ { ret (some(num(neg * res)), - str::char_slice(s, opos, str::char_len(s))); } + str::slice(s, opos, str::char_len(s))); } } } if pos == len { - ret (some(num(neg * res)), str::char_slice(s, pos, str::char_len(s))); + ret (some(num(neg * res)), str::slice(s, pos, str::char_len(s))); } let dec = 1f; @@ -220,17 +220,17 @@ fn from_str_float(s: str) -> (option, str) { res += (((c as int) - ('0' as int)) as float) * dec; } _ { ret (some(num(neg * res)), - str::char_slice(s, opos, str::char_len(s))); } + str::slice(s, opos, str::char_len(s))); } } } - ret (some(num(neg * res)), str::char_slice(s, pos, str::char_len(s))); + ret (some(num(neg * res)), str::slice(s, pos, str::char_len(s))); } fn from_str_bool(s: str) -> (option, str) { if (str::starts_with(s, "true")) { - (some(boolean(true)), str::char_slice(s, 4u, str::char_len(s))) + (some(boolean(true)), str::slice(s, 4u, str::char_len(s))) } else if (str::starts_with(s, "false")) { - (some(boolean(false)), str::char_slice(s, 5u, str::char_len(s))) + (some(boolean(false)), str::slice(s, 5u, str::char_len(s))) } else { (none, s) } @@ -238,7 +238,7 @@ fn from_str_bool(s: str) -> (option, str) { fn from_str_null(s: str) -> (option, str) { if (str::starts_with(s, "null")) { - (some(null), str::char_slice(s, 4u, str::char_len(s))) + (some(null), str::slice(s, 4u, str::char_len(s))) } else { (none, s) } diff --git a/src/rustdoc/unindent_pass.rs b/src/rustdoc/unindent_pass.rs index 8d6aec733003..9c43ce448641 100644 --- a/src/rustdoc/unindent_pass.rs +++ b/src/rustdoc/unindent_pass.rs @@ -68,7 +68,7 @@ fn unindent(s: str) -> str { line } else { assert str::byte_len(line) >= min_indent; - str::char_slice(line, min_indent, str::char_len(line)) + str::slice(line, min_indent, str::char_len(line)) } }; str::connect(unindented, "\n")