vincentlaucsb / csv-parser

A high-performance, fully-featured CSV parser and serializer for modern C++.
MIT License
901 stars 150 forks source link

Reading a quoted string row as an int64 #196

Closed raphasampaio closed 2 years ago

raphasampaio commented 2 years ago

Hello, I am using the single header v2.1.3, and when I try to read a CSV file where the rows are quoted strings, the parser says that the fields are int64.

#include <csv.hpp>
#include <string>

int main(void) {
    std::string csv_string =
        "Column\r\n"
        "\"43334218001\"\r\n"
        "\"43330147501\"\r\n";

    auto rows = csv::parse(csv_string);
    for (csv::CSVRow& row : rows) {
        for (std::size_t i = 0, size = row.size(); i < size; ++i) {
            auto field = row[i];
            switch (field.type()) {
                case csv::DataType::CSV_STRING: std::cout << "string" << std::endl; break;
                case csv::DataType::CSV_INT64: std::cout << "int64" << std::endl; break;
            }
        }
    }
    return 0;
}

The output is int64 and I was expecting a string.

vincentlaucsb commented 2 years ago

Quotes, when used to enclose fields, are used to escape syntactically significant characters and are not part of the data. This is consistent with other CSV parsers.