increase buffer size to 2MB and display an error when it is exhausted

pull/339/head
khimaros 10 months ago
parent 072fae2f6c
commit c4aae3383d

@ -2,6 +2,7 @@ package strings
import (
"bufio"
"log"
"net/url"
"regexp"
"strconv"
@ -37,9 +38,15 @@ func Pluralize(word string, count int) string {
func SplitLines(s string) []string {
var lines []string
scanner := bufio.NewScanner(strings.NewReader(s))
// increase the buffer size to 2Mb
buf := []byte{}
scanner.Buffer(buf, 2048*1024)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatalf("error while scanning text: %v", err)
}
return lines
}

Loading…
Cancel
Save