diff options
-rw-r--r-- | cmd/dehyphenate/main.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/cmd/dehyphenate/main.go b/cmd/dehyphenate/main.go index ed8eb13..afd1aac 100644 --- a/cmd/dehyphenate/main.go +++ b/cmd/dehyphenate/main.go @@ -68,11 +68,16 @@ func main() { for i, line := range lines { words := strings.Split(line, " ") last := words[len(words)-1] - if len(last) > 0 && last[len(last) - 1] == '-' { + // the - 2 here is to account for a trailing newline and counting from zero + if len(last) > 0 && last[len(last) - 1] == '-' && i < len(lines) - 2 { nextwords := strings.Split(lines[i+1], " ") - line = line[0:len(line)-1] + nextwords[0] + if len(nextwords) > 0 { + line = line[0:len(line)-1] + nextwords[0] + } if len(nextwords) > 1 { lines[i+1] = strings.Join(nextwords[1:], " ") + } else { + lines[i+1] = "" } } newlines = append(newlines, line) |