2012-12-03 16:48:01 -08: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 22:53:12 +01:00
|
|
|
//! Escapes text sequences
|
2012-03-16 12:20:29 -07:00
|
|
|
|
2013-01-08 19:37:25 -08:00
|
|
|
use pass::Pass;
|
2012-12-23 17:41:37 -05:00
|
|
|
use text_pass;
|
|
|
|
|
|
|
|
use core::str;
|
|
|
|
|
2012-11-19 18:00:12 -08:00
|
|
|
pub fn mk_pass() -> Pass {
|
2012-07-13 22:57:48 -07:00
|
|
|
text_pass::mk_pass(~"escape", escape)
|
2012-03-16 12:20:29 -07:00
|
|
|
}
|
|
|
|
|
2013-01-30 18:52:31 -08:00
|
|
|
fn escape(s: &str) -> ~str {
|
2012-07-13 22:57:48 -07:00
|
|
|
str::replace(s, ~"\\", ~"\\\\")
|
2012-03-16 12:20:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_escape_backslashes() {
|
2012-07-13 22:57:48 -07:00
|
|
|
let s = ~"\\n";
|
2012-03-16 12:20:29 -07:00
|
|
|
let r = escape(s);
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!(r == ~"\\\\n");
|
2012-03-16 12:20:29 -07:00
|
|
|
}
|