diff options
| author | zhibog <zhibog-github@web.de> | 2019-11-08 20:16:56 +0100 |
|---|---|---|
| committer | zhibog <zhibog-github@web.de> | 2019-11-08 20:16:56 +0100 |
| commit | 80cdf8b6a803cd510c8eff29e883124d2608a184 (patch) | |
| tree | ba36e8d5bde561b931516b51ff87cfa6b26b8d43 /core/encoding | |
| parent | dc2d5239c5801fb8ac7fea5b4b9717067eb5ce8f (diff) | |
Should be row_count obviously
Diffstat (limited to 'core/encoding')
| -rw-r--r-- | core/encoding/csv/csv.odin | 20 |
1 files 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 |