Skip to content

Commit 1ccd5a9

Browse files
committed
Use strip_prefix instead of starts_with and indexing
1 parent 8545974 commit 1ccd5a9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/rust-project-goals/src/markwaydown.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ fn categorize_line(line: &str) -> CategorizeLine {
163163
if line.starts_with('#') {
164164
let level = line.chars().take_while(|&ch| ch == '#').count();
165165
CategorizeLine::Title(level, line.trim_start_matches('#').trim().to_string())
166-
} else if line.starts_with('|') && line.ends_with('|') {
167-
let line = &line[1..line.len() - 1];
166+
} else if let Some(line) = line
167+
.strip_prefix('|')
168+
.and_then(|line| line.strip_suffix('|'))
169+
{
168170
let columns = line.split('|').map(|s| s.trim());
169171
if columns.clone().all(|s| s.chars().all(|c| c == '-')) {
170172
CategorizeLine::TableDashRow(columns.count())

0 commit comments

Comments
 (0)