Fixed bug where empty lines would be discarded from output
This commit is contained in:
10
kg/main.go
10
kg/main.go
@@ -195,6 +195,11 @@ func main() {
|
|||||||
panic(err)
|
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)
|
matchIndices := make([]reg.Match, 0)
|
||||||
if matchNumFlagEnabled {
|
if matchNumFlagEnabled {
|
||||||
tmp, err := regComp.FindNthMatch(test_str, *matchNum)
|
tmp, err := regComp.FindNthMatch(test_str, *matchNum)
|
||||||
@@ -307,9 +312,10 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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 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') &&
|
if (len(test_str_runes) == 0) || ((len(test_str_runes) > 0 && test_str_runes[len(test_str_runes)-1] != '\n') &&
|
||||||
(!*onlyFlag || indicesToPrint.len() > 0) {
|
(!*onlyFlag || indicesToPrint.len() > 0)) {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user