|
12 | 12 | * [Custom delimiter](#custom-delimiter) |
13 | 13 | * [Custom quote character](#custom-quote-character) |
14 | 14 | * [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) |
16 | 18 | * [Motivation](#motivation) |
17 | 19 | * [Documentation](#documentation) |
18 | 20 |
|
@@ -149,17 +151,6 @@ cp << String(102) + ",103\n"; |
149 | 151 | ``` |
150 | 152 | 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). |
151 | 153 |
|
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 | | - |
163 | 154 |
|
164 | 155 | ## Examples |
165 | 156 | Examples directory contains examples showing: |
@@ -337,12 +328,25 @@ It will display parsed header fields, their types and all the parsed values. Lik |
337 | 328 |
|
338 | 329 | ## Troubleshooting |
339 | 330 |
|
| 331 | +#### Platformio and SD library issue |
340 | 332 | 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: |
341 | 333 |
|
342 | 334 | ```cpp |
343 | 335 | #define CSV_PARSER_DONT_IMPORT_SD |
344 | 336 | #include <CSV_Parser.h> |
345 | 337 | ``` |
| 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 | + |
346 | 350 |
|
347 | 351 | ## Motivation |
348 | 352 | 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