Fixed bug where empty lines would be discarded from output

This commit is contained in:
2025-12-19 13:40:06 -05:00
parent 3c61ab16ae
commit 2e2dcf61f9

View File

@@ -195,6 +195,11 @@ func main() {
panic(err)
}
}
// We check again if linesRead is true, because if it is and we haven't read anything,
// then we can just exit.
if linesRead && len(test_str) == 0 {
break
}
matchIndices := make([]reg.Match, 0)
if matchNumFlagEnabled {
tmp, err := regComp.FindNthMatch(test_str, *matchNum)
@@ -307,9 +312,10 @@ func main() {
if err != nil {
panic(err)
}
// If the line was empty, OR
// If the last character in the string wasn't a newline, AND we either have don't -o set or we do (and we've matched something), then print a newline
if (len(test_str_runes) > 0 && test_str_runes[len(test_str_runes)-1] != '\n') &&
(!*onlyFlag || indicesToPrint.len() > 0) {
if (len(test_str_runes) == 0) || ((len(test_str_runes) > 0 && test_str_runes[len(test_str_runes)-1] != '\n') &&
(!*onlyFlag || indicesToPrint.len() > 0)) {
fmt.Println()
}
}