q5/csvreader.go
aozhiwei f54243a465 1
2020-08-28 23:27:02 +08:00

52 lines
834 B
Go

package q5
import "io"
import "os"
import "bufio"
type CsvReader struct {
columns map[string]int32
values []XValue
currLine int
lines []string
}
func (this *CsvReader) Load(fileName string) bool {
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
}
func (this *CsvReader) GetValue(fieldName string) *XValue {
return nil
}
func (this *CsvReader) KeyExists(fieldName string) bool {
return true
}