stdlib: Use if/alt expressions in std::str
This commit is contained in:
parent
10c904bc6a
commit
1ecd6a82ab
1 changed files with 8 additions and 8 deletions
|
@ -368,16 +368,16 @@ fn starts_with(str haystack, str needle) -> bool {
|
||||||
fn ends_with(str haystack, str needle) -> bool {
|
fn ends_with(str haystack, str needle) -> bool {
|
||||||
let uint haystack_len = byte_len(haystack);
|
let uint haystack_len = byte_len(haystack);
|
||||||
let uint needle_len = byte_len(needle);
|
let uint needle_len = byte_len(needle);
|
||||||
if (needle_len == 0u) {
|
ret if (needle_len == 0u) {
|
||||||
ret true;
|
true
|
||||||
}
|
} else if (needle_len > haystack_len) {
|
||||||
if (needle_len > haystack_len) {
|
false
|
||||||
ret false;
|
} else {
|
||||||
}
|
eq(substr(haystack,
|
||||||
ret eq(substr(haystack,
|
|
||||||
haystack_len - needle_len,
|
haystack_len - needle_len,
|
||||||
needle_len),
|
needle_len),
|
||||||
needle);
|
needle)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn substr(str s, uint begin, uint len) -> str {
|
fn substr(str s, uint begin, uint len) -> str {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue