2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
//! Escapes text sequences
|
2012-03-16 14:20:29 -05:00
|
|
|
|
2013-01-08 21:37:25 -06:00
|
|
|
use pass::Pass;
|
2012-12-23 16:41:37 -06:00
|
|
|
use text_pass;
|
|
|
|
|
|
|
|
use core::str;
|
|
|
|
|
2012-11-19 20:00:12 -06:00
|
|
|
pub 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
|
|
|
}
|
|
|
|
|
2013-01-30 20:52:31 -06:00
|
|
|
fn escape(s: &str) -> ~str {
|
2012-07-14 00:57:48 -05:00
|
|
|
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);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(r == ~"\\\\n");
|
2012-03-16 14:20:29 -05:00
|
|
|
}
|