From 726120f6610c6e47d3944adafa36d87116c13d89 Mon Sep 17 00:00:00 2001 From: DeaTh-G Date: Wed, 29 Jan 2025 16:38:26 +0100 Subject: [PATCH] remove regex usage --- UnleashedRecomp/ui/imgui_utils.cpp | 41 +++++++++++++++++++----------- UnleashedRecomp/ui/imgui_utils.h | 2 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/UnleashedRecomp/ui/imgui_utils.cpp b/UnleashedRecomp/ui/imgui_utils.cpp index 603dd918..41d82ffa 100644 --- a/UnleashedRecomp/ui/imgui_utils.cpp +++ b/UnleashedRecomp/ui/imgui_utils.cpp @@ -196,7 +196,7 @@ void DrawTextBasic(const ImFont* font, float fontSize, const ImVec2& pos, ImU32 drawList->AddText(font, fontSize, pos, colour, text, nullptr); } -void DrawTextWithMarquee(const ImFont* font, float fontSize, const ImVec2& pos, const ImVec2& min, const ImVec2& max, ImU32 color, const char* text, double time, double delay, double speed) +void DrawTextWithMarquee(const ImFont* font, float fontSize, const ImVec2& position, const ImVec2& min, const ImVec2& max, ImU32 color, const char* text, double time, double delay, double speed) { auto drawList = ImGui::GetForegroundDrawList(); auto rectWidth = max.x - min.x; @@ -500,27 +500,38 @@ Paragraph CalculateAnnotatedParagraph(const std::vector& lines) for (const auto& line : lines) { std::vector segments; - std::regex regex(R"(\[([^\:]+):([^\]]+)\])"); // Matches "[text:annotation]" - std::smatch match; - auto searchStart = line.cbegin(); - while (std::regex_search(searchStart, line.cend(), match, regex)) + size_t pos = 0; + size_t start = 0; + + while ((start = line.find('[', pos)) != std::string::npos) { - if (searchStart != match[0].first) + size_t end = line.find(']', start); + if (end == std::string::npos) + break; + + size_t colon = line.find(':', start); + if (colon != std::string::npos && colon < end) { - segments.push_back({ false, std::string(searchStart, match[0].first), "" }); + if (start != pos) + { + segments.push_back({ false, line.substr(pos, start - pos), "" }); + } + + segments.push_back({ true, line.substr(start + 1, colon - start - 1), line.substr(colon + 1, end - colon - 1) }); + + result.annotated = true; + pos = end + 1; + } + else + { + pos = start + 1; } - - segments.push_back({ true, match[1].str(), match[2].str() }); - - result.annotated = true; - - searchStart = match[0].second; } - if (searchStart != line.cend()) + if (pos < line.size()) { - segments.push_back({ false, std::string(searchStart, line.cend()), "" }); + segments.push_back({ false, line.substr(pos), "" }); } result.lines.push_back(segments); diff --git a/UnleashedRecomp/ui/imgui_utils.h b/UnleashedRecomp/ui/imgui_utils.h index cf8473ef..300f22f8 100644 --- a/UnleashedRecomp/ui/imgui_utils.h +++ b/UnleashedRecomp/ui/imgui_utils.h @@ -55,7 +55,7 @@ double ComputeMotion(double duration, double offset, double total); void DrawPauseContainer(ImVec2 min, ImVec2 max, float alpha = 1); void DrawTextBasic(const ImFont* font, float fontSize, const ImVec2& pos, ImU32 colour, const char* text); void DrawPauseHeaderContainer(ImVec2 min, ImVec2 max, float alpha = 1); -void DrawTextWithMarquee(const ImFont* font, float fontSize, const ImVec2& pos, const ImVec2& min, const ImVec2& max, ImU32 color, const char* text, double time, double delay, double speed); +void DrawTextWithMarquee(const ImFont* font, float fontSize, const ImVec2& position, const ImVec2& min, const ImVec2& max, ImU32 color, const char* text, double time, double delay, double speed); void DrawTextWithMarqueeShadow(const ImFont* font, float fontSize, const ImVec2& pos, const ImVec2& min, const ImVec2& max, ImU32 colour, const char* text, double time, double delay, double speed, float offset = 2.0f, float radius = 1.0f, ImU32 shadowColour = IM_COL32(0, 0, 0, 255)); void DrawTextWithOutline(const ImFont* font, float fontSize, const ImVec2& pos, ImU32 color, const char* text, float outlineSize, ImU32 outlineColor, uint32_t shaderModifier = IMGUI_SHADER_MODIFIER_NONE); void DrawTextWithShadow(const ImFont* font, float fontSize, const ImVec2& pos, ImU32 colour, const char* text, float offset = 2.0f, float radius = 1.0f, ImU32 shadowColour = IM_COL32(0, 0, 0, 255));