rust/src/librustdoc/escape_pass.rs

27 lines
747 B
Rust
Raw Normal View History

// 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.
//! Escapes text sequences
2012-03-16 14:20:29 -05:00
2012-11-19 20:00:12 -06:00
pub fn mk_pass() -> Pass {
text_pass::mk_pass(~"escape", escape)
2012-03-16 14:20:29 -05:00
}
fn escape(s: ~str) -> ~str {
str::replace(s, ~"\\", ~"\\\\")
2012-03-16 14:20:29 -05:00
}
#[test]
fn should_escape_backslashes() {
let s = ~"\\n";
2012-03-16 14:20:29 -05:00
let r = escape(s);
assert r == ~"\\\\n";
2012-03-16 14:20:29 -05:00
}