From 5d24f38122e30d92d2054def46c01aac8b6a6df3 Mon Sep 17 00:00:00 2001 From: hasherezade Date: Mon, 3 Feb 2025 05:02:23 -0800 Subject: [PATCH] [REFACT] Fixed compatibility with MinGW --- etw_settings.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/etw_settings.cpp b/etw_settings.cpp index 49e5cc6..4bc1f97 100644 --- a/etw_settings.cpp +++ b/etw_settings.cpp @@ -13,24 +13,29 @@ namespace util { + std::string WHITESPACES = " \t\n\v\f\r"; + static inline void ltrim(std::string& s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { - return !std::isspace(ch); - })); + size_t startpos = s.find_first_not_of(WHITESPACES); + if (startpos != std::string::npos) { + s = s.substr(startpos); + } } static inline void rtrim(std::string& s) { - s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { - return !std::isspace(ch); - }).base(), s.end()); + size_t endpos = s.find_last_not_of(WHITESPACES); + if (endpos != std::string::npos) { + s = s.substr(0, endpos + 1); + } } - void trim(std::string& s) + std::string trim(std::string& s) { ltrim(s); rtrim(s); + return s; } bool iequals(const std::string& a, const std::string& b)