From 1b20bbda645944fc71216db6f326bf07a3310b3f Mon Sep 17 00:00:00 2001 From: cetvrtak <59363714+cetvrtak@users.noreply.github.com> Date: Sun, 30 Jun 2024 16:30:05 +0200 Subject: [PATCH] Handle empty lines in HoI4 province definitions --- .../Map/HoI4ProvinceDefinitionImporter.cpp | 14 +++++++------- src/HOI4World/Map/HoI4Provinces.cpp | 4 ++++ src/Mappers/Provinces/ProvinceMapperFactory.cpp | 6 +++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/HOI4World/Map/HoI4ProvinceDefinitionImporter.cpp b/src/HOI4World/Map/HoI4ProvinceDefinitionImporter.cpp index a491ae0ec6..e8a9f2000d 100644 --- a/src/HOI4World/Map/HoI4ProvinceDefinitionImporter.cpp +++ b/src/HOI4World/Map/HoI4ProvinceDefinitionImporter.cpp @@ -34,7 +34,7 @@ Maps::ProvinceDefinitions HoI4::importProvinceDefinitions(const std::string& pat auto pos = line.find_first_of(';'); if (pos == std::string::npos) { - break; + continue; } auto provNum = stoi(line.substr(0, pos)); if (provNum == 0) @@ -47,7 +47,7 @@ Maps::ProvinceDefinitions HoI4::importProvinceDefinitions(const std::string& pat pos = line.find_first_of(';'); if (pos == std::string::npos) { - break; + continue; } const int red(stoi(line.substr(0, pos))); line = line.substr(pos + 1, line.length()); @@ -56,7 +56,7 @@ Maps::ProvinceDefinitions HoI4::importProvinceDefinitions(const std::string& pat pos = line.find_first_of(';'); if (pos == std::string::npos) { - break; + continue; } const int green(stoi(line.substr(0, pos))); line = line.substr(pos + 1, line.length()); @@ -65,7 +65,7 @@ Maps::ProvinceDefinitions HoI4::importProvinceDefinitions(const std::string& pat pos = line.find_first_of(';'); if (pos == std::string::npos) { - break; + continue; } const int blue(stoi(line.substr(0, pos))); line = line.substr(pos + 1, line.length()); @@ -77,7 +77,7 @@ Maps::ProvinceDefinitions HoI4::importProvinceDefinitions(const std::string& pat pos = line.find_first_of(';'); if (pos == std::string::npos) { - break; + continue; } const std::string landOrSea = line.substr(0, pos); line = line.substr(pos + 1, line.length()); @@ -94,7 +94,7 @@ Maps::ProvinceDefinitions HoI4::importProvinceDefinitions(const std::string& pat pos = line.find_first_of(';'); if (pos == std::string::npos) { - break; + continue; } line = line.substr(pos + 1, line.length()); @@ -102,7 +102,7 @@ Maps::ProvinceDefinitions HoI4::importProvinceDefinitions(const std::string& pat pos = line.find_first_of(';'); if (pos == std::string::npos) { - break; + continue; } const std::string terrain = line.substr(0, pos); line = line.substr(pos + 1, line.length()); diff --git a/src/HOI4World/Map/HoI4Provinces.cpp b/src/HOI4World/Map/HoI4Provinces.cpp index 91deaff36a..30014e729b 100644 --- a/src/HOI4World/Map/HoI4Provinces.cpp +++ b/src/HOI4World/Map/HoI4Provinces.cpp @@ -25,6 +25,10 @@ std::map HoI4::importProvinces(const Configuration& theConf } auto IDSeparator = line.find_first_of(';'); + if (IDSeparator == std::string::npos) + { + continue; + } auto ID = stoi(line.substr(0, IDSeparator)); if (ID == 0) { diff --git a/src/Mappers/Provinces/ProvinceMapperFactory.cpp b/src/Mappers/Provinces/ProvinceMapperFactory.cpp index 620e425fd1..89b810be16 100644 --- a/src/Mappers/Provinces/ProvinceMapperFactory.cpp +++ b/src/Mappers/Provinces/ProvinceMapperFactory.cpp @@ -58,10 +58,14 @@ void checkAllHoI4ProvincesMapped(const Mappers::VersionedMappings& versionedMapp while (true) { + if (definitions.eof()) + { + break; + } auto provNum = getNextProvinceNumFromFile(definitions); if (!provNum) { - break; + continue; } if (*provNum == 0) {