diff options
| -rw-r--r-- | src/lib/str.rs | 6 | ||||
| -rw-r--r-- | src/test/stdtest/str.rs | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/str.rs b/src/lib/str.rs index 0adf3561165..b3a94cd6e12 100644 --- a/src/lib/str.rs +++ b/src/lib/str.rs @@ -53,6 +53,7 @@ export unsafe_from_bytes_ivec; export is_empty; export is_not_empty; export replace; +export char_slice; native "rust" mod rustrt { type sbuf; @@ -518,6 +519,11 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str { } } +// FIXME: Also not efficient +fn char_slice(s: &str, begin: uint, end: uint) -> str { + from_chars(vec::slice(to_chars(s), begin, end)) +} + // Local Variables: // mode: rust; // fill-column: 78; diff --git a/src/test/stdtest/str.rs b/src/test/stdtest/str.rs index f2b6a6b46ec..00652996e77 100644 --- a/src/test/stdtest/str.rs +++ b/src/test/stdtest/str.rs @@ -154,6 +154,13 @@ fn test_replace() { assert (str::replace(" test test ", test, "") == " "); } +#[test] +fn test_char_slice() { + assert (str::eq("ab", str::char_slice("abc", 0u, 2u))); + assert (str::eq("bc", str::char_slice("abc", 1u, 3u))); + assert (str::eq("", str::char_slice("abc", 1u, 1u))); + assert (str::eq("\u65e5", str::char_slice("\u65e5\u672c", 0u, 1u))); +} // Local Variables: // mode: rust; |
