1
Fork 0

Rename str::char_slice -> str::slice

This commit is contained in:
Kevin Cantu 2012-02-01 04:36:33 -08:00 committed by Brian Anderson
commit ae0d49aa06
4 changed files with 28 additions and 28 deletions

View file

@ -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]