| 24 | this.escape = conv.parseParam.escape; |
| 25 | } |
| 26 | parse(fileline: Fileline): RowSplitResult { |
| 27 | if (fileline.length === 0 || (this.conv.parseParam.ignoreEmpty && fileline.trim().length === 0)) { |
| 28 | return { cells: [], closed: true }; |
| 29 | } |
| 30 | const quote = this.quote; |
| 31 | const trim = this.trim; |
| 32 | const escape = this.escape; |
| 33 | if (this.conv.parseRuntime.delimiter instanceof Array || this.conv.parseRuntime.delimiter.toLowerCase() === "auto") { |
| 34 | this.conv.parseRuntime.delimiter = this.getDelimiter(fileline); |
| 35 | |
| 36 | } |
| 37 | if (this.needEmitDelimiter && !this.delimiterEmitted) { |
| 38 | this.conv.emit("delimiter", this.conv.parseRuntime.delimiter); |
| 39 | this.delimiterEmitted = true; |
| 40 | } |
| 41 | const delimiter = this.conv.parseRuntime.delimiter; |
| 42 | const rowArr = fileline.split(delimiter); |
| 43 | if (quote === "off") { |
| 44 | if (trim) { |
| 45 | for (let i = 0; i < rowArr.length; i++) { |
| 46 | rowArr[i] = rowArr[i].trim(); |
| 47 | } |
| 48 | } |
| 49 | return { cells: rowArr, closed: true }; |
| 50 | } else { |
| 51 | return this.toCSVRow(rowArr, trim, quote, delimiter); |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | private toCSVRow(rowArr: string[], trim: boolean, quote: string, delimiter: string): RowSplitResult { |
| 56 | const row: string[] = []; |
| 57 | let inquote = false; |