2020-12-11 03:32:15 +00:00
|
|
|
package util
|
|
|
|
|
2020-12-16 07:55:39 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2020-12-11 03:32:15 +00:00
|
|
|
// Takes a slice of strings as from reading each line in a file.
|
|
|
|
// Concatenates strings, creating new ones when blank lines are encountered
|
|
|
|
// NB: adds a single space to the beginning of each concatenated line.
|
|
|
|
func SplitOnBlankLine(input []string) []string {
|
|
|
|
converted := []string{}
|
|
|
|
|
|
|
|
current := ""
|
|
|
|
for _, line := range input {
|
|
|
|
if line == "" {
|
|
|
|
converted = append(converted, current)
|
|
|
|
current = ""
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
current += " " + line
|
|
|
|
}
|
|
|
|
|
|
|
|
return converted
|
|
|
|
}
|
2020-12-16 07:55:39 +00:00
|
|
|
|
|
|
|
func MustAtoi(input string) int {
|
|
|
|
ret, err := strconv.Atoi(input)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf(err.Error())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|