/* WriteRow dump content of Row to file using format in metadata. */ func (writer *Writer) WriteRow(row *tabula.Row, recordMd []MetadataInterface) ( e error, ) { nRecord := row.Len() v := []byte{} esc := []byte(DefEscape) for i := range writer.OutputMetadata { md := writer.OutputMetadata[i] // find the input index based on name on record metadata. rIdx, mdMatch := FindMetadata(&md, recordMd) // No input metadata matched? skip it too. if rIdx >= nRecord { continue } // If input column is ignored, continue to next record. if mdMatch != nil && mdMatch.GetSkip() { continue } recV := (*row)[rIdx].Bytes() lq := md.GetLeftQuote() if "" != lq { v = append(v, []byte(lq)...) } rq := md.GetRightQuote() sep := md.GetSeparator() // Escape the escape character itself. if md.T == tabula.TString { recV, _ = tekstus.BytesEncapsulate(esc, recV, esc, nil) } // Escape the right quote in field content before writing it. if "" != rq && md.T == tabula.TString { recV, _ = tekstus.BytesEncapsulate([]byte(rq), recV, esc, nil) } else { // Escape the separator if "" != sep && md.T == tabula.TString { recV, _ = tekstus.BytesEncapsulate([]byte(sep), recV, esc, nil) } } v = append(v, recV...) if "" != rq { v = append(v, []byte(rq)...) } if "" != sep { v = append(v, []byte(sep)...) } } v = append(v, DefEOL) _, e = writer.BufWriter.Write(v) return e }