1
This commit is contained in:
parent
5d0b0eacad
commit
f54243a465
26
csvreader.go
26
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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user