feat: add new fields to dataset_entry and update related components for processing and display
This commit is contained in:
34
src/lib/csv-parser.ts
Normal file
34
src/lib/csv-parser.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* CSV parser that handles quoted fields
|
||||
*/
|
||||
export function parseCSVLine(line: string): string[] {
|
||||
const values: string[] = [];
|
||||
let current = '';
|
||||
let inQuotes = false;
|
||||
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const char = line[i];
|
||||
const nextChar = line[i + 1];
|
||||
|
||||
if (char === '"') {
|
||||
if (inQuotes && nextChar === '"') {
|
||||
// Escaped quote
|
||||
current += '"';
|
||||
i++;
|
||||
} else {
|
||||
// Toggle quote state
|
||||
inQuotes = !inQuotes;
|
||||
}
|
||||
} else if (char === ',' && !inQuotes) {
|
||||
// Field separator
|
||||
values.push(current.trim());
|
||||
current = '';
|
||||
} else {
|
||||
current += char;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the last field
|
||||
values.push(current.trim());
|
||||
return values;
|
||||
}
|
||||
Reference in New Issue
Block a user