Skip to content

Commit 24ff864

Browse files
committed
README.md
1 parent f8c819e commit 24ff864

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
* [Custom delimiter](#custom-delimiter)
1313
* [Custom quote character](#custom-quote-character)
1414
* [Checking if the file was parsed correctly](#checking-if-the-file-was-parsed-correctly)
15-
* [Troubleshooting](#troubleshooting)
15+
* [Troubleshooting](#troubleshooting)
16+
* Platformio and SD library issue
17+
* `cp << file.read()` requiring `(char)` cast (potential issue from version 1.0.0, which may break old code)
1618
* [Motivation](#motivation)
1719
* [Documentation](#documentation)
1820

@@ -149,17 +151,6 @@ cp << String(102) + ",103\n";
149151
```
150152
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).
151153

152-
**Important**
153-
Arduino built-in File.read() method returns an integer (instead of a char). Therefore, it's important to cast its return before supplying it to CSV_Parser object, like:
154-
```cpp
155-
File csv_file = SD.open(f_name); // or FFat.open(f_name);
156-
while (csv_file.available()) {
157-
cp << (char)csv_file.read();
158-
}
159-
```
160-
Without `(char)`, the string representation of ascii number would be stored.
161-
Before the 1.0.0 version, the `cp << 97;` expression would append letter 'a' (because '97' stands for 'a' in ascii table). From 1.0.0 version onwards, the `cp << 97;` is equivalent to `cp << String(97);`, it will append '97' instead of 'a'. That is correct behaviour in my opinion, however due to design of Arduino built-in "File.read()" method, which returns an integer, it is necessary to cast it's return (with `(char)csv_file.read()` as shown above), and problems may occur if some existing code (using this library) doesn't explicitly cast it.
162-
163154

164155
## Examples
165156
Examples directory contains examples showing:
@@ -337,12 +328,25 @@ It will display parsed header fields, their types and all the parsed values. Lik
337328
338329
## Troubleshooting
339330
331+
#### Platformio and SD library issue
340332
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:
341333
342334
```cpp
343335
#define CSV_PARSER_DONT_IMPORT_SD
344336
#include <CSV_Parser.h>
345337
```
338+
339+
#### `cp << file.read();` requiring a `(char)` cast (potential issue from version 1.0.0, which may break old code)
340+
Arduino built-in File.read() method returns an integer (instead of a char). Therefore, it's important to cast its return before supplying it to CSV_Parser object, like:
341+
```cpp
342+
File csv_file = SD.open(f_name); // or FFat.open(f_name);
343+
while (csv_file.available()) {
344+
cp << (char)csv_file.read();
345+
}
346+
```
347+
Without `(char)`, the string representation of ascii number would be stored.
348+
Before the 1.0.0 version, the `cp << 97;` expression would append letter 'a' (because '97' stands for 'a' in ascii table). From 1.0.0 version onwards, the `cp << 97;` is equivalent to `cp << String(97);`, it will append '97' instead of 'a'. That is correct behaviour in my opinion, however due to design of Arduino built-in "File.read()" method, which returns an integer, it is necessary to cast it's return (with `(char)csv_file.read()` as shown above), and problems may occur if some existing code (using this library) doesn't explicitly cast it.
349+
346350

347351
## Motivation
348352
I wanted to parse [covid-19 csv](https://github.com/tomwhite/covid-19-uk-data) data and couldn't find any csv parser for Arduino. So instead of rushing with a quick/dirty solution, I decided to write something that could be reused in the future (possibly by other people too).

0 commit comments

Comments
 (0)