Change separator detection on csv parsing.

This commit is contained in:
Deukhoofd 2021-09-07 18:55:36 +02:00
parent 85b80f4be7
commit d3e95dad61
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 14 additions and 7 deletions

View File

@ -20,6 +20,8 @@ static CreatureLib::Library::Statistic ParseStatistic(const std::string& stat) {
return static_cast<CreatureLib::Library::Statistic>(254);
}
const char PossibleSeparators[] = {',', ';', '|', '\t', ':'};
PkmnLib::Library::NatureLibrary* BuildNatures::Build(const std::string& path) {
std::ifstream file(path);
if (file.fail()) {
@ -33,11 +35,13 @@ PkmnLib::Library::NatureLibrary* BuildNatures::Build(const std::string& path) {
return nullptr;
}
auto divider = ',';
if (strncmp(line.c_str(), "sep=", 4) == 0) {
divider = line[4];
std::getline(file, line);
for (const auto& s : PossibleSeparators) {
if (line.find(s) != std::string::npos) {
divider = s;
break;
}
}
auto library = new PkmnLib::Library::NatureLibrary();
auto* library = new PkmnLib::Library::NatureLibrary();
std::string substr;
while (std::getline(file, line)) {
size_t lastStart = 0;

View File

@ -1,4 +1,5 @@
#include "BuildTypes.hpp"
const char PossibleSeparators[] = {',', ';', '|', '\t', ':'};
CreatureLib::Library::TypeLibrary* BuildTypes::Build(const std::string& path) {
std::ifstream file(path);
@ -13,9 +14,11 @@ CreatureLib::Library::TypeLibrary* BuildTypes::Build(const std::string& path) {
return nullptr;
}
auto divider = ',';
if (strncmp(line.c_str(), "sep=", 4) == 0) {
divider = line[4];
std::getline(file, line);
for (const auto& s :PossibleSeparators) {
if (line.find(s) != std::string::npos){
divider = s;
break;
}
}
auto* library = new CreatureLib::Library::TypeLibrary();