csvpp 1.2.0
CSV parsing / writing libraries
Loading...
Searching...
No Matches
embcsv.h
Go to the documentation of this file.
1
3
4// Copyright 2020 Matthew Chandler
5
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to deal
8// in the Software without restriction, including without limitation the rights
9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10// copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22// SOFTWARE.
23
39
40#ifndef EMBCSV_H
41#define EMBCSV_H
42
43#include <stdbool.h>
44#include <stdlib.h>
45
46#ifdef __cplusplus
47extern "C"
48{
49#endif
50
51#include "version.h"
52
53#ifndef EMBCSV_FIELD_BUF_SIZE
56#define EMBCSV_FIELD_BUF_SIZE 16
57#endif
58
62{
63 #ifndef EMBCSV_NO_MALLOC
64 char * field;
65 size_t field_alloc;
66 #else
68 #endif
69 size_t field_size;
70
71 char delimiter;
72 char quote;
73 bool lenient;
74
75 bool quoted;
76
77
79 enum {
84};
85
87typedef struct EMBCSV_reader EMBCSV_reader;
88
90
99
100#ifndef EMBCSV_NO_MALLOC
101
103
110
112
117
119
122
123#else
124
126
133
134
136
141
142#endif
143
145
154EMBCSV_result EMBCSV_reader_parse_char(EMBCSV_reader * r, int c, const char ** field_out);
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif // EMBCSV_H
void EMBCSV_reader_free(EMBCSV_reader *r)
Free an EMBCSV_reader.
EMBCSV_reader * EMBCSV_reader_init_full(char delimiter, char quote, bool lenient)
Create a new EMBCSV_reader.
EMBCSV_reader * EMBCSV_reader_init(void)
Create a new EMBCSV_reader with default settings.
EMBCSV_result
Parser result type.
Definition embcsv.h:93
#define EMBCSV_FIELD_BUF_SIZE
Field buffer size. Any fields at or over this limit will be truncated.
Definition embcsv.h:56
EMBCSV_result EMBCSV_reader_parse_char(EMBCSV_reader *r, int c, const char **field_out)
Parse a character.
@ EMBCSV_PARSE_ERROR
Syntax error found in input.
Definition embcsv.h:97
@ EMBCSV_END_OF_ROW
A field has been parsed, and parsing has reached the end of a row.
Definition embcsv.h:96
@ EMBCSV_FIELD
A field has been parsed.
Definition embcsv.h:95
@ EMBCSV_INCOMPLETE
Parsing is incomplete. Parse more characters.
Definition embcsv.h:94
Definition embcsv.h:62
size_t field_size
Field size.
Definition embcsv.h:69
size_t field_alloc
Field allocated size.
Definition embcsv.h:65
char delimiter
Delimiter character (default ',')
Definition embcsv.h:71
char * field
Field storage.
Definition embcsv.h:64
@ EMBCSV_STATE_DOUBLE_QUOTE
Checking for escaped quote character or end of quoted field.
Definition embcsv.h:81
@ EMBCSV_STATE_CONSUME_NEWLINES
Discarding any newline characters.
Definition embcsv.h:82
@ EMBCSV_STATE_READY
Ready to read a character into current field.
Definition embcsv.h:80
enum EMBCSV_reader::@1 state
Parsing states.
bool quoted
true if parsing a quoted field
Definition embcsv.h:75
bool lenient
true if parsing is at the end of a row
Definition embcsv.h:73
char quote
Quote character (default '"')
Definition embcsv.h:72