Skip to content

Commit 6b0dd00

Browse files
committed
---
yaml --- r: 82640 b: refs/heads/auto c: bcc7daa h: refs/heads/master v: v3
1 parent 398ab8e commit 6b0dd00

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 35c0cdff5a5fc9e41468ce167c9304ba43028ac4
16+
refs/heads/auto: bcc7daa6bcf9728eca36512975f9251a946618d7
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libextra/getopts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
//! that requires an input file to be specified, accepts an optional output
3030
//! file name following -o, and accepts both -h and --help as optional flags.
3131
//!
32-
//! ```
32+
//! ~~~{.rust}
3333
//! exter mod extra;
3434
//! use extra::getopts::*;
3535
//! use std::os;
@@ -75,7 +75,7 @@
7575
//! };
7676
//! do_work(input, output);
7777
//! }
78-
//! ```
78+
//! ~~~
7979
8080
use std::cmp::Eq;
8181
use std::result::{Err, Ok};

branches/auto/src/libsyntax/parse/comments.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,19 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
5959
fn vertical_trim(lines: ~[~str]) -> ~[~str] {
6060
let mut i = 0u;
6161
let mut j = lines.len();
62+
// first line of all-stars should be omitted
63+
if lines.len() > 0 && lines[0].iter().all(|c| c == '*') {
64+
i += 1;
65+
}
6266
while i < j && lines[i].trim().is_empty() {
63-
i += 1u;
67+
i += 1;
68+
}
69+
// like the first, a last line of all stars should be omitted
70+
if j > i && lines[j - 1].iter().skip(1).all(|c| c == '*') {
71+
j -= 1;
6472
}
65-
while j > i && lines[j - 1u].trim().is_empty() {
66-
j -= 1u;
73+
while j > i && lines[j - 1].trim().is_empty() {
74+
j -= 1;
6775
}
6876
return lines.slice(i, j).to_owned();
6977
}
@@ -106,8 +114,12 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
106114
}
107115
}
108116

109-
if comment.starts_with("//") {
110-
return comment.slice(3u, comment.len()).to_owned();
117+
// one-line comments lose their prefix
118+
static ONLINERS: &'static [&'static str] = &["///!", "///", "//!", "//"];
119+
for prefix in ONLINERS.iter() {
120+
if comment.starts_with(*prefix) {
121+
return comment.slice_from(prefix.len()).to_owned();
122+
}
111123
}
112124

113125
if comment.starts_with("/*") {
@@ -384,29 +396,42 @@ mod test {
384396

385397
#[test] fn test_block_doc_comment_1() {
386398
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
387-
let correct_stripped = " Test \n* Test\n Test";
388399
let stripped = strip_doc_comment_decoration(comment);
389-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
400+
assert_eq!(stripped, ~" Test \n* Test\n Test");
390401
}
391402
392403
#[test] fn test_block_doc_comment_2() {
393404
let comment = "/**\n * Test\n * Test\n*/";
394-
let correct_stripped = " Test\n Test";
395405
let stripped = strip_doc_comment_decoration(comment);
396-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
406+
assert_eq!(stripped, ~" Test\n Test");
397407
}
398408
399409
#[test] fn test_block_doc_comment_3() {
400410
let comment = "/**\n let a: *int;\n *a = 5;\n*/";
401-
let correct_stripped = " let a: *int;\n *a = 5;";
402411
let stripped = strip_doc_comment_decoration(comment);
403-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
412+
assert_eq!(stripped, ~" let a: *int;\n *a = 5;");
404413
}
405414
406-
#[test] fn test_line_doc_comment() {
407-
let comment = "/// Test";
408-
let correct_stripped = " Test";
415+
#[test] fn test_block_doc_comment_4() {
416+
let comment = "/*******************\n test\n *********************/";
409417
let stripped = strip_doc_comment_decoration(comment);
410-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
418+
assert_eq!(stripped, ~" test");
419+
}
420+
421+
#[test] fn test_line_doc_comment() {
422+
let stripped = strip_doc_comment_decoration("/// test");
423+
assert_eq!(stripped, ~" test");
424+
let stripped = strip_doc_comment_decoration("///! test");
425+
assert_eq!(stripped, ~" test");
426+
let stripped = strip_doc_comment_decoration("// test");
427+
assert_eq!(stripped, ~" test");
428+
let stripped = strip_doc_comment_decoration("// test");
429+
assert_eq!(stripped, ~" test");
430+
let stripped = strip_doc_comment_decoration("///test");
431+
assert_eq!(stripped, ~"test");
432+
let stripped = strip_doc_comment_decoration("///!test");
433+
assert_eq!(stripped, ~"test");
434+
let stripped = strip_doc_comment_decoration("//test");
435+
assert_eq!(stripped, ~"test");
411436
}
412437
}

0 commit comments

Comments
 (0)