fix parsing when there's no space after the colon
This commit is contained in:
parent
3fb74a4f09
commit
04adf4b42c
1 changed files with 9 additions and 2 deletions
|
@ -6,13 +6,20 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#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) {
|
inline std::string checkAndRemove(const std::string &str, const std::string &prefix) {
|
||||||
if (!str.starts_with(prefix)) {
|
if (!str.starts_with(prefix)) {
|
||||||
std::cerr << "failure parsing difficulty file on:\n" << str << "\n";
|
std::cerr << "failure parsing difficulty file on:\n" << str << "\n";
|
||||||
std::exit(EXIT_FAILURE);
|
std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.substr(prefix.length());
|
return trimString(str.substr(prefix.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void toLower(std::string &str) {
|
inline void toLower(std::string &str) {
|
||||||
|
@ -50,7 +57,7 @@ inline void toLower(std::string &str) {
|
||||||
#define VAR_GENERIC(section, name, ...) \
|
#define VAR_GENERIC(section, name, ...) \
|
||||||
namePascalCased = #name;\
|
namePascalCased = #name;\
|
||||||
namePascalCased[0] = std::toupper(namePascalCased[0]);\
|
namePascalCased[0] = std::toupper(namePascalCased[0]);\
|
||||||
namePascalCased.append(": ");\
|
namePascalCased.append(":");\
|
||||||
if (line.starts_with(namePascalCased)) {\
|
if (line.starts_with(namePascalCased)) {\
|
||||||
__VA_ARGS__\
|
__VA_ARGS__\
|
||||||
ret section.name = value;\
|
ret section.name = value;\
|
||||||
|
|
Loading…
Reference in a new issue