Esempio n. 1
0
func (v *csvTab) readRow(r *yacr.Reader) error {
	v.cols = v.cols[:0]
	for {
		if !r.Scan() {
			err := r.Err()
			v.eof = err == nil
			return err
		}
		if r.EndOfRecord() && len(r.Bytes()) == 0 { // skip empty line (or line comment)
			continue
		}
		col := r.Text()
		if len(col) >= v.maxLength {
			return fmt.Errorf("CSV row is too long (>= %d)", v.maxLength)
		}
		v.cols = append(v.cols, col)
		if len(v.cols) >= v.maxColumn {
			return fmt.Errorf("too many columns (>= %d)", v.maxColumn)
		}
		if r.EndOfRecord() {
			break
		}
	}
	return nil
}