1
Fork 0

stdlib: Use if/alt expressions in std::str

This commit is contained in:
Brian Anderson 2011-05-22 01:36:01 -04:00
parent 10c904bc6a
commit 1ecd6a82ab

View file

@ -368,16 +368,16 @@ fn starts_with(str haystack, str needle) -> bool {
fn ends_with(str haystack, str needle) -> bool {
let uint haystack_len = byte_len(haystack);
let uint needle_len = byte_len(needle);
if (needle_len == 0u) {
ret true;
}
if (needle_len > haystack_len) {
ret false;
}
ret eq(substr(haystack,
ret if (needle_len == 0u) {
true
} else if (needle_len > haystack_len) {
false
} else {
eq(substr(haystack,
haystack_len - needle_len,
needle_len),
needle);
needle)
};
}
fn substr(str s, uint begin, uint len) -> str {