Created
August 25, 2016 15:56
-
-
Save anonymous/a57ce4294af3ce876d3818a459071d2c 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