Skip to content

Commit d0ed2e3

Browse files
committed
Add _str.slice to std lib
1 parent 2746d20 commit d0ed2e3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/_str.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,14 @@ fn ends_with(str haystack, str needle) -> bool {
391391
}
392392

393393
fn substr(str s, uint begin, uint len) -> str {
394+
ret slice(s, begin, begin + len);
395+
}
396+
397+
fn slice(str s, uint begin, uint end) -> str {
394398
let str accum = "";
395399
let uint i = begin;
396-
while (i < begin+len) {
397-
accum += unsafe_from_byte(s.(i));
400+
while (i < end) {
401+
push_byte(accum, s.(i));
398402
i += 1u;
399403
}
400404
ret accum;

0 commit comments

Comments
 (0)