fix underflow error in get_count

This commit is contained in:
Moritz Hölting 2024-11-11 17:13:20 +01:00
parent 588bc3f464
commit 76d58c0766
2 changed files with 3 additions and 3 deletions

View File

@ -94,7 +94,7 @@ impl Command {
// TODO: change comment to compile to `1`, make sure nothing breaks
Self::Comment(_) => 0,
Self::Debug(_) => usize::from(options.debug),
Self::Raw(cmd) => cmd.lines().count(),
Self::Raw(cmd) => cmd.split('\n').count(),
Self::UsesMacro(cmd) => cmd.line_count(),
Self::Execute(ex) => ex.get_count(options),
Self::Group(_) => 1,

View File

@ -51,12 +51,12 @@ impl MacroString {
#[must_use]
pub fn line_count(&self) -> usize {
match self {
Self::String(s) => s.lines().count(),
Self::String(s) => s.split('\n').count(),
Self::MacroString(parts) => {
parts
.iter()
.map(|p| match p {
MacroStringPart::String(s) => s.lines().count() - 1,
MacroStringPart::String(s) => s.split('\n').count() - 1,
MacroStringPart::MacroUsage(_) => 0,
})
.sum::<usize>()