| 11 | } |
| 12 | |
| 13 | pub fn parse_csv(data: &str, delimiter: char) -> Vec<Vec<String>> { |
| 14 | let mut result = Vec::new(); |
| 15 | |
| 16 | for line in data.lines() { |
| 17 | let mut row = Vec::new(); |
| 18 | let mut field = String::new(); |
| 19 | let mut in_quotes = false; |
| 20 | |
| 21 | for c in line.chars() { |
| 22 | if c == '"' { |
| 23 | in_quotes = !in_quotes; |
| 24 | } else if c == delimiter && !in_quotes { |
| 25 | row.push(field.clone()); |
| 26 | field.clear(); |
| 27 | } else { |
| 28 | field.push(c); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // Don't forget the last field |
| 33 | row.push(field.clone()); |
| 34 | result.push(row); |
| 35 | } |
| 36 | |
| 37 | result |
| 38 | } |
| 39 | |
| 40 | pub fn detect_column_types(data: &Vec<Vec<String>>) -> Vec<ColumnType> { |
| 41 | if data.is_empty() || data.len() < 2 { |