UlrickBL commited on
Commit
21dd092
·
verified ·
1 Parent(s): f9bfa06

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +30 -7
index.html CHANGED
@@ -86,14 +86,37 @@
86
  </div>
87
 
88
  <script>
89
- // Function to parse CSV file
90
  function parseCSV(content) {
91
- const rows = content.split("\n").filter(row => row.trim() !== "");
92
- const headers = rows.shift().split(",");
93
- return {
94
- headers,
95
- rows: rows.map(row => row.split(","))
96
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
  // Load CSV file
 
86
  </div>
87
 
88
  <script>
89
+ // Improved CSV parsing to handle quoted fields
90
  function parseCSV(content) {
91
+ const rows = [];
92
+ let currentRow = [];
93
+ let currentField = '';
94
+ let insideQuotes = false;
95
+
96
+ for (let i = 0; i < content.length; i++) {
97
+ const char = content[i];
98
+
99
+ if (char === '"') {
100
+ insideQuotes = !insideQuotes;
101
+ } else if (char === ',' && !insideQuotes) {
102
+ currentRow.push(currentField.trim());
103
+ currentField = '';
104
+ } else if (char === '\n' && !insideQuotes) {
105
+ currentRow.push(currentField.trim());
106
+ rows.push(currentRow);
107
+ currentRow = [];
108
+ currentField = '';
109
+ } else {
110
+ currentField += char;
111
+ }
112
+ }
113
+
114
+ // Add the last field and row
115
+ if (currentField) currentRow.push(currentField.trim());
116
+ if (currentRow.length > 0) rows.push(currentRow);
117
+
118
+ const headers = rows.shift();
119
+ return { headers, rows };
120
  }
121
 
122
  // Load CSV file