forked from aehrc/BitEpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csvparser.h
48 lines (39 loc) · 1.25 KB
/
csvparser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef CSVPARSER_H
#define CSVPARSER_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct CsvRow {
char **fields_;
int numOfFields_;
} CsvRow;
typedef struct CsvParser {
char *filePath_;
char delimiter_;
int firstLineIsHeader_;
char *errMsg_;
CsvRow *header_;
FILE *fileHandler_;
int fromString_;
char *csvString_;
int csvStringIter_;
} CsvParser;
// Public
CsvParser *CsvParser_new(const char *filePath, const char *delimiter, int firstLineIsHeader);
CsvParser *CsvParser_new_from_string(const char *csvString, const char *delimiter, int firstLineIsHeader);
void CsvParser_destroy(CsvParser *csvParser);
void CsvParser_destroy_row(CsvRow *csvRow);
const CsvRow *CsvParser_getHeader(CsvParser *csvParser);
CsvRow *CsvParser_getRow(CsvParser *csvParser);
int CsvParser_getNumFields(const CsvRow *csvRow);
const char **CsvParser_getFields(const CsvRow *csvRow);
const char* CsvParser_getErrorMessage(CsvParser *csvParser);
// Private
CsvRow *_CsvParser_getRow(CsvParser *csvParser);
int _CsvParser_delimiterIsAccepted(const char *delimiter);
void _CsvParser_setErrorMessage(CsvParser *csvParser, const char *errorMessage);
#ifdef __cplusplus
}
#endif
#endif