Verify that CSV input is encoded as UTF-8

This commit is contained in:
Eric Fischer
2017-12-06 13:32:44 -08:00
parent f3e6afa4e9
commit afb5cece96
4 changed files with 39 additions and 1 deletions
+13
View File
@@ -1,4 +1,5 @@
#include "csv.hpp"
#include "text.hpp"
std::vector<std::string> csv_split(const char *s) {
std::vector<std::string> ret;
@@ -67,6 +68,12 @@ void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::str
std::string s;
if ((s = csv_getline(f)).size() > 0) {
std::string err = check_utf8(s);
if (err != "") {
fprintf(stderr, "%s: %s\n", fn, err.c_str());
exit(EXIT_FAILURE);
}
header = csv_split(s.c_str());
for (size_t i = 0; i < header.size(); i++) {
@@ -74,6 +81,12 @@ void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::str
}
}
while ((s = csv_getline(f)).size() > 0) {
std::string err = check_utf8(s);
if (err != "") {
fprintf(stderr, "%s: %s\n", fn, err.c_str());
exit(EXIT_FAILURE);
}
std::vector<std::string> line = csv_split(s.c_str());
if (line.size() > 0) {
line[0] = csv_dequote(line[0]);