From 4e406d7fdd55c6c499eb3af750c64292a88e4d9f Mon Sep 17 00:00:00 2001 From: Kevin Cantu Date: Wed, 1 Feb 2012 03:32:15 -0800 Subject: [PATCH] Make it work 1 --- src/libcore/str.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index b0dbb5b1901c..a2124880ea38 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -424,7 +424,7 @@ fn chars(s: str) -> [char] { If `begin` + `len` is is greater than the byte length of the string */ -fn substr(s: str, begin: uint, len: uint) -> str { +fn substr(s: str, begin: uint, len: uint) -> str unsafe { ret unsafe::slice(s, begin, begin + len); } @@ -706,13 +706,14 @@ fn to_upper(s: str) -> str { The original string with all occurances of `from` replaced with `to` */ -fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str { +fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe { // FIXME (694): Shouldn't have to check this check (is_not_empty(from)); if byte_len(s) == 0u { ret ""; } else if starts_with(s, from) { - ret to + replace(unsafe::slice(s, byte_len(from), byte_len(s)), from, to); + ret to + replace(unsafe::slice(s, byte_len(from), byte_len(s)), + from, to); } else { let idx = find(s, from); if idx == -1 { @@ -1401,7 +1402,8 @@ unsafe fn slice(s: str, begin: uint, end: uint) -> str unsafe { FIXME: rename to safe_range_byte_slice */ - unsafe fn safe_slice(s: str, begin: uint, end: uint) : uint::le(begin, end) -> str { + unsafe fn safe_slice(s: str, begin: uint, end: uint) + : uint::le(begin, end) -> str { // would need some magic to make this a precondition assert (end <= byte_len(s)); ret slice(s, begin, end); @@ -1634,7 +1636,7 @@ fn test_to_lower() { } #[test] - fn test_slice() { + fn test_unsafe_slice() unsafe { assert (eq("ab", slice("abc", 0u, 2u))); assert (eq("bc", slice("abc", 1u, 3u))); assert (eq("", slice("abc", 1u, 1u))); @@ -1651,7 +1653,7 @@ fn half_a_million_letter_a() -> str { ret rs; } assert (eq(half_a_million_letter_a(), - slice(a_million_letter_a(), 0u, 500000u))); + unsafe::slice(a_million_letter_a(), 0u, 500000u))); } #[test]