mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
<!-- Please provide as much information as possible about what your PR aims to do. PRs with no description will most likely be closed until more information is provided. If you're planing on changing fundamental behaviour or add big new features, please open a GitHub Issue first before starting to work on it. If it's not something big and you still want to contact us about it, feel free to do so ! --> ### Problem description <!-- Describe the bug that you fixed/feature request that you implemented, or link to an existing issue describing it --> ### Implementation description <!-- Explain what you did to correct the problem --> ### Screenshots <!-- If your change is visual, take a screenshot showing it. Ideally, make before/after sceenshots --> ### Additional things <!-- Anything else you would like to say -->
41 lines
1.5 KiB
C++
41 lines
1.5 KiB
C++
#include <hex/helpers/http_requests.hpp>
|
|
#include <hex/helpers/scaling.hpp>
|
|
#include <hex/helpers/logger.hpp>
|
|
#include <hex/api/localization_manager.hpp>
|
|
|
|
#include <boost/regex.hpp>
|
|
|
|
#include <imgui.h>
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
#include <fonts/vscode_icons.hpp>
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
void drawRegexReplacer() {
|
|
static std::string inputString;
|
|
static std::string regexPattern;
|
|
static std::string replacePattern;
|
|
static std::string outputString;
|
|
|
|
ImGui::PushItemWidth(-150_scaled);
|
|
bool changed1 = ImGuiExt::InputTextIcon("hex.builtin.tools.regex_replacer.pattern"_lang, ICON_VS_REGEX, regexPattern);
|
|
bool changed2 = ImGuiExt::InputTextIcon("hex.builtin.tools.regex_replacer.replace"_lang, ICON_VS_REGEX, replacePattern);
|
|
bool changed3 = ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.input"_lang, inputString, ImVec2(0, 0));
|
|
|
|
if (changed1 || changed2 || changed3) {
|
|
try {
|
|
const auto regex = boost::regex(regexPattern);
|
|
outputString = boost::regex_replace(inputString, regex, replacePattern);
|
|
} catch (const boost::regex_error &e) {
|
|
log::warn("Invalid regex pattern in Regex Replacer tool: {}", e.what());
|
|
}
|
|
}
|
|
|
|
ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.output"_lang, outputString, ImVec2(0, 0), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
ImGui::PopItemWidth();
|
|
}
|
|
|
|
}
|