Skip to content

Commit d826a08

Browse files
committed
---
yaml --- r: 4314 b: refs/heads/master c: 598e25e h: refs/heads/master v: v3
1 parent 3f3ac72 commit d826a08

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0c7a95fde5c1ea6d686c5194f2d46ff0f7305aca
2+
refs/heads/master: 598e25e09194f3ff89d413d9bb2a4246ce5cfeee

trunk/src/lib/str.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export unsafe_from_bytes_ivec;
5353
export is_empty;
5454
export is_not_empty;
5555
export replace;
56+
export char_slice;
5657

5758
native "rust" mod rustrt {
5859
type sbuf;
@@ -518,6 +519,11 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str {
518519
}
519520
}
520521

522+
// FIXME: Also not efficient
523+
fn char_slice(s: &str, begin: uint, end: uint) -> str {
524+
from_chars(vec::slice(to_chars(s), begin, end))
525+
}
526+
521527
// Local Variables:
522528
// mode: rust;
523529
// fill-column: 78;

trunk/src/test/stdtest/str.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ fn test_replace() {
154154
assert (str::replace(" test test ", test, "") == " ");
155155
}
156156

157+
#[test]
158+
fn test_char_slice() {
159+
assert (str::eq("ab", str::char_slice("abc", 0u, 2u)));
160+
assert (str::eq("bc", str::char_slice("abc", 1u, 3u)));
161+
assert (str::eq("", str::char_slice("abc", 1u, 1u)));
162+
assert (str::eq("\u65e5", str::char_slice("\u65e5\u672c", 0u, 1u)));
163+
}
157164

158165
// Local Variables:
159166
// mode: rust;

0 commit comments

Comments
 (0)