fix parsing when there's no space after the colon

This commit is contained in:
jacekpoz 2024-04-18 22:53:34 +02:00
parent 3fb74a4f09
commit 04adf4b42c
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -6,13 +6,20 @@
#include <sstream>
#include <iostream>
inline std::string trimString(const std::string &str) {
std::string ret(str);
ret.erase(0, ret.find_first_not_of(" \n\r\t"));
ret.erase(ret.find_last_not_of(" \n\r\t") + 1);
return ret;
}
inline std::string checkAndRemove(const std::string &str, const std::string &prefix) {
if (!str.starts_with(prefix)) {
std::cerr << "failure parsing difficulty file on:\n" << str << "\n";
std::exit(EXIT_FAILURE);
}
return str.substr(prefix.length());
return trimString(str.substr(prefix.length()));
}
inline void toLower(std::string &str) {
@ -50,7 +57,7 @@ inline void toLower(std::string &str) {
#define VAR_GENERIC(section, name, ...) \
namePascalCased = #name;\
namePascalCased[0] = std::toupper(namePascalCased[0]);\
namePascalCased.append(": ");\
namePascalCased.append(":");\
if (line.starts_with(namePascalCased)) {\
__VA_ARGS__\
ret section.name = value;\