2012-07-04 16:53:12 -05:00
|
|
|
//! Escapes text sequences
|
2012-03-16 14:20:29 -05:00
|
|
|
|
|
|
|
export mk_pass;
|
|
|
|
|
2012-09-18 18:48:40 -05:00
|
|
|
fn mk_pass() -> Pass {
|
2012-07-14 00:57:48 -05:00
|
|
|
text_pass::mk_pass(~"escape", escape)
|
2012-03-16 14:20:29 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn escape(s: ~str) -> ~str {
|
|
|
|
str::replace(s, ~"\\", ~"\\\\")
|
2012-03-16 14:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_escape_backslashes() {
|
2012-07-14 00:57:48 -05:00
|
|
|
let s = ~"\\n";
|
2012-03-16 14:20:29 -05:00
|
|
|
let r = escape(s);
|
2012-07-14 00:57:48 -05:00
|
|
|
assert r == ~"\\\\n";
|
2012-03-16 14:20:29 -05:00
|
|
|
}
|