From 3eeb401d222be0439dce28ac33df40617793a6c3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 29 Jul 2022 12:17:55 +0900 Subject: [PATCH] internal/gamepaddb: refactoring --- internal/gamepaddb/gamepaddb.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/internal/gamepaddb/gamepaddb.go b/internal/gamepaddb/gamepaddb.go index 38705d81a..fd4aa7a8c 100644 --- a/internal/gamepaddb/gamepaddb.go +++ b/internal/gamepaddb/gamepaddb.go @@ -26,7 +26,6 @@ import ( "bufio" "bytes" "fmt" - "io" "runtime" "strconv" "strings" @@ -513,7 +512,7 @@ func Update(mappingData []byte) error { defer mappingsM.Unlock() buf := bytes.NewBuffer(mappingData) - r := bufio.NewReader(buf) + s := bufio.NewScanner(buf) type parsedLine struct { id string @@ -523,15 +522,12 @@ func Update(mappingData []byte) error { } var lines []parsedLine - for { - line, err := r.ReadString('\n') - if err != nil && err != io.EOF { + for s.Scan() { + line := s.Text() + id, name, buttons, axes, err := parseLine(line, currentPlatform) + if err != nil { return err } - id, name, buttons, axes, err1 := parseLine(line, currentPlatform) - if err1 != nil { - return err1 - } if id != "" { lines = append(lines, parsedLine{ id: id, @@ -540,9 +536,10 @@ func Update(mappingData []byte) error { axes: axes, }) } - if err == io.EOF { - break - } + } + + if err := s.Err(); err != nil { + return err } for _, l := range lines {