-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto merge of #9577 : alexcrichton/rust/rustdoc, r=cmr
They're getting smaller each time though! The highlight of this round is source files in documentation. Still trying to figure out the best syntax-highlighting solution.
- Loading branch information
Showing
10 changed files
with
313 additions
and
136 deletions.
There are no files selected for viewing
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2013 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. | ||
|
||
use std::fmt; | ||
|
||
pub struct Escape<'self>(&'self str); | ||
|
||
impl<'self> fmt::Default for Escape<'self> { | ||
fn fmt(s: &Escape<'self>, fmt: &mut fmt::Formatter) { | ||
// Because the internet is always right, turns out there's not that many | ||
// characters to escape: http://stackoverflow.com/questions/7381974 | ||
let pile_o_bits = s.as_slice(); | ||
let mut last = 0; | ||
for (i, ch) in s.byte_iter().enumerate() { | ||
match ch as char { | ||
'<' | '>' | '&' | '\'' | '"' => { | ||
fmt.buf.write(pile_o_bits.slice(last, i).as_bytes()); | ||
let s = match ch as char { | ||
'>' => ">", | ||
'<' => "<", | ||
'&' => "&", | ||
'\'' => "'", | ||
'"' => """, | ||
_ => unreachable!() | ||
}; | ||
fmt.buf.write(s.as_bytes()); | ||
last = i + 1; | ||
} | ||
_ => {} | ||
} | ||
} | ||
|
||
if last < s.len() { | ||
fmt.buf.write(pile_o_bits.slice_from(last).as_bytes()); | ||
} | ||
} | ||
} |
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 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
Oops, something went wrong.