From 80cdf8b6a803cd510c8eff29e883124d2608a184 Mon Sep 17 00:00:00 2001 From: zhibog Date: Fri, 8 Nov 2019 20:16:56 +0100 Subject: [PATCH] Should be row_count obviously --- core/encoding/csv/csv.odin | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/encoding/csv/csv.odin b/core/encoding/csv/csv.odin index a8f387e69..80af438c3 100644 --- a/core/encoding/csv/csv.odin +++ b/core/encoding/csv/csv.odin @@ -16,16 +16,16 @@ main :: proc() { // Write file and read with the headers omitted if isOkWrite := write(file_name, &ctx); isOkWrite { - if content, col_count, isOkRead := read(file_name, DELIMITER, true); isOkRead { - fmt.println("Column count(no headers): ", col_count); + if content, row_count, isOkRead := read(file_name, DELIMITER, true); isOkRead { + fmt.println("Column count(no headers): ", row_count); fmt.println(content); } } // Write file and read with the headers being read as well if isOkWrite := write(file_name, &ctx); isOkWrite { - if content, col_count, isOkRead := read(file_name); isOkRead { - fmt.println("Column count(with headers): ", col_count); + if content, row_count, isOkRead := read(file_name); isOkRead { + fmt.println("Column count(with headers): ", row_count); fmt.println(content); } } @@ -76,31 +76,31 @@ read :: proc(path: string, delimiter := DELIMITER, skip_header := false) -> ([]s cols: [dynamic]string; defer delete(cols); out: [dynamic]string; - col_count := 0; + row_count := 0; prev_index := 0; for i := 0; i < len(bytes); i += 1 { if bytes[i] == '\n' { append(&cols, string(bytes[prev_index:i])); i += 1; prev_index = i; - col_count += 1; + row_count += 1; } else if bytes[i] == '\r' { if bytes[i + 1] == '\n' { append(&cols, string(bytes[prev_index:i])); i += 2; prev_index = i; - col_count += 1; + row_count += 1; } else { append(&cols, string(bytes[prev_index:i])); i += 1; prev_index = i; - col_count += 1; + row_count += 1; } } } for col in cols do append(&out, ..strings.split(col, delimiter)); - if skip_header do return out[col_count:], col_count - 1, true; - else do return out[:], col_count, true; + if skip_header do return out[row_count:], row_count - 1, true; + else do return out[:], row_count, true; } return nil, -1, false; } \ No newline at end of file