Skip to content

Instantly share code, notes, and snippets.

@thommay
Created October 27, 2015 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thommay/22eb052ee372fe1b4cc8 to your computer and use it in GitHub Desktop.
Save thommay/22eb052ee372fe1b4cc8 to your computer and use it in GitHub Desktop.
/// Remove duplicate and trailing slashes from a path
fn squeeze_path(pth: String) -> String {
let mut st = String::new();
for p in pth.split('/').filter(|&x| x != "") {
st.push('/');
st.push_str(p)
}
if st.len() == 0 {
String::from("/")
} else {
st
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment