Skip to content

SherllyNeo/dsvParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dsvParser

A simple CSV or other deliminated parser

This is a header only library. Simpily include the headerfile and use!

Look at the example main.c to see all the functionality.

git clone https://github.com/SherllyNeo/dsvParser.git &&
cd dsvParser &&
make &&
./bin/dsvParserExample

Features

typedef struct {
    char*** content;
    size_t rows;
    size_t cols;
    bool valid;
} DSV;
  • The struct can be checked to see if it is valid after each operation
  • Read delim seperated value file into a DSV struct (
  • Escapes inner deliminators with "", for example one,"tw,o",three will be parsed correctly
  • Supports '\' escaping, so '\,' will not start a newline in a csv for example
  • Write DSV to a file with a customer deliminator which allows for escaping
  • Loop through each element of the array using the rows and cols to do with what you like
  • Insert row
  • Delete row
  • print DSV
  • Easy to free using the dsvFreeDSV function using the dsvFreeDSV function
  • Most functions returns an int value where 0 means success or a DSV struct that may be valid

Functions

DSV dsvParseFile(char* filepath, char delim);
int dsvWriteFile(DSV parsed,char* filepath,char delim);
int dsvInsertRow(DSV *dsv, char** tmp_row, size_t position);
int dsvRemoveRow(DSV *dsv, size_t position);
void dsvPrintDSV(DSV parsed);
int dsvFreeDSV(DSV parsed);

you can also access elements directly like so (example printing)

for (size_t i = 0; i<parsed_csv.rows; i++) {
    for (size_t j = 0; j<parsed_csv.cols; j++) {
        printf("%s ",parsed_csv.content[i][j]);
    }
    printf("\n");
}

About

A simple CSV or other deliminated parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published