-
-
Save jpastuszek/87c5daf36c35d47749fba41e234c38d2 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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
// This code is editable and runnable! | |
fn main() { | |
let s = "foo\"bar\"baz\""; | |
//println!("{}", s.split('"').collect::<Vec<_>>().join("\\\"")); | |
let mut iter = s.split('"').peekable(); | |
loop { | |
match (iter.next(), iter.peek()) { | |
(Some(i), Some(_)) => print!("{}\\\"", i), | |
(Some(i), None) => { | |
print!("{}", i); | |
break | |
} | |
_ => unreachable!() | |
} | |
} | |
/* | |
for i in iter { | |
println!("{:?}", iter.peek()); | |
print!("{}\\\"", i); | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment