1
0
mirror of synced 2024-12-15 01:01:15 +01:00
ImHex/plugins/builtin/source/content/tools/regex_replacer.cpp

38 lines
1.4 KiB
C++
Raw Normal View History

#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/api/localization_manager.hpp>
#include <boost/regex.hpp>
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <fonts/codicons_font.h>
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 (boost::regex_error &) { }
}
ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.output"_lang, outputString.data(), outputString.size(), ImVec2(0, 0), ImGuiInputTextFlags_ReadOnly);
ImGui::PopItemWidth();
}
}