Skip to content

Commit

Permalink
lint-docs: Use strip-prefix to simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Nov 29, 2020
1 parent 228510b commit a90fdfc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/tools/lint-docs/src/lib.rs
Expand Up @@ -142,8 +142,8 @@ impl<'a> LintExtractor<'a> {
match lines.next() {
Some((lineno, line)) => {
let line = line.trim();
if line.starts_with("/// ") {
doc_lines.push(line.trim()[4..].to_string());
if let Some(text) = line.strip_prefix("/// ") {
doc_lines.push(text.trim().to_string());
} else if line.starts_with("///") {
doc_lines.push("".to_string());
} else if line.starts_with("// ") {
Expand Down Expand Up @@ -347,8 +347,7 @@ impl<'a> LintExtractor<'a> {
let mut source = String::new();
let needs_main = !example.iter().any(|line| line.contains("fn main"));
// Remove `# ` prefix for hidden lines.
let unhidden =
example.iter().map(|line| if line.starts_with("# ") { &line[2..] } else { line });
let unhidden = example.iter().map(|line| line.strip_prefix("# ").unwrap_or(line));
let mut lines = unhidden.peekable();
while let Some(line) = lines.peek() {
if line.starts_with("#!") {
Expand Down

0 comments on commit a90fdfc

Please sign in to comment.