From 04adf4b42ce8e8bec3ff2f7a9e176ed50f522bad Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Thu, 18 Apr 2024 22:53:34 +0200 Subject: [PATCH] fix parsing when there's no space after the colon --- src/osuparser.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/osuparser.cpp b/src/osuparser.cpp index 3f72697..c7a4805 100644 --- a/src/osuparser.cpp +++ b/src/osuparser.cpp @@ -6,13 +6,20 @@ #include #include +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;\