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
parent fc9169f09c
commit ae0d49aa06
4 changed files with 28 additions and 28 deletions

View file

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

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]

View file

@ -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<json>, str) {
@ -99,7 +99,7 @@ fn from_str_str(s: str) -> (option<json>, 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<json>, 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<json>, 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<json>, 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<json>, str) {
fn from_str_null(s: str) -> (option<json>, 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)
}

View file

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