Skip to content

Instantly share code, notes, and snippets.

@jamesmcm
Created December 5, 2019 20:55
Show Gist options
  • Select an option

  • Save jamesmcm/93a51c164692fb8ba837710ea04649c7 to your computer and use it in GitHub Desktop.

Select an option

Save jamesmcm/93a51c164692fb8ba837710ea04649c7 to your computer and use it in GitHub Desktop.
split_with_matches_broken.rs
fn split_with_matches<F>(s: &str, f: F) -> Vec<&str> where
F: Fn(char) -> bool {
let mut out: Vec<&str> = vec![];
let mut curstring: String = String::new();
for c in s.chars() {
if f(c) {
out.push(&curstring);
out.push(&c.to_string());
} else {
curstring.push(c);
}
}
out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment