Supports reading a CSV text file.
CSV-Filereader | Supports reading a CSV text file. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file CSV-Filereader. |
C-kern/ | Implementation file CSV-Filereader impl. |
Types | |
struct csvfilereader_t | Export csvfilereader_t into global namespace. |
Functions | |
test | |
unittest_io_reader_csvfilereader | Test csvfilereader_t functionality. |
csvfilereader_t | Reads a CSV file and allows to access the values. |
file | The read file content mapped to memory. |
nrcolumns | The number of columns (Data fields) per row. |
nrrows | The number of rows of data. |
allocated_rows | The number of allocated rows of tablevalues. |
tablevalues | Table of strings indexing memory mapped file. |
lifetime | |
csvfilereader_FREE | Static initializer. |
init_csvfilereader | Opens file and reads all contained values. |
free_csvfilereader | Closes file and frees memory for parsed values. |
query | |
nrcolumns_csvfilereader | The number of columns (data fields) per row contained in the input data. |
nrrows_csvfilereader | The number of rows (data records) contained in the input data. |
colname_csvfilereader | The name of a column. |
colvalue_csvfilereader | Returns the value of a single column in a certain row. |
description | |
CSV-File-Format | It is a file format for storing tabular data as plain text. |
inline implementation | |
Macros | |
colname_csvfilereader | Implements csvfilereader_t.colname_csvfilereader. |
nrcolumns_csvfilereader | Implements csvfilereader_t.nrcolumns_csvfilereader. |
nrrows_csvfilereader | Implements csvfilereader_t.nrrows_csvfilereader. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2012 Jörg Seebohn
Header file CSV-Filereader.
Implementation file CSV-Filereader impl.
typedef struct csvfilereader_t csvfilereader_t
Export csvfilereader_t into global namespace.
test | |
unittest_io_reader_csvfilereader | Test csvfilereader_t functionality. |
int unittest_io_reader_csvfilereader( void )
Test csvfilereader_t functionality.
struct csvfilereader_t
Reads a CSV file and allows to access the values. The file is accessed with help of mmfile_t.
See CSV-File-Format.
file | The read file content mapped to memory. |
nrcolumns | The number of columns (Data fields) per row. |
nrrows | The number of rows of data. |
allocated_rows | The number of allocated rows of tablevalues. |
tablevalues | Table of strings indexing memory mapped file. |
lifetime | |
csvfilereader_FREE | Static initializer. |
init_csvfilereader | Opens file and reads all contained values. |
free_csvfilereader | Closes file and frees memory for parsed values. |
query | |
nrcolumns_csvfilereader | The number of columns (data fields) per row contained in the input data. |
nrrows_csvfilereader | The number of rows (data records) contained in the input data. |
colname_csvfilereader | The name of a column. |
colvalue_csvfilereader | Returns the value of a single column in a certain row. |
description | |
CSV-File-Format | It is a file format for storing tabular data as plain text. |
size_t allocated_rows
The number of allocated rows of tablevalues.
struct string_t * tablevalues/*[nrrows][nrcolumns]*/
Table of strings indexing memory mapped file. The allocated table size is determined by allocated_rows and nrcolumns. The valid values are determined by nrrows and nrcolumns.
int colvalue_csvfilereader( const csvfilereader_t * csvfile, size_t row/*1..nrrows-1*/, size_t column/*0..nrcolumns-1*/, /*out*/struct string_t * colvalue )
Returns the value of a single column in a certain row. The index of the columns a value between 0 and nrcolumns_csvfilereader-1. The index of the row is a value between 1 and nrrows_csvfilereader-1. A row index of 0 is the same as calling colname_csvfilereader.
It is a file format for storing tabular data as plain text. A text line contains one data row (record) they are separated by new lines (‘\n’). Any additional carriage return ‘\r’ is ignored. Every row contains the same number of columns (data fields). A single value in a row is separated by comma from another value. It must be enclosed in double quotes.
# The first line contains the column names "filename", "proglang", "authors" # The following lines defines the data "test_file_1.cpp", "C++", "MR. X1, MR. X2" "test_file_2.c", "C", "MR. Y" "test_file_3.sh", "shell", "MR. Z"
A double quote or new line character as part of a value is not supported. It must be represented by an escape sequence of a higher level abstraction like “\x22” or “\042” used in C-strings.
The values of the first row are considered to be the header names of the corresponding column.
Lines beginning with a ‘#’ are recognized as comments and are ignored.
The reader assumes that comma, white space and double quotes are encoded in ASCII. UTF-8 is supported or other code pages if comma, white space and double quotes uses the same codes as in ASCII.
#define colname_csvfilereader( csvfile, column, colname ) (colvalue_csvfilereader((csvfile), 0, (column), (colname)))
Implements csvfilereader_t.colname_csvfilereader.
#define nrcolumns_csvfilereader( csvfile ) ((csvfile)->nrcolumns)
Implements csvfilereader_t.nrcolumns_csvfilereader.
#define nrrows_csvfilereader( csvfile ) ((csvfile)->nrrows)
Implements csvfilereader_t.nrrows_csvfilereader.
Export csvfilereader_t into global namespace.
typedef struct csvfilereader_t csvfilereader_t
Reads a CSV file and allows to access the values.
struct csvfilereader_t
Test csvfilereader_t functionality.
int unittest_io_reader_csvfilereader( void )
The read file content mapped to memory.
mmfile_t file
The number of columns (Data fields) per row.
size_t nrcolumns
The number of rows of data.
size_t nrrows
The number of allocated rows of tablevalues.
size_t allocated_rows
Table of strings indexing memory mapped file.
struct string_t * tablevalues/*[nrrows][nrcolumns]*/
Static initializer.
#define csvfilereader_FREE { mmfile_FREE, 0, 0, 0, 0 }
Opens file and reads all contained values.
int init_csvfilereader( /*out*/csvfilereader_t * csvfile, const char * filepath )
Closes file and frees memory for parsed values.
int free_csvfilereader( csvfilereader_t * csvfile )
The number of columns (data fields) per row contained in the input data.
size_t nrcolumns_csvfilereader( const csvfilereader_t * csvfile )
The number of rows (data records) contained in the input data.
size_t nrrows_csvfilereader( const csvfilereader_t * csvfile )
The name of a column.
int colname_csvfilereader( const csvfilereader_t * csvfile, size_t column/*0..nrcolumns-1*/, /*out*/struct string_t * colname )
Returns the value of a single column in a certain row.
int colvalue_csvfilereader( const csvfilereader_t * csvfile, size_t row/*1..nrrows-1*/, size_t column/*0..nrcolumns-1*/, /*out*/struct string_t * colvalue )
Implements csvfilereader_t.colname_csvfilereader.
#define colname_csvfilereader( csvfile, column, colname ) (colvalue_csvfilereader((csvfile), 0, (column), (colname)))
Implements csvfilereader_t.nrcolumns_csvfilereader.
#define nrcolumns_csvfilereader( csvfile ) ((csvfile)->nrcolumns)
Implements csvfilereader_t.nrrows_csvfilereader.
#define nrrows_csvfilereader( csvfile ) ((csvfile)->nrrows)