Created
August 24, 2011 01:04
-
-
Save brson/1167061 to your computer and use it in GitHub Desktop.
typestate in std::str::replace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn replace(s: &istr, from: &istr, to: &istr) : is_not_empty(from) -> istr { | |
if byte_len(s) == 0u { | |
ret ~""; | |
} else if starts_with(s, from) { | |
check (is_not_empty(from)); | |
ret to + replace(slice(s, byte_len(from), byte_len(s)), from, to); | |
} else { | |
check (is_not_empty(from)); | |
ret unsafe_from_byte(s[0]) + | |
replace(slice(s, 1u, byte_len(s)), from, to); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment