Change separator detection on csv parsing.
This commit is contained in:
parent
85b80f4be7
commit
d3e95dad61
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue