| 46 | }; |
| 47 | // Returns null on an unterminated quote or a quote run into the next token. |
| 48 | const readQuoted = (): string | null => { |
| 49 | let value = ""; |
| 50 | i += 1; // opening quote |
| 51 | while (i < len) { |
| 52 | const ch = header[i]!; |
| 53 | if (ch === '"') { |
| 54 | i += 1; |
| 55 | return i >= len || /[\s,]/.test(header[i]!) ? value : null; |
| 56 | } |
| 57 | if (ch === "\\" && i + 1 < len) { |
| 58 | value += header[i + 1]; |
| 59 | i += 2; |
| 60 | continue; |
| 61 | } |
| 62 | value += ch; |
| 63 | i += 1; |
| 64 | } |
| 65 | return null; // unterminated |
| 66 | }; |
| 67 | |
| 68 | while (i < len) { |
| 69 | while (i < len && /\s/.test(header[i]!)) i += 1; |