MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / parse_csv

Function parse_csv

frontend/wasm-src/data-processing/src/csv.rs:13–38  ·  view source on GitHub ↗
(data: &str, delimiter: char)

Source from the content-addressed store, hash-verified

11}
12
13pub 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
40pub fn detect_column_types(data: &Vec<Vec<String>>) -> Vec<ColumnType> {
41 if data.is_empty() || data.len() < 2 {

Callers

nothing calls this directly

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected