Loading...
Searching...
No Matches
csv.h
Go to the documentation of this file.
#ifndef ARC_STD_PARSER_PARSERLANG_H_
#define ARC_STD_PARSER_PARSERLANG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/std/bool.h"
#include "arc/std/parser.h"
#include "arc/std/string.h"
#include <stdint.h>
/*
<line> -> <data> NEWLINE <line> | <data> | NEWLINE <line> | LAMBDA
<data> -> <string> COMMA <data> | <string>
<string> -> <nonCommaChar> <string> | <nonCommaChar>
<nonCommaChar> -> CHAR_BEFORE_COMMA | CHAR_AFTER_COMMA
*/
/**
* @brief a callback for the csv parser to use to cast that data the stored data
*
* @note this callback will only be called on non-header data
*
* @param[in/out] data the csv data casted into the users type
* @param[in] string an value of the csv as a string
*/
typedef void (* ARC_ParserCSV_CastTypeFn)(void **data, ARC_String *string);
/**
* @brief a callback for the csv parser to use to free csv data
*
* @note this callback will only be called on non-header data
*
* @param[in] data the csv data to free
*/
typedef void (* ARC_ParserCSV_DestroyTypeFn)(void *data);
/**
* @brief defines a csv data type, data is set by the callback passed in when createing a parserCSV as parser
*
* @note this data can be retieved after parsing by calling get data, check arc/std/parser.h for more information
*/
typedef struct ARC_ParserCSVData {
ARC_Bool hasHeader;
ARC_String **headers;
uint32_t width;
uint32_t height;
void ***data;
} ARC_ParserCSVData;
/**
* @brief creates a parser for the Parser Lang
*
* @note the rules will be inited for the parser lang
* @note the parsed data will be saved as a vector of ARC_ParserLanguageTag
*
* @param[out] parser the parser to create
*/
void ARC_ParserCSV_CreateAsParser(ARC_Parser **parser, ARC_Bool header, ARC_ParserCSV_CastTypeFn castTypeFn, ARC_ParserCSV_DestroyTypeFn destroyTypeFn);
#define ARC_PARSER_CSV_CHAR_COMMA 1
#define ARC_PARSER_CSV_CHAR_NEWLINE 2
#define ARC_PARSER_CSV_CHAR_BEFORE_COMMA 3
#define ARC_PARSER_CSV_CHAR_AFTER_COMMA 4
#define ARC_PARSER_CSV_LINE 5
#define ARC_PARSER_CSV_DATA 6
#define ARC_PARSER_CSV_STRING 7
#define ARC_PARSER_CSV_NON_COMMA_CHAR 8
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_PARSER_PARSERLANG_H_
bool.h
ARC_Bool
#define ARC_Bool
Definition bool.h:10
ARC_ParserCSVData
struct ARC_ParserCSVData ARC_ParserCSVData
defines a csv data type, data is set by the callback passed in when createing a parserCSV as parser
ARC_ParserCSV_CastTypeFn
void(* ARC_ParserCSV_CastTypeFn)(void **data, ARC_String *string)
a callback for the csv parser to use to cast that data the stored data
Definition csv.h:28
ARC_ParserCSV_DestroyTypeFn
void(* ARC_ParserCSV_DestroyTypeFn)(void *data)
a callback for the csv parser to use to free csv data
Definition csv.h:37
ARC_ParserCSV_CreateAsParser
void ARC_ParserCSV_CreateAsParser(ARC_Parser **parser, ARC_Bool header, ARC_ParserCSV_CastTypeFn castTypeFn, ARC_ParserCSV_DestroyTypeFn destroyTypeFn)
creates a parser for the Parser Lang
parser.h
ARC_Parser
struct ARC_Parser ARC_Parser
a parser type
Definition parser.h:16
string.h
ARC_ParserCSVData
defines a csv data type, data is set by the callback passed in when createing a parserCSV as parser
Definition csv.h:44
ARC_ParserCSVData::height
uint32_t height
Definition csv.h:49
ARC_ParserCSVData::width
uint32_t width
Definition csv.h:48
ARC_ParserCSVData::data
void *** data
Definition csv.h:50
ARC_ParserCSVData::headers
ARC_String ** headers
Definition csv.h:46
ARC_ParserCSVData::hasHeader
ARC_Bool hasHeader
Definition csv.h:45
ARC_String
substring position within a string
Definition string.h:14