func (obj *Idcsv) load(t *tool.TFile) { headStr := t.NextLine(0) //the first line headArr := strings.Split(*headStr, ",") num := len(headArr) if num < 2 { fmt.Println("error format for dict") return } L: for { lineStr := t.Next() if lineStr == nil { break L } lineArr := strings.Split(*lineStr, ",") if len(lineArr) != num { fmt.Printf("error format string #%v#, bad num #%v#%v#\n", lineStr, len(lineArr), num) continue } for idx, str := range headArr { if str != "" || lineArr[idx] == "" { continue } obj.addItem(lineArr[idx-1], strings.Trim(lineArr[idx], " ")) } } }
// End used to func (r *Rout) End(ch core.RoutineChan) { var t *tool.TFile var ok bool if t, ok = ch.(*tool.TFile); !ok { fmt.Println("dict-csv.go error") return } headStr := t.NextLine(0) //the first line headArr := strings.Split(*headStr, ",") num := len(headArr) if num < 2 { fmt.Println("error format for dict") return } L: for { lineStr := t.Next() if lineStr == nil { break L } lineArr := make([]string, num) formatKey([]rune(*lineStr), lineArr) if len(lineArr) != num { fmt.Printf("error format string #%v#, bad num #%v#%v#\n", *lineStr, len(lineArr), num) continue } for idx, str := range headArr { if str != "" || lineArr[idx] == "" { continue } addItem(r.Dict, lineArr[idx-1], strings.Trim(lineArr[idx], " ")) } } }