(text: string, out: Array<Parsed>)
| 270 | } |
| 271 | |
| 272 | feed(text: string, out: Array<Parsed>): void { |
| 273 | const length = text.length |
| 274 | const delimiter = this.delimiter |
| 275 | let i = 0 |
| 276 | if (length > 0 && !this.started) { |
| 277 | this.started = true |
| 278 | if (text.charCodeAt(0) === 0xFEFF) i = 1 |
| 279 | } |
| 280 | // The current record starts at `start` in this chunk, so its size at `i` |
| 281 | // is `this.size + i - start`. |
| 282 | let start = i |
| 283 | let state = this.state |
| 284 | let field = this.field |
| 285 | while (i < length) { |
| 286 | if (state === FIELD_START) { |
| 287 | if (this.skipLF) { |
| 288 | this.skipLF = false |
| 289 | if (text.charCodeAt(i) === LF) { |
| 290 | start = ++i |
| 291 | continue |
| 292 | } |
| 293 | } |
| 294 | if (text.charCodeAt(i) === QUOTE) { |
| 295 | state = QUOTED |
| 296 | this.quotedCR = false |
| 297 | i++ |
| 298 | continue |
| 299 | } |
| 300 | state = UNQUOTED |
| 301 | } |
| 302 | if (state === UNQUOTED) { |
| 303 | let j = i |
| 304 | let c = 0 |
| 305 | while (j < length) { |
| 306 | c = text.charCodeAt(j) |
| 307 | if (c === delimiter || c === CR || c === LF || c === QUOTE) break |
| 308 | j++ |
| 309 | } |
| 310 | if (j > i) field = field === "" ? text.slice(i, j) : field + text.slice(i, j) |
| 311 | if (j === length) { |
| 312 | i = j |
| 313 | break |
| 314 | } |
| 315 | if (c === QUOTE) { |
| 316 | throw this.failSyntax(this.size + j - start, "Unexpected quote in an unquoted field") |
| 317 | } |
| 318 | this.cells.push(field) |
| 319 | field = "" |
| 320 | state = FIELD_START |
| 321 | i = j + 1 |
| 322 | if (c !== delimiter) { |
| 323 | this.endRecord(this.size + j - start, out) |
| 324 | this.line++ |
| 325 | this.recordLine = this.line |
| 326 | this.skipLF = c === CR |
| 327 | start = i |
| 328 | } |
| 329 | continue |
no test coverage detected