func readRow(r *yacr.Reader, buffer row, pEof bool) (row, row, bool) { if pEof { return buffer, nil, pEof } var eof bool var v, cv []byte orig := buffer i := 0 buffer = buffer[:0] for { if r.Scan() { v = r.Bytes() // must be copied if i < len(orig) { cv = orig[i] cv = append(cv[:0], v...) } else { cv = make([]byte, len(v)) copy(cv, v) } buffer = append(buffer, cv) if r.EndOfRecord() { break } } else { eof = true break } i++ } if err := r.Err(); err != nil { log.Fatalf("Error while reading file: '%s'\n", err) } if len(buffer) == 0 { return buffer, nil, eof } return buffer, buffer, eof }
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 }