You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// retrieving parsed values (and casting them to correct types,
71
+
// corresponding to format string provided in constructor above)
70
72
char **strings = (char**)cp["my_strings"];
71
73
int32_t *longs = (int32_t*)cp["my_longs"];
72
74
int16_t *ints = (int16_t*)cp["my_ints"];
@@ -89,8 +91,7 @@ Output:
89
91
> world - 80000 - 150 - 20 - 7.77 - FF
90
92
> noice - 90000 - 160 - 20 - 9.99 - FFFFFF
91
93
92
-
Notice how each character within `"sLdcfx-"` string specifies different type for each column. It is very important to set this format right.
93
-
We could set each solumn to be strings like "sssssss", however this would use more memory than it's really needed. If we wanted to store a large array of small numerical values (e.g. under 128), then using "c" specifier would be appropriate. See [Specifying value types](#specifying-value-types) section for full list of available specifiers and their descriptions.
94
+
Notice how each character within `"sLdcfx-"` string specifies different type for each column. It is very important to set this format right. It determines to what type we must cast parsed value arrays (char\* for "s", int32_t for "L"). We could set each solumn to be strings like "sssssss", however this would use more memory than it's really needed. If we wanted to store a large array of small numerical values (e.g. under 128), then using "c" specifier (int8_t) would be appropriate. See [Specifying value types](#specifying-value-types) section for full list of available specifiers and their descriptions.
94
95
95
96

96
97
@@ -150,10 +151,10 @@ cp << ",";
150
151
cp << String(102) + ",103\n";
151
152
```
152
153
Floats can be supplied as well. In general, any types can be supplied, the principle is: if the type isn't "String", "char \*" or "char", then the String(supplied_value) will be appended (before being parsed and stored as a type specified in the format string).
*[how to handle unsigned types](https://github.com/michalmonday/CSV-Parser-for-Arduino/tree/master/examples/unsigned_values)
159
160
*[how to supply csv by incomplete parts](https://github.com/michalmonday/CSV-Parser-for-Arduino/tree/master/examples/supplying_csv_by_incomplete_parts)
See [unsigned_values example](https://github.com/michalmonday/CSV-Parser-for-Arduino/blob/master/examples/unsigned_values/unsigned_values.ino) for more info.
260
261
261
-
## Casting returned values
262
-
Let's suppose that we parse the following:
263
-
```cpp
264
-
char * csv_str = "my_strings,my_floats\n"
265
-
"hello,1.1\n"
266
-
"world,2.2\n";
267
-
268
-
CSV_Parser cp(csv_str, /*format*/ "sf"); // s = string, f = float
269
-
```
270
-
271
-
To cast/retrieve the values we can use:
272
-
```cpp
273
-
char **strings = (char**)cp["my_strings"];
274
-
float *floats = (float*)cp["my_floats"];
275
-
```
276
-
277
-
"x" (hex input values), should be cast as "int32_t*" (or uint32_t*), because that's how they're stored. Casting them to "int*" could result in wrong address being computed when using `ints[index]`.
262
+
## Customization
278
263
279
-
280
-
## Headerless files
264
+
### Headerless files
281
265
To parse CSV files without header we can specify 3rd optional argument to the constructor. Example:
Use CSV_Parser.print function and check serial monitor. Example:
311
297
```cpp
312
298
CSV_Parser cp(csv_str, /*format*/ "sLdcfx-");
@@ -326,7 +312,6 @@ It will display parsed header fields, their types and all the parsed values. Lik
326
312
327
313
**Important - cp.print() method is using "Serial" object, it assumes that "Serial.begin(baud_rate);" was previously called.**
328
314
329
-
## Troubleshooting
330
315
331
316
#### Platformio and SD library issue
332
317
Platformio users reported compilation issues due to SD library import by the CSV_Parser.cpp file. Since 0.2.1 version of this library, the SD import can be disabled by placing `#define CSV_PARSER_DONT_IMPORT_SD` above (it won't work if it's below) the CSV_Parser library import like this:
@@ -353,4 +338,5 @@ I wanted to parse [covid-19 csv](https://github.com/tomwhite/covid-19-uk-data) d
353
338
354
339
355
340
## Documentation
341
+
Documentation is embedded into source code and automatically generated using doxygen.
0 commit comments