Skip to content

Commit

Permalink
Use strip_prefix instead of doing it manually with slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 19, 2023
1 parent 655228a commit 4195076
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,20 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
let ln = ln.trim();
if ln.starts_with("fn") || ln.starts_with("mod") {
return;
} else if ln.starts_with("//[") {
} else if let Some(ln) = ln.strip_prefix("//[") {
// A comment like `//[foo]` is specific to revision `foo`
if let Some(close_brace) = ln.find(']') {
let lncfg = &ln[3..close_brace];
let matches = match cfg {
Some(s) => s == &lncfg[..],
None => false,
};
if matches {
it(ln[(close_brace + 1) ..].trim_start());
if let Some((lncfg, ln)) = ln.split_once(']') {
if cfg == Some(lncfg) {
it(ln.trim_start());
}
} else {
panic!("malformed condition directive: expected `//[foo]`, found `{}`",
ln)
panic!(
"malformed condition directive: expected `//[foo]`, found `{}`",
ln
)
}
} else if ln.starts_with("//") {
it(ln[2..].trim_start());
} else if let Some(ln) = ln.strip_prefix("//") {
it(ln.trim_start());
}
}
return;
Expand Down

0 comments on commit 4195076

Please sign in to comment.