diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2024-09-04 21:37:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-04 21:37:48 +0100 |
| commit | a4fd0c133e824e349f830cad171d46fc210faab4 (patch) | |
| tree | 8c869bc49609d68c5cd9e4e53a2b2f03b92f6297 /core/encoding/csv/example.odin | |
| parent | ce018b4e6fc21356f5236449d90712fc5d0adc3e (diff) | |
| parent | 288312a8126d71fae26c9d62a8cd342d830e1c5f (diff) | |
Merge pull request #4191 from laytan/improve-package-doc-comments
core: improve package doc comments for the documentation generator
Diffstat (limited to 'core/encoding/csv/example.odin')
| -rw-r--r-- | core/encoding/csv/example.odin | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/core/encoding/csv/example.odin b/core/encoding/csv/example.odin deleted file mode 100644 index f7c368636..000000000 --- a/core/encoding/csv/example.odin +++ /dev/null @@ -1,90 +0,0 @@ -//+build ignore -package encoding_csv - -import "core:fmt" -import "core:encoding/csv" -import "core:os" - -// Requires keeping the entire CSV file in memory at once -iterate_csv_from_string :: proc(filename: string) { - r: csv.Reader - r.trim_leading_space = true - r.reuse_record = true // Without it you have to delete(record) - r.reuse_record_buffer = true // Without it you have to each of the fields within it - defer csv.reader_destroy(&r) - - csv_data, ok := os.read_entire_file(filename) - if ok { - csv.reader_init_with_string(&r, string(csv_data)) - } else { - fmt.printfln("Unable to open file: %v", filename) - return - } - defer delete(csv_data) - - for r, i, err in csv.iterator_next(&r) { - if err != nil { /* Do something with error */ } - for f, j in r { - fmt.printfln("Record %v, field %v: %q", i, j, f) - } - } -} - -// Reads the CSV as it's processed (with a small buffer) -iterate_csv_from_stream :: proc(filename: string) { - fmt.printfln("Hellope from %v", filename) - r: csv.Reader - r.trim_leading_space = true - r.reuse_record = true // Without it you have to delete(record) - r.reuse_record_buffer = true // Without it you have to each of the fields within it - defer csv.reader_destroy(&r) - - handle, err := os.open(filename) - if err != nil { - fmt.eprintfln("Error opening file: %v", filename) - return - } - defer os.close(handle) - csv.reader_init(&r, os.stream_from_handle(handle)) - - for r, i in csv.iterator_next(&r) { - for f, j in r { - fmt.printfln("Record %v, field %v: %q", i, j, f) - } - } - fmt.printfln("Error: %v", csv.iterator_last_error(r)) -} - -// Read all records at once -read_csv_from_string :: proc(filename: string) { - r: csv.Reader - r.trim_leading_space = true - r.reuse_record = true // Without it you have to delete(record) - r.reuse_record_buffer = true // Without it you have to each of the fields within it - defer csv.reader_destroy(&r) - - csv_data, ok := os.read_entire_file(filename) - if ok { - csv.reader_init_with_string(&r, string(csv_data)) - } else { - fmt.printfln("Unable to open file: %v", filename) - return - } - defer delete(csv_data) - - records, err := csv.read_all(&r) - if err != nil { /* Do something with CSV parse error */ } - - defer { - for rec in records { - delete(rec) - } - delete(records) - } - - for r, i in records { - for f, j in r { - fmt.printfln("Record %v, field %v: %q", i, j, f) - } - } -}
\ No newline at end of file |