diff options
| author | Marijn Haverbeke <[email protected]> | 2011-04-26 17:38:14 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <[email protected]> | 2011-04-26 17:38:14 +0200 |
| commit | d0ed2e384a3b90394ca0f160e21a4948a1dbccb0 (patch) | |
| tree | 441ab18b344d22d31848ea545f781de8af8d280d /src/lib/_str.rs | |
| parent | rustc: Add a missing return value to Collect.ty_of_item() (diff) | |
| download | rust-d0ed2e384a3b90394ca0f160e21a4948a1dbccb0.tar.xz rust-d0ed2e384a3b90394ca0f160e21a4948a1dbccb0.zip | |
Add _str.slice to std lib
Diffstat (limited to 'src/lib/_str.rs')
| -rw-r--r-- | src/lib/_str.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lib/_str.rs b/src/lib/_str.rs index 3922acb6..41a86cf3 100644 --- a/src/lib/_str.rs +++ b/src/lib/_str.rs @@ -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; |