From 35773b5ba68207b747bac67bad93f4ebbeb9424f Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Tue, 1 Aug 2023 10:40:41 +0300 Subject: [PATCH] * Fix Util::stringTrim. Not sure if accurate --- source/Base/Util.cpp | 50 +++++++------------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/source/Base/Util.cpp b/source/Base/Util.cpp index d720085..68b1e8f 100644 --- a/source/Base/Util.cpp +++ b/source/Base/Util.cpp @@ -17,61 +17,25 @@ std::string Util::stringTrim(const std::string& str, const std::string& filter, if (!a4 && !a5) return ""; - int v12, strIndex = 0, v13, v17, strLength = int(str.size()), filterLength = int(filter.size()); + int startIndex = 0, endIndex = int(str.size()) - 1; + // @TODO: This ain't working man if (a4) { - v12 = strLength - 1; - if (strLength > 0) + while (startIndex < endIndex && strchr(filter.c_str(), str[startIndex])) { - v17 = strLength - 1; - do - { - const void* v14 = memchr(filter.c_str(), str[strIndex], filterLength); - if (!v14) - { - v13 = strIndex; - v12 = v17; - goto label_12; - } - - ++strIndex; - } while (strIndex != strLength); - - v12 = strLength - 1; - v13 = strIndex; + startIndex++; } - else v13 = 0; } - else - { - if (a5) - { - v12 = strLength - 1; - strIndex = 0; - v13 = 0; - - goto label_19; - } - - return ""; - } - -label_12: if (a5) { - v13 = strIndex; - label_19: - while (v12 >= strIndex) + while (startIndex < endIndex && strchr(filter.c_str(), str[endIndex])) { - const void* v15 = memchr(filter.c_str(), str[strIndex], filterLength); - if (!v15) - break; - --v12; + endIndex--; } } - return std::string(str, v13, v12 - 1 + strIndex); + return str.substr(startIndex, endIndex + 1 - startIndex); } std::string Util::stringTrim(const std::string& str)