File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,10 @@ import (
2424 "strings"
2525 "sync"
2626
27- "github.com/duke-git/lancet/v2/validator"
2827 "golang.org/x/text/encoding/simplifiedchinese"
2928 "golang.org/x/text/transform"
29+
30+ "github.com/duke-git/lancet/v2/validator"
3031)
3132
3233// FileReader is a reader supporting offset seeking and reading one
@@ -283,21 +284,18 @@ func ReadFileByLine(path string) ([]string, error) {
283284 }
284285 defer f .Close ()
285286
287+ scanner := bufio .NewScanner (f )
286288 result := make ([]string , 0 )
287- buf := bufio .NewReader (f )
288289
289- for {
290- line , _ , err := buf .ReadLine ()
291- l := string (line )
292- if err == io .EOF {
293- break
294- }
295- if err != nil {
296- continue
297- }
290+ for scanner .Scan () {
291+ l := scanner .Text ()
298292 result = append (result , l )
299293 }
300294
295+ if err := scanner .Err (); err != nil {
296+ return nil , err
297+ }
298+
301299 return result , nil
302300}
303301
You can’t perform that action at this time.
0 commit comments