Add _str.slice to std lib
This commit is contained in:
parent
2746d20c83
commit
d0ed2e384a
1 changed files with 6 additions and 2 deletions
|
|
@ -391,10 +391,14 @@ fn ends_with(str haystack, str needle) -> bool {
|
|||
}
|
||||
|
||||
fn substr(str s, uint begin, uint len) -> str {
|
||||
ret slice(s, begin, begin + len);
|
||||
}
|
||||
|
||||
fn slice(str s, uint begin, uint end) -> str {
|
||||
let str accum = "";
|
||||
let uint i = begin;
|
||||
while (i < begin+len) {
|
||||
accum += unsafe_from_byte(s.(i));
|
||||
while (i < end) {
|
||||
push_byte(accum, s.(i));
|
||||
i += 1u;
|
||||
}
|
||||
ret accum;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue