From 76d58c0766518fe5ab2635de60ba40972565a3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:13:20 +0100 Subject: [PATCH] fix underflow error in get_count --- src/datapack/command/mod.rs | 2 +- src/util/macro_string.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/datapack/command/mod.rs b/src/datapack/command/mod.rs index 6e2e028..eb8f291 100644 --- a/src/datapack/command/mod.rs +++ b/src/datapack/command/mod.rs @@ -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, diff --git a/src/util/macro_string.rs b/src/util/macro_string.rs index 11dfbc4..24988d5 100644 --- a/src/util/macro_string.rs +++ b/src/util/macro_string.rs @@ -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::()