This commit is contained in:
aozhiwei 2020-09-03 20:06:44 +08:00
parent f54243a465
commit 4192dcc9fc
2 changed files with 22 additions and 4 deletions

View File

@ -3,10 +3,11 @@ package q5
import "io" import "io"
import "os" import "os"
import "bufio" import "bufio"
import "strings"
type CsvReader struct { type CsvReader struct {
columns map[string]int32 columns map[string]int32
values []XValue values []string
currLine int currLine int
lines []string lines []string
@ -14,7 +15,7 @@ type CsvReader struct {
func (this *CsvReader) Load(fileName string) bool { func (this *CsvReader) Load(fileName string) bool {
this.columns = map[string]int32{} this.columns = map[string]int32{}
this.values = []XValue{} this.values = []string{}
this.currLine = 0 this.currLine = 0
this.lines = []string{} this.lines = []string{}
@ -38,14 +39,25 @@ func (this *CsvReader) NextLine() bool {
if this.currLine >= len(this.lines) { if this.currLine >= len(this.lines) {
return false return false
} }
this.values = strings.Split(this.lines[this.currLine], ",")
this.currLine++ this.currLine++
return true return true
} }
func (this *CsvReader) GetValue(fieldName string) *XValue { func (this *CsvReader) GetValue(fieldName string) *XValue {
return nil index, ok := this.columns[fieldName]
if ok {
if index >= 0 && index < int32(len(this.values)) {
return (&XValue{}).SetString(this.values[index])
} else {
return &XValue{}
}
} else {
return &XValue{}
}
} }
func (this *CsvReader) KeyExists(fieldName string) bool { func (this *CsvReader) KeyExists(fieldName string) bool {
return true _, ok := this.columns[fieldName]
return ok
} }

View File

@ -1,5 +1,11 @@
package q5 package q5
import "time"
func GetDaySeconds(seconds int64) int64 { func GetDaySeconds(seconds int64) int64 {
return 0 return 0
} }
func GetTickCount() int64 {
return time.Now().UnixNano() / 1e6
}