From f54243a46587de5b53ea60a17b70aef4f74e02f5 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 28 Aug 2020 23:27:02 +0800 Subject: [PATCH] 1 --- csvreader.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/csvreader.go b/csvreader.go index fb47663..1eac367 100644 --- a/csvreader.go +++ b/csvreader.go @@ -1,24 +1,44 @@ package q5 -import "ioutil" +import "io" +import "os" +import "bufio" type CsvReader struct { columns map[string]int32 values []XValue - currLine int32 + currLine int + lines []string } func (this *CsvReader) Load(fileName string) bool { - f, err := ioutil.ReadFile(fileName) + this.columns = map[string]int32{} + this.values = []XValue{} + this.currLine = 0 + this.lines = []string{} + + f, err := os.Open(fileName) if err == nil { defer f.Close() + br := bufio.NewReader(f) + for { + line, _, c := br.ReadLine() + if c == io.EOF { + break + } + this.lines = append(this.lines, string(line)) + } } return err == nil } func (this *CsvReader) NextLine() bool { + if this.currLine >= len(this.lines) { + return false + } + this.currLine++ return true }