From d246e974d013dc00657bc60b38fbed3ceed3ef37 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 29 Oct 2026 22:58:07 +0000 Subject: [PATCH] Decompile 5 functions in Source/Utility/Text/StringUtil.cpp, Source/Utility/Text/StringUtil.h Batch #3633 by Yommy: 0 byte-identical, 5 confirmed by peer review. - fn_02759 GetFileName: logic confirmed by peer review - fn_02764 FormatDecimal: logic confirmed by peer review - fn_02765 Split: logic confirmed by peer review - fn_02766 TrimRight: logic confirmed by peer review - fn_02767 TrimLeft: logic confirmed by peer review Peer-reviewed-by: eAthena, meitogi, superintelligence Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Utility/Text/StringUtil.cpp | 68 ++++++++++++++++++++++++++++++ Source/Utility/Text/StringUtil.h | 6 +++ 2 files changed, 74 insertions(+) diff --git a/Source/Utility/Text/StringUtil.cpp b/Source/Utility/Text/StringUtil.cpp index da8eb5d9..9941ab87 100644 --- a/Source/Utility/Text/StringUtil.cpp +++ b/Source/Utility/Text/StringUtil.cpp @@ -1,6 +1,12 @@ #include "Utility/Text/StringUtil.h" +#include +#include +#include #include +#include +#include +#include // OFFSET: 0x0058A4D0 // FUNCTION: fn_02757 @@ -26,6 +32,16 @@ bool ContainsText(const std::string& text, std::string_view pattern) { return text.find(pattern.data(), 0, pattern.size()) != std::string::npos; } +// OFFSET: 0x0058A8F0 +// FUNCTION: fn_02759 +std::string GetFileName(const std::string& path) { + std::size_t position = path.find_last_of("\\/"); + if (position == std::string::npos) { + return path; + } + return path.substr(position + 1); +} + // OFFSET: 0x0058AAF0 // FUNCTION: fn_02761 bool IsNullOrEmpty(const char* text) { @@ -50,3 +66,55 @@ int ReplaceAll(std::string& text, std::string_view pattern, std::string_view rep } return count; } + +// OFFSET: 0x0058AE30 +// FUNCTION: fn_02764 +std::string FormatDecimal(double value, int precision, bool trimZeros) { + double scale = std::pow(10.0, precision); + double inverseScale = std::pow(0.1, precision); + double rounded = std::round(value * scale) * inverseScale; + + std::ostringstream stream; + stream << std::fixed << std::setprecision(precision) << rounded; + std::string result = stream.str(); + + if (trimZeros) { + result.erase(result.find_last_not_of('0') + 1); + if (result.back() == '.') { + result.pop_back(); + } + } + return result; +} + +// OFFSET: 0x0058B170 +// FUNCTION: fn_02765 +std::vector Split(std::string_view text, std::string_view delimiter) { + std::vector result; + for (auto part : text | std::views::split(delimiter)) { + result.emplace_back(std::string_view(part.begin(), part.end())); + } + return result; +} + +// OFFSET: 0x0058B830 +// FUNCTION: fn_02766 +void TrimRight(std::string& text, std::string_view characters) { + if (characters.empty()) { + auto last = std::find_if(text.rbegin(), text.rend(), [](unsigned char c) { return !std::isspace(c); }); + text.erase(last.base(), text.end()); + return; + } + text.erase(text.find_last_not_of(characters) + 1); +} + +// OFFSET: 0x0058BA30 +// FUNCTION: fn_02767 +void TrimLeft(std::string& text, std::string_view characters) { + if (characters.empty()) { + auto first = std::find_if(text.begin(), text.end(), [](unsigned char c) { return !std::isspace(c); }); + text.erase(text.begin(), first); + return; + } + text.erase(0, text.find_first_not_of(characters)); +} diff --git a/Source/Utility/Text/StringUtil.h b/Source/Utility/Text/StringUtil.h index 54d6a5f9..bbf35f3e 100644 --- a/Source/Utility/Text/StringUtil.h +++ b/Source/Utility/Text/StringUtil.h @@ -3,12 +3,18 @@ #include #include +#include #include int CountCharacters(WORD codePage, const char* text, const char* end); bool ContainsText(const std::string& text, std::string_view pattern); +std::string GetFileName(const std::string& path); bool IsNullOrEmpty(const char* text); int RemoveAll(std::string& text, std::string_view pattern); int ReplaceAll(std::string& text, std::string_view pattern, std::string_view replacement); +std::string FormatDecimal(double value, int precision, bool trimZeros); +std::vector Split(std::string_view text, std::string_view delimiter); +void TrimRight(std::string& text, std::string_view characters); +void TrimLeft(std::string& text, std::string_view characters); #endif