chore: apply light lints (#2570)

This commit is contained in:
iTrooz
2025-12-19 23:49:37 +01:00
committed by GitHub
parent 92cfdf1145
commit 261610dcf1
72 changed files with 477 additions and 447 deletions

View File

@@ -12,7 +12,7 @@ namespace hex::plugin::builtin {
[[nodiscard]] UnlocalizedString getTitle() const override;
private:
static void resize(size_t newSize);
void resize(size_t newSize);
u64 m_size;
};
}

View File

@@ -66,7 +66,7 @@ namespace hex::plugin::builtin {
private:
void handleFileChange();
OpenResult open(bool memoryMapped);
OpenResult open(bool directAccess);
protected:
std::fs::path m_path;

View File

@@ -191,7 +191,7 @@ namespace hex::plugin::builtin {
void renderErrors();
/// A token range is the set of token indices of a definition. The namespace token
/// ranges are obtained first because they are needed to obtain unique identifiers.
void getAllTokenRanges(IdentifierType idtype);
void getAllTokenRanges(IdentifierType identifierTypeToSearch);
/// The global scope is the complement of the union of all the function and UDT token ranges
void getGlobalTokenRanges();
/// If the current token is a function or UDT, creates a map entry from the name to the token range. These are ordered alphabetically by name.
@@ -251,10 +251,10 @@ namespace hex::plugin::builtin {
void skipDelimiters(i32 maxSkipCount, Token delimiter[2], i8 increment);
void skipToken(Token token, i8 step=1);
/// from given or current names find the corresponding definition
bool findIdentifierDefinition(Definition &result, const std::string &optionalIdentifierName = "", std::string optionalName = "", bool optional = false);
bool findIdentifierDefinition(Definition &result, const std::string &optionalIdentifierName = "", std::string optionalName = "", bool setInstances = false);
/// To deal with the Parent keyword
std::optional<Definition> setChildrenTypes();
bool findParentTypes(std::vector<std::string> &parentTypes, const std::string &optionalName="");
bool findParentTypes(std::vector<std::string> &parentTypes, const std::string &optionalUDTName="");
bool findAllParentTypes(std::vector<std::string> &parentTypes, std::vector<Identifier *> &identifiers, std::string &optionalFullName);
bool tryParentType(const std::string &parentType, std::string &variableName, std::optional<Definition> &result, std::vector<Identifier *> &identifiers);
/// Convenience function

View File

@@ -0,0 +1,46 @@
namespace hex::plugin::builtin {
void registerEventHandlers();
void registerDataVisualizers();
void registerMiniMapVisualizers();
void registerDataInspectorEntries();
void registerToolEntries();
void registerPatternLanguageFunctions();
void registerPatternLanguageTypes();
void registerPatternLanguagePragmas();
void registerPatternLanguageVisualizers();
void registerCommandPaletteCommands();
void registerSettings();
void loadSettings();
void registerDataProcessorNodes();
void registerProviders();
void registerDataFormatters();
void registerMainMenuEntries();
void createWelcomeScreen();
void registerViews();
void registerThemeHandlers();
void registerStyleHandlers();
void registerThemes();
void registerBackgroundServices();
void registerNetworkEndpoints();
void registerMCPTools();
void registerFileHandlers();
void registerProjectHandlers();
void registerAchievements();
void registerReportGenerators();
void registerTutorials();
void registerDataInformationSections();
void loadWorkspaces();
void addWindowDecoration();
void addFooterItems();
void addTitleBarButtons();
void addToolbarItems();
void addGlobalUIItems();
void addInitTasks();
void handleBorderlessWindowMode();
void setupOutOfBoxExperience();
void extractBundledFiles();
}

View File

@@ -352,7 +352,7 @@ namespace hex::plugin::builtin {
}
void handleHexdumpCommand(const std::vector<std::string> &args) {
if (args.size() < 1 || args.size() > 3) {
if (args.empty() || args.size() > 3) {
log::println("usage: imhex --hexdump <file> <offset> <size>");
std::exit(EXIT_FAILURE);
}
@@ -399,7 +399,7 @@ namespace hex::plugin::builtin {
if (std::fgets(input.data(), input.size() - 1, stdin) == nullptr)
std::exit(EXIT_FAILURE);
input = input.c_str();
input = input.c_str(); // Stop at first null byte
input = wolv::util::trim(input);
if (input == ConfirmationString) {
@@ -536,7 +536,7 @@ namespace hex::plugin::builtin {
mcp::Client client;
auto result = client.run(std::cin, std::cout);
std::fprintf(stderr, "MCP Client disconnected!\n");
fmt::print(stderr, "MCP Client disconnected!\n");
std::exit(result);
}

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <hex/api/imhex_api/provider.hpp>
#include <hex/api/imhex_api/hex_editor.hpp>
#include <hex/api/content_registry/data_inspector.hpp>
@@ -42,7 +43,7 @@ namespace hex::plugin::builtin {
std::memcpy(bytes.data(), &result, bytes.size());
if (endian != std::endian::native)
std::reverse(bytes.begin(), bytes.end());
std::ranges::reverse(bytes);
return bytes;
});
@@ -58,7 +59,7 @@ namespace hex::plugin::builtin {
std::memcpy(bytes.data(), &result, bytes.size());
if (endian != std::endian::native)
std::reverse(bytes.begin(), bytes.end());
std::ranges::reverse(bytes);
return bytes;
});
@@ -73,7 +74,7 @@ namespace hex::plugin::builtin {
std::memcpy(bytes.data(), &result, bytes.size());
if (endian != std::endian::native)
std::reverse(bytes.begin(), bytes.end());
std::ranges::reverse(bytes);
return bytes;
});
@@ -449,7 +450,7 @@ namespace hex::plugin::builtin {
std::memcpy(bytes.data(), wideString->data(), bytes.size());
if (endian != std::endian::native)
std::reverse(bytes.begin(), bytes.end());
std::ranges::reverse(bytes);
return bytes;
})
@@ -477,7 +478,7 @@ namespace hex::plugin::builtin {
std::memcpy(bytes.data(), wideString->data(), bytes.size());
if (endian != std::endian::native)
std::reverse(bytes.begin(), bytes.end());
std::ranges::reverse(bytes);
return bytes;
})
@@ -505,7 +506,7 @@ namespace hex::plugin::builtin {
std::memcpy(bytes.data(), wideString->data(), bytes.size());
if (endian != std::endian::native)
std::reverse(bytes.begin(), bytes.end());
std::ranges::reverse(bytes);
return bytes;
})

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <hex/api/content_registry/data_processor.hpp>
#include <hex/data_processor/node.hpp>
@@ -159,7 +160,7 @@ namespace hex::plugin::builtin {
for (u8 &b : data)
b = BitFlipLookup[b & 0xf] << 4 | BitFlipLookup[b >> 4];
std::reverse(data.begin(), data.end());
std::ranges::reverse(data);
this->setBufferOnOutput(1, data);
}

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <hex/api/imhex_api/provider.hpp>
#include <hex/api/content_registry/pattern_language.hpp>
#include <hex/api/content_registry/data_processor.hpp>
@@ -8,6 +9,7 @@
#include <hex/data_processor/node.hpp>
#include <hex/helpers/utils.hpp>
#include <numeric>
#include <wolv/utils/core.hpp>
#include <content/helpers/diagrams.hpp>
@@ -174,7 +176,7 @@ namespace hex::plugin::builtin {
const auto &inputB = this->getBufferOnInput(1);
auto output = inputA;
std::copy(inputB.begin(), inputB.end(), std::back_inserter(output));
std::ranges::copy(inputB, std::back_inserter(output));
this->setBufferOnOutput(2, output);
}
@@ -212,7 +214,7 @@ namespace hex::plugin::builtin {
output.resize(buffer.size() * count);
for (u32 i = 0; i < count; i++)
std::copy(buffer.begin(), buffer.end(), output.begin() + buffer.size() * i);
std::ranges::copy(buffer, output.begin() + buffer.size() * i);
this->setBufferOnOutput(2, output);
}
@@ -233,7 +235,7 @@ namespace hex::plugin::builtin {
if (address + patch.size() > buffer.size())
buffer.resize(address + patch.size());
std::copy(patch.begin(), patch.end(), buffer.begin() + address);
std::ranges::copy(patch, buffer.begin() + address);
this->setBufferOnOutput(3, buffer);
}
@@ -382,7 +384,7 @@ namespace hex::plugin::builtin {
if (ImPlot::BeginPlot("##distribution", viewSize, ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect)) {
ImPlot::SetupAxes("Address", "Count", ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock);
ImPlot::SetupAxisScale(ImAxis_Y1, ImPlotScale_Log10);
ImPlot::SetupAxesLimits(0, 256, 1, double(*std::max_element(m_counts.begin(), m_counts.end())) * 1.1F, ImGuiCond_Always);
ImPlot::SetupAxesLimits(0, 256, 1, double(*std::ranges::max_element(m_counts)) * 1.1F, ImGuiCond_Always);
static auto x = [] {
std::array<ImU64, 256> result { 0 };
@@ -463,7 +465,7 @@ namespace hex::plugin::builtin {
void process() override {
auto data = this->getBufferOnInput(0);
std::reverse(data.begin(), data.end());
std::ranges::reverse(data);
this->setBufferOnOutput(1, data);
}

View File

@@ -90,8 +90,8 @@ namespace hex::plugin::builtin {
}
private:
constexpr static inline auto ByteCount = 1;
constexpr static inline auto CharCount = ByteCount * 2;
constexpr static auto ByteCount = 1;
constexpr static auto CharCount = ByteCount * 2;
const static inline auto FormattingUpperCase = fmt::format("%0{}{}X", CharCount, ImGuiExt::getFormatLengthSpecifier<u8>());
const static inline auto FormattingLowerCase = fmt::format("%0{}{}x", CharCount, ImGuiExt::getFormatLengthSpecifier<u8>());
@@ -175,13 +175,13 @@ namespace hex::plugin::builtin {
}
private:
constexpr static inline auto ByteCount = sizeof(T);
constexpr static inline auto CharCount = 14;
constexpr static auto ByteCount = sizeof(T);
constexpr static auto CharCount = 14;
const static inline auto FormatStringUpperCase = fmt::format("%{}G", CharCount);
const static inline auto FormatStringLowerCase = fmt::format("%{}g", CharCount);
const char *getFormatString(bool upperCase) const {
[[nodiscard]] const char *getFormatString(bool upperCase) const {
if (upperCase)
return FormatStringUpperCase.c_str();
else

View File

@@ -258,11 +258,11 @@ namespace hex::plugin::builtin {
});
EventImHexStartupFinished::subscribe([] {
const auto currVersion = ImHexApi::System::getImHexVersion();
const auto& currVersion = ImHexApi::System::getImHexVersion();
const auto prevLaunchVersion = ContentRegistry::Settings::read<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", "");
const auto forceOobe = getEnvironmentVariable("IMHEX_FORCE_OOBE");
if (prevLaunchVersion == "" || (forceOobe.has_value() && *forceOobe != "0")) {
if (prevLaunchVersion.empty() || (forceOobe.has_value() && *forceOobe != "0")) {
EventFirstLaunch::post();
return;
}

View File

@@ -123,7 +123,7 @@ namespace hex::plugin::builtin {
if (restoreWindowPos) {
ImHexApi::System::InitialWindowProperties properties = {};
properties.maximized = ContentRegistry::Settings::read<bool>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window.maximized", 0);
properties.maximized = ContentRegistry::Settings::read<bool>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window.maximized", false);
properties.x = ContentRegistry::Settings::read<int>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window.x", 0);
properties.y = ContentRegistry::Settings::read<int>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window.y", 0);
properties.width = ContentRegistry::Settings::read<int>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window.width", 0);

View File

@@ -51,9 +51,9 @@ namespace hex::plugin::builtin {
void zerosMiniMapVisualizer(u64, std::span<const u8> data, std::vector<ImColor> &output) {
for (u8 byte : data) {
if (byte == 0x00)
output.push_back(ImColor(1.0F, 1.0F, 1.0F, 1.0F));
output.emplace_back(1.0F, 1.0F, 1.0F, 1.0F);
else
output.push_back(ImColor(0.0F, 0.0F, 0.0F, 1.0F));
output.emplace_back(0.0F, 0.0F, 0.0F, 1.0F);
}
}
@@ -99,7 +99,7 @@ namespace hex::plugin::builtin {
void rgba8MiniMapVisualizer(u64 address, std::span<const u8> data, std::vector<ImColor> &output) {
colorMinimapVisualizer(address, data, output, 4, [](std::span<const u8> subData) -> ImColor {
return ImColor(subData[0], subData[1], subData[2], 0xFF);
return {subData[0], subData[1], subData[2], 0xFF};
});
}
@@ -108,7 +108,7 @@ namespace hex::plugin::builtin {
u8 r = (subData[0] & 0xF8);
u8 g = ((subData[0] & 0x07) << 5) | ((subData[1] & 0xE0) >> 3);
u8 b = (subData[1] & 0x1F) << 3;
return ImColor(r, g, b, 0xFF);
return {r, g, b, 0xFF};
});
}

View File

@@ -37,7 +37,7 @@ namespace hex::plugin::builtin {
class Blend {
public:
Blend(float start, float end) : m_time(0), m_start(start), m_end(end) {}
Blend(float start, float end) : m_start(start), m_end(end) {}
[[nodiscard]] operator float() {
m_time += ImGui::GetIO().DeltaTime;
@@ -56,7 +56,7 @@ namespace hex::plugin::builtin {
}
private:
float m_time;
float m_time = 0;
float m_start, m_end;
};
@@ -472,7 +472,7 @@ namespace hex::plugin::builtin {
EventFirstLaunch::subscribe([] {
ImHexApi::System::setWindowResizable(false);
const auto imageTheme = ThemeManager::getImageTheme();
auto &imageTheme = ThemeManager::getImageTheme();
s_imhexBanner = ImGuiExt::Texture::fromSVG(romfs::get(fmt::format("assets/{}/banner.svg", imageTheme)).span<std::byte>(), 0, 0, ImGuiExt::Texture::Filter::Linear);
s_compassTexture = ImGuiExt::Texture::fromImage(romfs::get("assets/common/compass.png").span<std::byte>(), ImGuiExt::Texture::Filter::Linear);
s_globeTexture = ImGuiExt::Texture::fromImage(romfs::get("assets/common/globe.png").span<std::byte>(), ImGuiExt::Texture::Filter::Linear);

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <hex/api/content_registry/pattern_language.hpp>
#include <hex/helpers/encoding_file.hpp>
@@ -43,7 +44,7 @@ namespace hex::plugin::builtin {
this->getEvaluator()->readData(this->getOffset(), result.data(), result.size(), this->getSection());
if (this->getEndian() != std::endian::native)
std::reverse(result.begin(), result.end());
std::ranges::reverse(result);
return result;
}

View File

@@ -27,7 +27,7 @@ namespace hex::plugin::builtin {
using namespace std::chrono_literals;
CommandProvider::CommandProvider() { }
CommandProvider::CommandProvider() = default;
bool CommandProvider::isAvailable() const {
return m_open;

View File

@@ -217,7 +217,7 @@ namespace hex::plugin::builtin {
auto data = gdb::readMemory(m_socket, offset, size);
if (!data.empty())
std::memcpy(buffer, &data[0], data.size());
std::memcpy(buffer, data.data(), data.size());
}
void GDBProvider::writeToSource(u64 offset, const void *buffer, size_t size) {

View File

@@ -1,5 +1,6 @@
#if defined(OS_WINDOWS) || defined(OS_MACOS) || (defined(OS_LINUX) && !defined(OS_FREEBSD))
#include <algorithm>
#include <content/providers/process_memory_provider.hpp>
#include <hex/api/imhex_api/hex_editor.hpp>
@@ -568,7 +569,7 @@ namespace hex::plugin::builtin {
std::variant<std::string, i128> ProcessMemoryProvider::queryInformation(const std::string &category, const std::string &argument) {
auto findRegionByName = [this](const std::string &name) {
return std::find_if(m_memoryRegions.begin(), m_memoryRegions.end(),
return std::ranges::find_if(m_memoryRegions,
[name](const auto &region) {
return region.name == name;
});

View File

@@ -116,7 +116,7 @@ namespace hex::plugin::builtin::recent {
return ImGuiWindowFlags_AlwaysAutoResize;
}
void saveCurrentProjectAsRecent() {
static void saveCurrentProjectAsRecent() {
if (!ContentRegistry::Settings::read<bool>("hex.builtin.setting.general", "hex.builtin.setting.general.save_recent_providers", true)) {
return;
}

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <hex/api/imhex_api/system.hpp>
#include <hex/api/content_registry/settings.hpp>
#include <hex/api/content_registry/user_interface.hpp>
@@ -81,11 +82,7 @@ namespace hex::plugin::builtin {
return "%d FPS";
}();
if (ImGui::SliderInt(name.data(), &m_value, 14, 201, format.c_str(), ImGuiSliderFlags_AlwaysClamp)) {
return true;
}
return false;
return ImGui::SliderInt(name.data(), &m_value, 14, 201, format.c_str(), ImGuiSliderFlags_AlwaysClamp);
}
void load(const nlohmann::json &data) override {
@@ -129,7 +126,7 @@ namespace hex::plugin::builtin {
if (ImGuiExt::DimmedIconButton(ICON_VS_NEW_FOLDER, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
fs::openFileBrowser(fs::DialogMode::Folder, {}, [&](const std::fs::path &path) {
if (std::find(m_paths.begin(), m_paths.end(), path) == m_paths.end()) {
if (std::ranges::find(m_paths, path) == m_paths.end()) {
m_paths.emplace_back(path);
ImHexApi::System::setAdditionalFolderPaths(m_paths);
@@ -170,7 +167,8 @@ namespace hex::plugin::builtin {
nlohmann::json store() override {
std::vector<std::string> pathStrings;
for (const auto &path : m_paths) {
pathStrings.reserve(m_paths.size());
for (const auto &path : m_paths) {
pathStrings.push_back(wolv::io::fs::toNormalizedPathString(path));
}
@@ -211,7 +209,7 @@ namespace hex::plugin::builtin {
return m_value;
}
float getValue() const {
[[nodiscard]] float getValue() const {
return m_value;
}
@@ -232,11 +230,7 @@ namespace hex::plugin::builtin {
return fmt::format("hex.builtin.setting.general.backups.auto_backup_time.format.extended"_lang, value / 60, value % 60);
}();
if (ImGui::SliderInt(name.data(), &m_value, 0, (30 * 60) / 30, format.c_str(), ImGuiSliderFlags_AlwaysClamp | ImGuiSliderFlags_NoInput)) {
return true;
}
return false;
return ImGui::SliderInt(name.data(), &m_value, 0, (30 * 60) / 30, format.c_str(), ImGuiSliderFlags_AlwaysClamp | ImGuiSliderFlags_NoInput);
}
void load(const nlohmann::json &data) override {
@@ -794,6 +788,7 @@ namespace hex::plugin::builtin {
{
auto themeNames = ThemeManager::getThemeNames();
std::vector<nlohmann::json> themeJsons = { };
themeJsons.reserve(themeNames.size());
for (const auto &themeName : themeNames)
themeJsons.emplace_back(themeName);
@@ -1059,7 +1054,8 @@ namespace hex::plugin::builtin {
auto folderPathStrings = ContentRegistry::Settings::read<std::vector<std::string>>("hex.builtin.setting.folders", "hex.builtin.setting.folders", { });
std::vector<std::fs::path> paths;
for (const auto &pathString : folderPathStrings) {
paths.reserve(folderPathStrings.size());
for (const auto &pathString : folderPathStrings) {
paths.emplace_back(pathString);
}

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <content/text_highlighting/pattern_language.hpp>
#include <pl/core/ast/ast_node_type_decl.hpp>
#include <pl/core/ast/ast_node_enum.hpp>
@@ -59,7 +60,7 @@ namespace hex::plugin::builtin {
bool TextHighlighter::forwardIdentifierName(std::string &identifierName, std::vector<Identifier *> &identifiers, bool preserveCurr ) {
auto curr = m_curr;
Identifier *identifier = getValue<Identifier>(0);
auto *identifier = getValue<Identifier>(0);
std::string current;
if (identifier != nullptr) {
@@ -287,7 +288,7 @@ namespace hex::plugin::builtin {
if (peek(tkn::Literal::Identifier)) {
if (identifier = getValue<Identifier>(0); identifier != nullptr) {
identifierType = identifier->getType();
std::string name = identifier->get();
auto& name = identifier->get();
if (identifierType == identifierTypeToSearch) {
switch (identifierType) {
@@ -367,8 +368,7 @@ namespace hex::plugin::builtin {
}
}
m_curr = curr;
return;
}
}
void TextHighlighter::skipTemplate(i32 maxSkipCount, bool forward) {
Token delimiters[2];
@@ -523,7 +523,7 @@ namespace hex::plugin::builtin {
result.idType = IdentifierType::Unknown;
std::string identifierName = optionalIdentifierName;
if (optionalIdentifierName == "") {
if (optionalIdentifierName.empty()) {
std::vector<Identifier *> identifiers;
getFullName(identifierName, identifiers);
}
@@ -579,7 +579,7 @@ namespace hex::plugin::builtin {
}
}
}
auto it = std::find_if(definitions.begin(), definitions.end(), [&](const Definition &definition) {
auto it = std::ranges::find_if(definitions, [&](const Definition &definition) {
return definition.tokenIndex > tokenRange.start && definition.tokenIndex < tokenRange.end;
});
@@ -681,7 +681,7 @@ namespace hex::plugin::builtin {
next();
} else if (auto udtVars = m_UDTVariables[result.typeStr];udtVars.contains(vectorString[index-1])) {
auto saveCurr = m_curr;
std::string templateName = "";
std::string templateName;
auto instances = m_instances[variableParentType];
for (auto instance : instances) {
if (auto *identifier = std::get_if<Identifier>(&m_tokens[instance].value); identifier != nullptr && identifier->getType() == IdentifierType::TemplateArgument) {
@@ -704,7 +704,7 @@ namespace hex::plugin::builtin {
next();
} else{
if (m_typeDefMap.contains(variableParentType)) {
std::string typeName = "";
std::string typeName;
instances = m_instances[variableParentType];
for (auto instance: instances) {
if (auto *identifier = std::get_if<Identifier>(&m_tokens[instance].value);
@@ -771,7 +771,7 @@ namespace hex::plugin::builtin {
if (!sequence(tkn::Operator::ScopeResolution) || vectorStringCount != i+2 ||
!m_UDTVariables.contains(name))
return false;
auto variableName = vectorString[i+1];
const auto& variableName = vectorString[i+1];
if (!m_UDTVariables[name].contains(variableName))
return false;
auto variableDefinition = m_UDTVariables[name][variableName][0];
@@ -858,16 +858,14 @@ namespace hex::plugin::builtin {
if (tokenId > interval.start && tokenId < interval.end) {
if (nameSpace == "")
if (nameSpace.empty())
nameSpace = name;
else
nameSpace = name + "::" + nameSpace;
}
}
if (nameSpace != "")
return true;
return false;
return nameSpace != "";
}
//The context is the name of the function or UDT that the variable is in.
@@ -1300,7 +1298,7 @@ namespace hex::plugin::builtin {
if (identifierType == IdentifierType::Typedef) {
auto curr = m_curr;
next();
std::string typeName = "";
std::string typeName;
if (sequence(tkn::Operator::Assign, tkn::Literal::Identifier)) {
auto identifier2 = getValue<Identifier>(-1);
if (identifier2 != nullptr) {
@@ -1452,7 +1450,8 @@ namespace hex::plugin::builtin {
void TextHighlighter::colorRemainingIdentifierTokens() {
std::vector<i32> taggedIdentifiers;
for (auto index: m_taggedIdentifiers) {
taggedIdentifiers.reserve(m_taggedIdentifiers.size());
for (auto index: m_taggedIdentifiers) {
taggedIdentifiers.push_back(index);
}
m_taggedIdentifiers.clear();
@@ -1470,7 +1469,7 @@ namespace hex::plugin::builtin {
taggedIdentifiers.pop_back();
}
Token *token = const_cast<Token *>(&m_curr[0]);
auto *token = const_cast<Token *>(&m_curr[0]);
if (sequence(tkn::Keyword::Import, tkn::Literal::Identifier)) {
next(-1);
@@ -1581,7 +1580,7 @@ namespace hex::plugin::builtin {
continue;
std::string lineOfColors = std::string(m_lines[line].size(), 0);
for (auto tokenIndex = m_firstTokenIdOfLine[line]; tokenIndex < m_firstTokenIdOfLine[nextLine(line)]; tokenIndex++) {
Token *token = const_cast<Token *>(&m_tokens[tokenIndex]);
auto *token = const_cast<Token *>(&m_tokens[tokenIndex]);
if (m_tokenColors.contains(token) && token->type == Token::Type::Identifier) {
u8 color = (u8) m_tokenColors.at(token);
u32 tokenLength = token->location.length;
@@ -1935,7 +1934,7 @@ namespace hex::plugin::builtin {
}
m_lines = wolv::util::splitString(m_text, "\n");
m_lines.push_back("");
m_lines.emplace_back("");
m_firstTokenIdOfLine.clear();
m_firstTokenIdOfLine.resize(m_lines.size(), -1);
@@ -2143,7 +2142,7 @@ namespace hex::plugin::builtin {
while (next != ranges.end()) {
if (next->start - it->end < 2) {
Interval &range = const_cast<Interval &>(*it);
auto &range = const_cast<Interval &>(*it);
range.end = next->end;
ranges.erase(next);
next = std::next(it);
@@ -2345,6 +2344,5 @@ namespace hex::plugin::builtin {
m_wasInterrupted = true;
return;
}
return;
}
}

View File

@@ -4,6 +4,7 @@
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <content/tools_entries.hpp>
#include <fonts/vscode_icons.hpp>

View File

@@ -124,7 +124,7 @@ namespace hex::plugin::builtin {
if (response.valid() && response.wait_for(0s) != std::future_status::timeout) {
const auto result = response.get();
const auto data = result.getData();
const auto& data = result.getData();
if (const auto status = result.getStatusCode(); status != 0)
responseText = "Status: " + std::to_string(result.getStatusCode()) + "\n\n" + data;

View File

@@ -25,12 +25,12 @@ namespace hex::plugin::builtin {
class IEEE754STATICS {
public:
IEEE754STATICS() : value(0), exponentBitCount(8), mantissaBitCount(23), resultFloat(0) {}
IEEE754STATICS() {}
u128 value;
i32 exponentBitCount;
i32 mantissaBitCount;
long double resultFloat;
u128 value = 0;
i32 exponentBitCount = 8;
i32 mantissaBitCount =23;
long double resultFloat = 0;
};
static IEEE754STATICS ieee754statics;

View File

@@ -9,7 +9,7 @@
namespace hex::plugin::builtin {
void drawFileTools() {
static void drawFileTools() {
if (ImGui::BeginTabBar("file_tools_tabs")) {
if (ImGui::BeginTabItem("hex.builtin.tools.file_tools.shredder"_lang)) {
drawFileToolShredder();

View File

@@ -121,7 +121,7 @@ namespace hex::plugin::builtin {
try {
const auto attribute = pattern->getAttributeArguments(SimplifiedEditorAttribute);
const auto name = attribute.size() >= 1 ? attribute[0].toString() : pattern->getDisplayName();
const auto name = !attribute.empty() ? attribute[0].toString() : pattern->getDisplayName();
const auto description = attribute.size() >= 2 ? attribute[1].toString() : pattern->getComment();
const auto widgetPos = 200_scaled;

View File

@@ -1,5 +1,6 @@
#include "content/views/view_achievements.hpp"
#include <algorithm>
#include <hex/api/content_registry/user_interface.hpp>
#include <hex/api/content_registry/settings.hpp>
#include <hex/api/task_manager.hpp>
@@ -321,11 +322,12 @@ namespace hex::plugin::builtin {
// Get all achievement category names
std::vector<std::string> categories;
for (const auto &[categoryName, achievements] : startNodes) {
categories.reserve(startNodes.size());
for (const auto &[categoryName, achievements] : startNodes) {
categories.push_back(categoryName);
}
std::reverse(categories.begin(), categories.end());
std::ranges::reverse(categories);
// Draw each individual achievement category
for (const auto &categoryName : categories) {

View File

@@ -1,5 +1,6 @@
#include "content/views/view_data_inspector.hpp"
#include <algorithm>
#include <hex/api/achievement_manager.hpp>
#include <hex/api/content_registry/settings.hpp>
#include <hex/providers/provider.hpp>
@@ -263,7 +264,7 @@ namespace hex::plugin::builtin {
}
const auto selection = ImHexApi::HexEditor::getSelection();
const auto selectedEntryIt = std::find_if(m_cachedData.begin(), m_cachedData.end(), [this](const InspectorCacheEntry &entry) {
const auto selectedEntryIt = std::ranges::find_if(m_cachedData, [this](const InspectorCacheEntry &entry) {
return entry.unlocalizedName == m_selectedEntryName;
});

View File

@@ -1,4 +1,5 @@
#include "content/views/view_data_processor.hpp"
#include <algorithm>
#include <toasts/toast_notification.hpp>
#include <hex/api/content_registry/data_processor.hpp>
@@ -52,9 +53,9 @@ namespace hex::plugin::builtin {
void setValue(auto value) { m_value = std::move(value); }
const std::string &getName() const { return m_name; }
[[nodiscard]] const std::string &getName() const { return m_name; }
dp::Attribute::Type getType() const {
[[nodiscard]] dp::Attribute::Type getType() const {
switch (m_type) {
default:
case 0: return dp::Attribute::Type::Integer;
@@ -121,8 +122,8 @@ namespace hex::plugin::builtin {
ImGui::PopItemWidth();
}
const std::string &getName() const { return m_name; }
dp::Attribute::Type getType() const {
[[nodiscard]] const std::string &getName() const { return m_name; }
[[nodiscard]] dp::Attribute::Type getType() const {
switch (m_type) {
case 0: return dp::Attribute::Type::Integer;
case 1: return dp::Attribute::Type::Float;
@@ -139,7 +140,7 @@ namespace hex::plugin::builtin {
}
}
const auto& getValue() const { return m_value; }
[[nodiscard]] const auto& getValue() const { return m_value; }
void store(nlohmann::json &j) const override {
j = nlohmann::json::object();
@@ -314,7 +315,7 @@ namespace hex::plugin::builtin {
}
private:
std::vector<dp::Attribute> findAttributes() const {
[[nodiscard]] std::vector<dp::Attribute> findAttributes() const {
std::vector<dp::Attribute> result;
// Search through all nodes in the workspace and add all input and output nodes to the result
@@ -328,7 +329,7 @@ namespace hex::plugin::builtin {
return result;
}
NodeCustomInput* findInput(const std::string &name) const {
[[nodiscard]] NodeCustomInput* findInput(const std::string &name) const {
for (auto &node : m_workspace.nodes) {
if (auto *inputNode = dynamic_cast<NodeCustomInput*>(node.get()); inputNode != nullptr && inputNode->getName() == name)
return inputNode;
@@ -337,7 +338,7 @@ namespace hex::plugin::builtin {
return nullptr;
}
NodeCustomOutput* findOutput(const std::string &name) const {
[[nodiscard]] NodeCustomOutput* findOutput(const std::string &name) const {
for (auto &node : m_workspace.nodes) {
if (auto *outputNode = dynamic_cast<NodeCustomOutput*>(node.get()); outputNode != nullptr && outputNode->getName() == name)
return outputNode;
@@ -445,7 +446,7 @@ namespace hex::plugin::builtin {
void ViewDataProcessor::eraseLink(Workspace &workspace, int id) {
// Find the link with the given ID
auto link = std::find_if(workspace.links.begin(), workspace.links.end(),
auto link = std::ranges::find_if(workspace.links,
[&id](auto link) {
return link.getId() == id;
});
@@ -472,7 +473,7 @@ namespace hex::plugin::builtin {
// and remove all links that are connected to the attributes of the node
for (int id : ids) {
// Find the node with the given ID
auto node = std::find_if(workspace.nodes.begin(), workspace.nodes.end(),
auto node = std::ranges::find_if(workspace.nodes,
[&id](const auto &node) {
return node->getId() == id;
});
@@ -495,7 +496,7 @@ namespace hex::plugin::builtin {
// and remove the nodes from the workspace
for (int id : ids) {
// Find the node with the given ID
auto node = std::find_if(workspace.nodes.begin(), workspace.nodes.end(),
auto node = std::ranges::find_if(workspace.nodes,
[&id](const auto &node) {
return node->getId() == id;
});
@@ -762,7 +763,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginPopup("Node Menu")) {
if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.save_node"_lang)) {
// Find the node that was right-clicked
auto it = std::find_if(workspace.nodes.begin(), workspace.nodes.end(),
auto it = std::ranges::find_if(workspace.nodes,
[this](const auto &node) {
return node->getId() == m_rightClickedId;
});
@@ -856,7 +857,7 @@ namespace hex::plugin::builtin {
auto value = i64(*reinterpret_cast<i128*>(defaultValue.data()));
if (ImGui::InputScalar(Lang(attribute.getUnlocalizedName()), ImGuiDataType_S64, &value)) {
std::fill(defaultValue.begin(), defaultValue.end(), 0x00);
std::ranges::fill(defaultValue, 0x00);
i128 writeValue = value;
std::memcpy(defaultValue.data(), &writeValue, sizeof(writeValue));
@@ -866,7 +867,7 @@ namespace hex::plugin::builtin {
auto value = double(*reinterpret_cast<long double*>(defaultValue.data()));
if (ImGui::InputScalar(Lang(attribute.getUnlocalizedName()), ImGuiDataType_Double, &value)) {
std::fill(defaultValue.begin(), defaultValue.end(), 0x00);
std::ranges::fill(defaultValue, 0x00);
long double writeValue = value;
std::memcpy(defaultValue.data(), &writeValue, sizeof(writeValue));

View File

@@ -1,5 +1,6 @@
#include "content/views/view_find.hpp"
#include <algorithm>
#include <hex/api/achievement_manager.hpp>
#include <hex/api/imhex_api/hex_editor.hpp>
#include <hex/api/events/events_interaction.hpp>
@@ -214,16 +215,16 @@ namespace hex::plugin::builtin {
newSettings.type = ASCII;
auto asciiResults = searchStrings(task, provider, searchRegion, newSettings);
std::copy(asciiResults.begin(), asciiResults.end(), std::back_inserter(results));
std::ranges::copy(asciiResults, std::back_inserter(results));
if (settings.type == ASCII_UTF16BE) {
newSettings.type = UTF16BE;
auto utf16Results = searchStrings(task, provider, searchRegion, newSettings);
std::copy(utf16Results.begin(), utf16Results.end(), std::back_inserter(results));
std::ranges::copy(utf16Results, std::back_inserter(results));
} else if (settings.type == ASCII_UTF16LE) {
newSettings.type = UTF16LE;
auto utf16Results = searchStrings(task, provider, searchRegion, newSettings);
std::copy(utf16Results.begin(), utf16Results.end(), std::back_inserter(results));
std::ranges::copy(utf16Results, std::back_inserter(results));
}
return results;
@@ -921,7 +922,7 @@ namespace hex::plugin::builtin {
ImGui::Checkbox(fmt::format("{} [0-9]", "hex.builtin.view.find.strings.numbers"_lang.get()).c_str(), &settings.numbers);
ImGui::Checkbox(fmt::format("{} [_]", "hex.builtin.view.find.strings.underscores"_lang.get()).c_str(), &settings.underscores);
ImGui::Checkbox(fmt::format("{} [!\"#$%...]", "hex.builtin.view.find.strings.symbols"_lang.get()).c_str(), &settings.symbols);
ImGui::Checkbox(fmt::format("{} [ \\f\\t\\v]", "hex.builtin.view.find.strings.spaces"_lang.get()).c_str(), &settings.spaces);
ImGui::Checkbox(fmt::format(R"({} [ \f\t\v])", "hex.builtin.view.find.strings.spaces"_lang.get()).c_str(), &settings.spaces);
ImGui::Checkbox(fmt::format("{} [\\r\\n]", "hex.builtin.view.find.strings.line_feeds"_lang.get()).c_str(), &settings.lineFeeds);
ImGui::EndPopup();
@@ -1158,11 +1159,11 @@ namespace hex::plugin::builtin {
m_filterTask.interrupt();
static std::mutex mutex;
std::lock_guard lock(mutex);
std::scoped_lock lock(mutex);
if (!m_currFilter->empty()) {
m_filterTask = TaskManager::createTask("hex.builtin.task.filtering_data", currOccurrences.size(), [this, provider, &currOccurrences, filter = m_currFilter.get(provider)](Task &task) {
std::lock_guard lock(mutex);
std::scoped_lock lock(mutex);
u64 progress = 0;
std::erase_if(currOccurrences, [this, provider, &task, &progress, &filter](const auto &region) {

View File

@@ -304,7 +304,7 @@ namespace hex::plugin::builtin {
try {
const auto attribute = pattern->getAttributeArguments(SimplifiedEditorAttribute);
const auto name = attribute.size() >= 1 ? attribute[0].toString() : pattern->getDisplayName();
const auto name = !attribute.empty() ? attribute[0].toString() : pattern->getDisplayName();
const auto description = attribute.size() >= 2 ? attribute[1].toString() : pattern->getComment();
const auto widgetPos = 200_scaled;

View File

@@ -456,8 +456,8 @@ namespace hex::plugin::builtin {
)
)
);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0F, 0.0F));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0F, 0.0F));
if (ImGui::BeginChild("##pattern_editor_resizer", defaultEditorSize, ImGuiChildFlags_ResizeY)) {
m_textEditor.get(provider).render("##pattern_editor", ImGui::GetContentRegionAvail(), false);
m_textEditorHoverBox = ImGui::GetCurrentWindow()->Rect();
@@ -1257,7 +1257,7 @@ namespace hex::plugin::builtin {
m_hasUnevaluatedChanges.get(provider) = true;
variable.value = buffer[0];
} else if (variable.type == pl::core::Token::ValueType::String) {
std::string buffer = hex::get_or<std::string>(variable.value, "");
auto buffer = hex::get_or<std::string>(variable.value, "");
if (ImGui::InputText(label.c_str(), buffer))
m_hasUnevaluatedChanges.get(provider) = true;
variable.value = buffer;
@@ -1354,7 +1354,7 @@ namespace hex::plugin::builtin {
for (const auto &frame : **m_callStack | std::views::reverse) {
auto location = frame.node->getLocation();
if (location.source != nullptr && location.source->mainSource) {
std::string message = "";
std::string message;
if (m_lastEvaluationError->has_value())
message = processMessage((*m_lastEvaluationError)->message);
auto key = ui::TextEditor::Coordinates(location.line, location.column);
@@ -1646,7 +1646,7 @@ namespace hex::plugin::builtin {
ContentRegistry::PatternLanguage::configureRuntime(*m_editorRuntime, nullptr);
const auto &ast = m_editorRuntime->parseString(code, pl::api::Source::DefaultSource);
m_textEditor.get(provider).setLongestLineLength(m_editorRuntime->getInternals().preprocessor.get()->getLongestLineLength());
m_textEditor.get(provider).setLongestLineLength(m_editorRuntime->getInternals().preprocessor->getLongestLineLength());
auto &patternVariables = m_patternVariables.get(provider);
auto oldPatternVariables = std::move(patternVariables);
@@ -2132,7 +2132,7 @@ namespace hex::plugin::builtin {
if (m_breakpoints->contains(line))
evaluator->removeBreakpoint(line);
else
else
evaluator->addBreakpoint(line);
m_breakpoints = evaluator->getBreakpoints();

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <hex.hpp>
#include <hex/api/workspace_manager.hpp>
@@ -162,7 +163,7 @@ namespace hex::plugin::builtin {
bool isAnyViewOpen() {
const auto &views = ContentRegistry::Views::impl::getEntries();
return std::any_of(views.begin(), views.end(),
return std::ranges::any_of(views,
[](const auto &entry) {
return entry.second->getWindowOpenState();
});
@@ -819,7 +820,7 @@ namespace hex::plugin::builtin {
std::mt19937 random(daysSinceEpoch.count());
auto chosenCategory = tipsCategories[random()%tipsCategories.size()].at("tips");
auto chosenTip = chosenCategory[random()%chosenCategory.size()];
const auto& chosenTip = chosenCategory[random()%chosenCategory.size()];
s_tipOfTheDay = chosenTip.get<std::string>();
bool showTipOfTheDay = ContentRegistry::Settings::read<bool>("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", false);

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <hex/api/content_registry/user_interface.hpp>
#include <hex/api/content_registry/views.hpp>
#include <hex/api/content_registry/settings.hpp>
@@ -601,7 +602,7 @@ namespace hex::plugin::builtin {
if (const auto &items = ContentRegistry::UserInterface::impl::getSidebarItems(); items.empty()) {
return false;
} else {
return std::any_of(items.begin(), items.end(), [](const auto &item) {
return std::ranges::any_of(items, [](const auto &item) {
return item.enabledCallback();
});
}
@@ -609,7 +610,7 @@ namespace hex::plugin::builtin {
bool isAnyViewOpen() {
const auto &views = ContentRegistry::Views::impl::getEntries();
return std::any_of(views.begin(), views.end(),
return std::ranges::any_of(views,
[](const auto &entry) {
return entry.second->getWindowOpenState();
});

View File

@@ -1,5 +1,6 @@
#include <hex/plugin.hpp>
#include <plugin_builtin.hpp>
#include <hex/plugin.hpp>
#include <hex/api/content_registry/settings.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/helpers/logger.hpp>
@@ -15,54 +16,6 @@
using namespace hex;
namespace hex::plugin::builtin {
void registerEventHandlers();
void registerDataVisualizers();
void registerMiniMapVisualizers();
void registerDataInspectorEntries();
void registerToolEntries();
void registerPatternLanguageFunctions();
void registerPatternLanguageTypes();
void registerPatternLanguagePragmas();
void registerPatternLanguageVisualizers();
void registerCommandPaletteCommands();
void registerSettings();
void loadSettings();
void registerDataProcessorNodes();
void registerProviders();
void registerDataFormatters();
void registerMainMenuEntries();
void createWelcomeScreen();
void registerViews();
void registerThemeHandlers();
void registerStyleHandlers();
void registerThemes();
void registerBackgroundServices();
void registerNetworkEndpoints();
void registerMCPTools();
void registerFileHandlers();
void registerProjectHandlers();
void registerAchievements();
void registerReportGenerators();
void registerTutorials();
void registerDataInformationSections();
void loadWorkspaces();
void addWindowDecoration();
void addFooterItems();
void addTitleBarButtons();
void addToolbarItems();
void addGlobalUIItems();
void addInitTasks();
void handleBorderlessWindowMode();
void setupOutOfBoxExperience();
void extractBundledFiles();
}
IMHEX_PLUGIN_SUBCOMMANDS() {
{ "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand },
{ "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand },

View File

@@ -3,14 +3,10 @@
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <regex>
#include <chrono>
#include <iostream>
#include "imgui.h"
#include "imgui_internal.h"
#include <hex/helpers/utils.hpp>
@@ -107,7 +103,7 @@ namespace hex::ui {
public:
friend class TextEditor;
bool operator==(const EditorState &o) const;
EditorState() : m_selection(), m_cursorPosition() {}
EditorState() = default;
EditorState(const Range &selection, const Coordinates &cursorPosition) : m_selection(selection), m_cursorPosition(cursorPosition) {}
private:
Range m_selection;
@@ -277,37 +273,37 @@ namespace hex::ui {
enum class LinePart { Chars, Utf8, Colors, Flags };
Line() : m_chars(""), m_colors(""), m_flags(""), m_colorized(false), m_lineMaxColumn(-1) {}
Line() : m_lineMaxColumn(-1) {}
explicit Line(const char *line) : Line(std::string(line)) {}
explicit Line(const std::string &line) : m_chars(line), m_colors(std::string(line.size(), 0x00)), m_flags(std::string(line.size(), 0x00)), m_colorized(false), m_lineMaxColumn(maxColumn()) {}
explicit Line(const std::string &line) : m_chars(line), m_colors(std::string(line.size(), 0x00)), m_flags(std::string(line.size(), 0x00)), m_lineMaxColumn(maxColumn()) {}
Line(const Line &line) : m_chars(std::string(line.m_chars)), m_colors(std::string(line.m_colors)), m_flags(std::string(line.m_flags)), m_colorized(line.m_colorized), m_lineMaxColumn(line.m_lineMaxColumn) {}
Line(Line &&line) noexcept : m_chars(std::move(line.m_chars)), m_colors(std::move(line.m_colors)), m_flags(std::move(line.m_flags)), m_colorized(line.m_colorized), m_lineMaxColumn(line.m_lineMaxColumn) {}
Line(std::string chars, std::string colors, std::string flags) : m_chars(std::move(chars)), m_colors(std::move(colors)), m_flags(std::move(flags)), m_colorized(false), m_lineMaxColumn(maxColumn()) {}
Line(std::string chars, std::string colors, std::string flags) : m_chars(std::move(chars)), m_colors(std::move(colors)), m_flags(std::move(flags)), m_lineMaxColumn(maxColumn()) {}
bool operator==(const Line &o) const;
bool operator!=(const Line &o) const;
i32 indexColumn(i32 stringIndex) const;
i32 maxColumn();
i32 maxColumn() const;
i32 columnIndex(i32 column) const;
i32 textSize() const;
i32 textSize(u32 index) const;
bool operator==(const Line &line) const;
bool operator!=(const Line &line) const;
[[nodiscard]] i32 indexColumn(i32 stringIndex) const;
[[nodiscard]] i32 maxColumn();
[[nodiscard]] i32 maxColumn() const;
[[nodiscard]] i32 columnIndex(i32 column) const;
[[nodiscard]] i32 textSize() const;
[[nodiscard]] i32 textSize(u32 index) const;
i32 lineTextSize(TrimMode trimMode = TrimMode::TrimNone);
i32 stringTextSize(const std::string &str) const;
[[nodiscard]] i32 stringTextSize(const std::string &str) const;
i32 textSizeIndex(float textSize, i32 position);
LineIterator begin() const;
LineIterator end() const;
[[nodiscard]] LineIterator begin() const;
[[nodiscard]] LineIterator end() const;
LineIterator begin();
LineIterator end();
Line &operator=(const Line &line);
Line &operator=(Line &&line) noexcept;
u64 size() const;
[[nodiscard]] u64 size() const;
TextEditor::Line trim(TrimMode trimMode);
char front(LinePart part = LinePart::Chars) const;
std::string frontUtf8(LinePart part = LinePart::Chars) const;
[[nodiscard]] char front(LinePart part = LinePart::Chars) const;
[[nodiscard]] std::string frontUtf8(LinePart part = LinePart::Chars) const;
void push_back(char c);
bool empty() const;
std::string substr(u64 start, u64 length = (u64) -1, LinePart part = LinePart::Chars) const;
[[nodiscard]] bool empty() const;
[[nodiscard]] std::string substr(u64 start, u64 length = (u64) -1, LinePart part = LinePart::Chars) const;
Line subLine(u64 start, u64 length = (u64) -1);
char operator[](u64 index) const;
// C++ can't overload functions based on return type, so use any type other
@@ -315,12 +311,12 @@ namespace hex::ui {
std::string operator[](i64 column) const;
void setNeedsUpdate(bool needsUpdate);
void append(const char *text);
void append(const char text);
void append(char text);
void append(const std::string &text);
void append(const Line &line);
void append(LineIterator begin, LineIterator end);
void insert(LineIterator iter, const std::string &text);
void insert(LineIterator iter, const char text);
void insert(LineIterator iter, char text);
void insert(LineIterator iter, strConstIter beginString, strConstIter endString);
void insert(LineIterator iter, const Line &line);
void insert(LineIterator iter, LineIterator beginLine, LineIterator endLine);
@@ -330,7 +326,7 @@ namespace hex::ui {
void clear();
void setLine(const std::string &text);
void setLine(const Line &text);
bool needsUpdate() const;
[[nodiscard]] bool needsUpdate() const;
bool isEndOfLine(i32 column);
private:
std::string m_chars;
@@ -352,14 +348,14 @@ namespace hex::ui {
Identifiers m_identifiers;
Identifiers m_preprocIdentifiers;
std::string m_singleLineComment, m_commentEnd, m_commentStart, m_globalDocComment, m_docComment, m_blockDocComment;
char m_preprocChar;
bool m_autoIndentation;
char m_preprocChar = '#';
bool m_autoIndentation = true;
TokenizeCallback m_tokenize;
TokenRegexStrings m_tokenRegexStrings;
bool m_caseSensitive;
bool m_caseSensitive = true;
LanguageDefinition() : m_name(""), m_keywords({}), m_identifiers({}), m_preprocIdentifiers({}), m_singleLineComment(""), m_commentEnd(""), m_commentStart(""), m_globalDocComment(""),
m_docComment(""), m_blockDocComment(""), m_preprocChar('#'), m_autoIndentation(true), m_tokenize(nullptr), m_tokenRegexStrings({}), m_caseSensitive(true) {}
LanguageDefinition() : m_keywords({}), m_identifiers({}), m_preprocIdentifiers({}),
m_tokenize(nullptr), m_tokenRegexStrings({}) {}
static const LanguageDefinition &CPlusPlus();
static const LanguageDefinition &HLSL();
@@ -376,12 +372,12 @@ namespace hex::ui {
class UndoRecord {
public:
friend class TextEditor;
UndoRecord() {}
UndoRecord() = default;
~UndoRecord() {}
UndoRecord( const std::string &added,
const Range addedRange,
Range addedRange,
const std::string &removed,
const Range removedRange,
Range removedRange,
EditorState &before,
EditorState &after);
@@ -398,7 +394,7 @@ namespace hex::ui {
class UndoAction {
public:
UndoAction() {}
UndoAction() = default;
~UndoAction() {}
explicit UndoAction(const UndoRecords &records) : m_records(records) {}
void undo(TextEditor *editor);
@@ -412,8 +408,8 @@ namespace hex::ui {
struct MatchedBracket {
bool m_active = false;
bool m_changed = false;
Coordinates m_nearCursor = {};
Coordinates m_matched = {};
Coordinates m_nearCursor;
Coordinates m_matched;
static const std::string s_separators;
static const std::string s_operators;
@@ -421,7 +417,7 @@ namespace hex::ui {
m_nearCursor(other.m_nearCursor),
m_matched(other.m_matched) {}
MatchedBracket() : m_active(false), m_changed(false), m_nearCursor(0, 0), m_matched(0, 0) {}
MatchedBracket() : m_nearCursor(0, 0), m_matched(0, 0) {}
MatchedBracket(bool active, bool changed, const Coordinates &nearCursor, const Coordinates &matched)
: m_active(active), m_changed(changed), m_nearCursor(nearCursor), m_matched(matched) {}
@@ -429,8 +425,8 @@ namespace hex::ui {
bool isNearABracket(TextEditor *editor, const Coordinates &from);
i32 detectDirection(TextEditor *editor, const Coordinates &from);
void findMatchingBracket(TextEditor *editor);
bool isActive() const { return m_active; }
bool hasChanged() const { return m_changed; }
[[nodiscard]] bool isActive() const { return m_active; }
[[nodiscard]] bool hasChanged() const { return m_changed; }
};
@@ -446,11 +442,11 @@ namespace hex::ui {
void setTopLine();
void render(const char *title, const ImVec2 &size = ImVec2(), bool border = false);
inline void setShowCursor(bool value) { m_showCursor = value; }
inline void setShowLineNumbers(bool value) { m_showLineNumbers = value; }
inline void setShowWhitespaces(bool value) { m_showWhitespaces = value; }
inline bool isShowingWhitespaces() const { return m_showWhitespaces; }
inline i32 getTabSize() const { return m_tabSize; }
void setShowCursor(bool value) { m_showCursor = value; }
void setShowLineNumbers(bool value) { m_showLineNumbers = value; }
void setShowWhitespaces(bool value) { m_showWhitespaces = value; }
bool isShowingWhitespaces() const { return m_showWhitespaces; }
i32 getTabSize() const { return m_tabSize; }
ImVec2 &getCharAdvance() { return m_charAdvance; }
void clearGotoBoxes() { m_errorGotoBoxes.clear(); }
void clearCursorBoxes() { m_cursorBoxes.clear(); }
@@ -461,7 +457,7 @@ namespace hex::ui {
void setLongestLineLength(u64 line) { m_longestLineLength = line; }
u64 getLongestLineLength() const { return m_longestLineLength; }
void setTopMarginChanged(i32 newMargin);
void setFocusAtCoords(const Coordinates &coords, bool ensureVisible = false);
void setFocusAtCoords(const Coordinates &coords, bool scrollToCursor = false);
void clearErrorMarkers();
void clearActionables();
private:
@@ -518,16 +514,16 @@ namespace hex::ui {
std::vector<std::string> getTextLines() const;
std::string getSelectedText();
std::string getLineText(i32 line);
inline void setTextChanged(bool value) { m_textChanged = value; }
inline bool isTextChanged() { return m_textChanged; }
inline void setReadOnly(bool value) { m_readOnly = value; }
inline void setHandleMouseInputs(bool value) { m_handleMouseInputs = value; }
inline bool isHandleMouseInputsEnabled() const { return m_handleKeyboardInputs; }
inline void setHandleKeyboardInputs(bool value) { m_handleKeyboardInputs = value; }
inline bool isHandleKeyboardInputsEnabled() const { return m_handleKeyboardInputs; }
void setTextChanged(bool value) { m_textChanged = value; }
bool isTextChanged() { return m_textChanged; }
void setReadOnly(bool value) { m_readOnly = value; }
void setHandleMouseInputs(bool value) { m_handleMouseInputs = value; }
bool isHandleMouseInputsEnabled() const { return m_handleMouseInputs; }
void setHandleKeyboardInputs(bool value) { m_handleKeyboardInputs = value; }
bool isHandleKeyboardInputsEnabled() const { return m_handleKeyboardInputs; }
private:
std::string getText(const Range &selection);
void deleteRange(const Range &selection);
std::string getText(const Range &from);
void deleteRange(const Range &rangeToDelete);
i32 insertTextAt(Coordinates &where, const std::string &value);
void removeLine(i32 start, i32 end);
void removeLine(i32 index);
@@ -575,10 +571,10 @@ namespace hex::ui {
i32 getTotalLines() const { return (i32) m_lines.size(); }
FindReplaceHandler *getFindReplaceHandler() { return &m_findReplaceHandler; }
void setSourceCodeEditor(TextEditor *editor) { m_sourceCodeEditor = editor; }
inline void clearBreakpointsChanged() { m_breakPointsChanged = false; }
inline bool isBreakpointsChanged() { return m_breakPointsChanged; }
inline void setImGuiChildIgnored(bool value) { m_ignoreImGuiChild = value; }
inline bool isImGuiChildIgnored() const { return m_ignoreImGuiChild; }
void clearBreakpointsChanged() { m_breakPointsChanged = false; }
bool isBreakpointsChanged() { return m_breakPointsChanged; }
void setImGuiChildIgnored(bool value) { m_ignoreImGuiChild = value; }
bool isImGuiChildIgnored() const { return m_ignoreImGuiChild; }
bool raiseContextMenu() { return m_raiseContextMenu; }
void clearRaiseContextMenu() { m_raiseContextMenu = false; }
TextEditor *getSourceCodeEditor();
@@ -610,7 +606,7 @@ namespace hex::ui {
private:
float m_lineSpacing = 1.0F;
Lines m_lines;
EditorState m_state = {};
EditorState m_state;
UndoBuffer m_undoBuffer;
i32 m_undoIndex = 0;
bool m_scrollToBottom = false;
@@ -638,18 +634,18 @@ namespace hex::ui {
bool m_ignoreImGuiChild = false;
bool m_showWhitespaces = true;
MatchedBracket m_matchedBracket = {};
MatchedBracket m_matchedBracket;
Palette m_palette = {};
LanguageDefinition m_languageDefinition = {};
LanguageDefinition m_languageDefinition;
RegexList m_regexList;
bool m_updateFlags = true;
Breakpoints m_breakpoints = {};
ErrorMarkers m_errorMarkers = {};
ErrorHoverBoxes m_errorHoverBoxes = {};
ErrorGotoBoxes m_errorGotoBoxes = {};
CursorBoxes m_cursorBoxes = {};
ImVec2 m_charAdvance = {};
Range m_interactiveSelection = {};
Breakpoints m_breakpoints;
ErrorMarkers m_errorMarkers;
ErrorHoverBoxes m_errorHoverBoxes;
ErrorGotoBoxes m_errorGotoBoxes;
CursorBoxes m_cursorBoxes;
ImVec2 m_charAdvance;
Range m_interactiveSelection;
u64 m_startTime = 0;
std::vector<std::string> m_defines;
TextEditor *m_sourceCodeEditor = nullptr;
@@ -663,7 +659,7 @@ namespace hex::ui {
bool m_showCursor = true;
bool m_showLineNumbers = true;
bool m_raiseContextMenu = false;
Coordinates m_focusAtCoords = {};
Coordinates m_focusAtCoords;
bool m_updateFocus = false;
std::vector<std::string> m_clickableText;

View File

@@ -250,7 +250,7 @@ namespace hex::ui {
return wolv::container::Lazy<ImGuiExt::Texture>([data = std::move(data)]() -> ImGuiExt::Texture {
if (data.empty())
return ImGuiExt::Texture();
return {};
auto texture = ImGuiExt::Texture::fromImage(data.data(), data.size(), ImGuiExt::Texture::Filter::Linear);
if (!texture.isValid()) {

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <ui/pattern_drawer.hpp>
#include <pl/core/lexer.hpp>
@@ -320,10 +321,9 @@ namespace hex::ui {
m_filteredPatterns.push_back(pattern);
} else {
auto patternValue = pattern->getValue();
if (!m_filter->inverted && (patternValue <=> *m_filter->value) == m_filter->operation) {
if (!m_filter->typeMatch || (m_filter->value->index() == patternValue.index()))
m_filteredPatterns.push_back(pattern);
} else if (m_filter->inverted && (patternValue <=> *m_filter->value) != m_filter->operation) {
auto operation = patternValue <=> *m_filter->value;
bool isOperationOk = operation == m_filter->operation;
if ((!m_filter->inverted && isOperationOk) || (m_filter->inverted && !isOperationOk)) {
if (!m_filter->typeMatch || (m_filter->value->index() == patternValue.index()))
m_filteredPatterns.push_back(pattern);
}
@@ -480,7 +480,7 @@ namespace hex::ui {
pattern = pattern->getParent();
}
std::reverse(result.begin(), result.end());
std::ranges::reverse(result);
return result;
}
@@ -1221,7 +1221,7 @@ namespace hex::ui {
if (!m_favoritesUpdateTask.isRunning()) {
sortedPatterns = patterns;
std::stable_sort(sortedPatterns.begin(), sortedPatterns.end(), [this, &sortSpecs](const std::shared_ptr<pl::ptrn::Pattern> &left, const std::shared_ptr<pl::ptrn::Pattern> &right) -> bool {
std::ranges::stable_sort(sortedPatterns, [this, &sortSpecs](const std::shared_ptr<pl::ptrn::Pattern> &left, const std::shared_ptr<pl::ptrn::Pattern> &right) -> bool {
return this->sortPatterns(sortSpecs, left.get(), right.get());
});
@@ -1365,7 +1365,7 @@ namespace hex::ui {
for (const auto &formatter : m_formatters) {
const auto name = [&]{
auto formatterName = formatter->getName();
std::transform(formatterName.begin(), formatterName.end(), formatterName.begin(), [](char c){ return char(std::toupper(c)); });
std::ranges::transform(formatterName, formatterName.begin(), [](char c){ return char(std::toupper(c)); });
return formatterName;
}();

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <ui/text_editor.hpp>
#include <algorithm>
#include <string>
@@ -21,11 +22,10 @@ namespace hex::ui {
TextEditor::TextEditor() {
m_startTime = ImGui::GetTime() * 1000;
setLanguageDefinition(LanguageDefinition::HLSL());
m_lines.push_back(Line());
m_lines.emplace_back();
}
TextEditor::~TextEditor() {
}
TextEditor::~TextEditor() = default;
std::string TextEditor::getText(const Range &from) {
std::string result;
@@ -83,7 +83,7 @@ namespace hex::ui {
m_lines[0].m_lineMaxColumn = -1;
m_lines[0].m_lineMaxColumn = m_lines[0].maxColumn();
} else {
m_lines.push_back(Line(text));
m_lines.emplace_back(text);
auto &line = m_lines.back();
line.m_lineMaxColumn = -1;
line.m_lineMaxColumn = line.maxColumn();
@@ -366,7 +366,7 @@ namespace hex::ui {
u.m_addedRange.m_start = coord;
if (m_lines.empty())
m_lines.push_back(Line());
m_lines.emplace_back();
if (character == '\n') {
insertLine(coord.m_line + 1);
@@ -426,9 +426,9 @@ namespace hex::ui {
}
u.m_addedRange.m_end = setCoordinates(m_state.m_cursorPosition);
} else {
std::string buf = "";
std::string buf;
imTextCharToUtf8(buf, character);
if (buf.size() > 0) {
if (!buf.empty()) {
auto &line = m_lines[coord.m_line];
auto charIndex = lineCoordinatesToIndex(coord);
@@ -679,7 +679,7 @@ namespace hex::ui {
if (!isEmpty()) {
std::string str;
const auto &line = m_lines[setCoordinates(m_state.m_cursorPosition).m_line];
std::copy(line.m_chars.begin(), line.m_chars.end(), std::back_inserter(str));
std::ranges::copy(line.m_chars, std::back_inserter(str));
ImGui::SetClipboardText(str.c_str());
}
}
@@ -744,7 +744,7 @@ namespace hex::ui {
const char *clipText = ImGui::GetClipboardText();
if (clipText != nullptr) {
auto stringVector = wolv::util::splitString(clipText, "\n", false);
if (std::any_of(stringVector.begin(), stringVector.end(), [](const std::string &s) { return s.size() > 1024; })) {
if (std::ranges::any_of(stringVector, [](const std::string &s) { return s.size() > 1024; })) {
ui::PopupQuestion::open("hex.builtin.view.pattern_editor.warning_paste_large"_lang, [this, clipText]() {
this->doPaste(clipText);
}, [] {});
@@ -858,8 +858,8 @@ namespace hex::ui {
}
void TextEditor::UndoAction::redo(TextEditor *editor) {
for (i32 i = 0; i < (i32) m_records.size(); i++)
m_records.at(i).redo(editor);
for (auto & m_record : m_records)
m_record.redo(editor);
}
}

View File

@@ -1,7 +1,7 @@
#include <algorithm>
#include <ui/text_editor.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/logger.hpp>
#include <algorithm>
namespace hex::ui {
extern TextEditor::Palette s_paletteBase;
@@ -25,7 +25,7 @@ namespace hex::ui {
auto &lineTokens = m_lines[line].m_colors;
if (lineTokens.size() != tokens.size()) {
lineTokens.resize(tokens.size());
std::fill(lineTokens.begin(), lineTokens.end(), 0x00);
std::ranges::fill(lineTokens, 0x00);
}
bool needsUpdate = false;
for (u64 i = 0; i < tokens.size(); ++i) {
@@ -94,10 +94,10 @@ namespace hex::ui {
// todo : almost all language definitions use lower case to specify keywords, so shouldn't this use ::tolower ?
if (!m_languageDefinition.m_caseSensitive)
std::transform(id.begin(), id.end(), id.begin(), ::toupper);
else if (m_languageDefinition.m_keywords.count(id) != 0)
std::ranges::transform(id, id.begin(), ::toupper);
else if (m_languageDefinition.m_keywords.contains(id))
token_color = PaletteIndex::Keyword;
else if (m_languageDefinition.m_identifiers.count(id) != 0)
else if (m_languageDefinition.m_identifiers.contains(id))
token_color = PaletteIndex::BuiltInType;
else if (id == "$")
token_color = PaletteIndex::GlobalVariable;
@@ -105,7 +105,7 @@ namespace hex::ui {
} else {
if ((token_color == PaletteIndex::Identifier || flags.m_bits.preprocessor) && !flags.m_bits.deactivated && !(flags.m_value & inComment)) {
id.assign(token_begin, token_end);
if (m_languageDefinition.m_preprocIdentifiers.count(id) != 0) {
if (m_languageDefinition.m_preprocIdentifiers.contains(id)) {
token_color = PaletteIndex::Directive;
token_begin -= 1;
token_length = token_end - token_begin;
@@ -125,7 +125,7 @@ namespace hex::ui {
token_color = PaletteIndex::PreprocessorDeactivated;
token_begin -= 1;
token_offset -= 1;
} else if (id.assign(token_begin, token_end);flags.m_value & inComment && m_languageDefinition.m_preprocIdentifiers.count(id) != 0) {
} else if (id.assign(token_begin, token_end);flags.m_value & inComment && m_languageDefinition.m_preprocIdentifiers.contains(id)) {
token_color = getColorIndexFromFlags(flags);
token_begin -= 1;
token_offset -= 1;
@@ -148,12 +148,12 @@ namespace hex::ui {
if (token_offset + token_length >= line.m_colors.size()) {
auto colors = line.m_colors;
line.m_colors.resize(token_offset + token_length, static_cast<char>(PaletteIndex::Default));
std::copy(colors.begin(), colors.end(), line.m_colors.begin());
std::ranges::copy(colors, line.m_colors.begin());
}
try {
line.m_colors.replace(token_offset, token_length, token_length, static_cast<char>(token_color));
} catch (const std::exception &e) {
std::cerr << "Error replacing color: " << e.what() << std::endl;
fmt::print(stderr, "Error replacing color: {}\n", e.what());
return;
}
}
@@ -184,7 +184,7 @@ namespace hex::ui {
std::vector<bool> ifDefs;
ifDefs.push_back(true);
m_defines.push_back("__IMHEX__");
m_defines.emplace_back("__IMHEX__");
for (currentLine = 0; currentLine < endLine; currentLine++) {
auto &line = m_lines[currentLine];
auto lineLength = line.size();
@@ -298,10 +298,10 @@ namespace hex::ui {
auto definesBegin = m_defines.begin();
auto definesEnd = m_defines.end();
if (directive == "define") {
if (identifier.size() > 0 && !withinNotDef && std::find(definesBegin, definesEnd, identifier) == definesEnd)
if (!identifier.empty() && !withinNotDef && std::find(definesBegin, definesEnd, identifier) == definesEnd)
m_defines.push_back(identifier);
} else if (directive == "undef") {
if (identifier.size() > 0 && !withinNotDef)
if (!identifier.empty() && !withinNotDef)
m_defines.erase(std::remove(definesBegin, definesEnd, identifier), definesEnd);
} else if (directive == "ifdef") {
if (!withinNotDef) {
@@ -407,7 +407,7 @@ namespace hex::ui {
m_regexList.clear();
for (auto &r: m_languageDefinition.m_tokenRegexStrings)
m_regexList.push_back(std::make_pair(std::regex(r.first, std::regex_constants::optimize), r.second));
m_regexList.emplace_back(std::regex(r.first, std::regex_constants::optimize), r.second);
colorize();
}
@@ -649,16 +649,16 @@ namespace hex::ui {
langDef.m_identifiers.insert(std::make_pair(std::string(k), id));
}
langDef.m_tokenRegexStrings.push_back(std::make_pair("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive));
langDef.m_tokenRegexStrings.push_back(std::make_pair("L?\\\"(\\\\.|[^\\\"])*\\\"", PaletteIndex::StringLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("\\'\\\\?[^\\']\\'", PaletteIndex::CharLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\!\\%\\^\\&\\*\\-\\+\\=\\~\\|\\<\\>\\?\\/]", PaletteIndex::Operator));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\[\\]\\{\\}\\(\\)\\;\\,\\.]", PaletteIndex::Separator));
langDef.m_tokenRegexStrings.emplace_back("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive);
langDef.m_tokenRegexStrings.emplace_back(R"(L?\"(\\.|[^\"])*\")", PaletteIndex::StringLiteral);
langDef.m_tokenRegexStrings.emplace_back(R"(\'\\?[^\']\')", PaletteIndex::CharLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier);
langDef.m_tokenRegexStrings.emplace_back(R"([\!\%\^\&\*\-\+\=\~\|\<\>\?\/])", PaletteIndex::Operator);
langDef.m_tokenRegexStrings.emplace_back(R"([\[\]\{\}\(\)\;\,\.])", PaletteIndex::Separator);
langDef.m_commentStart = "/*";
langDef.m_commentEnd = "*/";
langDef.m_singleLineComment = "//";
@@ -700,16 +700,16 @@ namespace hex::ui {
langDef.m_identifiers.insert(std::make_pair(std::string(k), id));
}
langDef.m_tokenRegexStrings.push_back(std::make_pair("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive));
langDef.m_tokenRegexStrings.push_back(std::make_pair("L?\\\"(\\\\.|[^\\\"])*\\\"", PaletteIndex::StringLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("\\'\\\\?[^\\']\\'", PaletteIndex::CharLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\!\\%\\^\\&\\*\\-\\+\\=\\~\\|\\<\\>\\?\\/]", PaletteIndex::Operator));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\[\\]\\{\\}\\(\\)\\;\\,\\.]", PaletteIndex::Separator));
langDef.m_tokenRegexStrings.emplace_back("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive);
langDef.m_tokenRegexStrings.emplace_back(R"(L?\"(\\.|[^\"])*\")", PaletteIndex::StringLiteral);
langDef.m_tokenRegexStrings.emplace_back(R"(\'\\?[^\']\')", PaletteIndex::CharLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier);
langDef.m_tokenRegexStrings.emplace_back(R"([\!\%\^\&\*\-\+\=\~\|\<\>\?\/])", PaletteIndex::Operator);
langDef.m_tokenRegexStrings.emplace_back(R"([\[\]\{\}\(\)\;\,\.])", PaletteIndex::Separator);
langDef.m_commentStart = "/*";
langDef.m_commentEnd = "*/";
langDef.m_singleLineComment = "//";
@@ -844,16 +844,16 @@ namespace hex::ui {
langDef.m_identifiers.insert(std::make_pair(std::string(k), id));
}
langDef.m_tokenRegexStrings.push_back(std::make_pair("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive));
langDef.m_tokenRegexStrings.push_back(std::make_pair("L?\\\"(\\\\.|[^\\\"])*\\\"", PaletteIndex::StringLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("\\'\\\\?[^\\']\\'", PaletteIndex::CharLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\!\\%\\^\\&\\*\\-\\+\\=\\~\\|\\<\\>\\?\\/]", PaletteIndex::Operator));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\[\\]\\{\\}\\(\\)\\;\\,\\.]", PaletteIndex::Separator));
langDef.m_tokenRegexStrings.emplace_back("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive);
langDef.m_tokenRegexStrings.emplace_back(R"(L?\"(\\.|[^\"])*\")", PaletteIndex::StringLiteral);
langDef.m_tokenRegexStrings.emplace_back(R"(\'\\?[^\']\')", PaletteIndex::CharLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier);
langDef.m_tokenRegexStrings.emplace_back(R"([\!\%\^\&\*\-\+\=\~\|\<\>\?\/])", PaletteIndex::Operator);
langDef.m_tokenRegexStrings.emplace_back(R"([\[\]\{\}\(\)\;\,\.])", PaletteIndex::Separator);
langDef.m_commentStart = "/*";
langDef.m_commentEnd = "*/";
@@ -897,16 +897,16 @@ namespace hex::ui {
langDef.m_identifiers.insert(std::make_pair(std::string(k), id));
}
langDef.m_tokenRegexStrings.push_back(std::make_pair("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive));
langDef.m_tokenRegexStrings.push_back(std::make_pair("L?\\\"(\\\\.|[^\\\"])*\\\"", PaletteIndex::StringLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("\\'\\\\?[^\\']\\'", PaletteIndex::CharLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\!\\%\\^\\&\\*\\-\\+\\=\\~\\|\\<\\>\\?\\/]", PaletteIndex::Operator));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\[\\]\\{\\}\\(\\)\\;\\,\\.]", PaletteIndex::Separator));
langDef.m_tokenRegexStrings.emplace_back("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive);
langDef.m_tokenRegexStrings.emplace_back(R"(L?\"(\\.|[^\"])*\")", PaletteIndex::StringLiteral);
langDef.m_tokenRegexStrings.emplace_back(R"(\'\\?[^\']\')", PaletteIndex::CharLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?",PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier);
langDef.m_tokenRegexStrings.emplace_back(R"([\!\%\^\&\*\-\+\=\~\|\<\>\?\/])", PaletteIndex::Operator);
langDef.m_tokenRegexStrings.emplace_back(R"([\[\]\{\}\(\)\;\,\.])", PaletteIndex::Separator);
langDef.m_commentStart = "/*";
langDef.m_commentEnd = "*/";
@@ -961,16 +961,16 @@ namespace hex::ui {
langDef.m_identifiers.insert(std::make_pair(std::string(k), id));
}
langDef.m_tokenRegexStrings.push_back(std::make_pair("[ \\t]*#[ \\t]*[a-zA-Z_]+", PaletteIndex::Directive));
langDef.m_tokenRegexStrings.push_back(std::make_pair("L?\\\"(\\\\.|[^\\\"])*\\\"", PaletteIndex::StringLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("\\'\\\\?[^\\']\\'", PaletteIndex::CharLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\!\\%\\^\\&\\*\\-\\+\\=\\~\\|\\<\\>\\?\\/]", PaletteIndex::Operator));
langDef.m_tokenRegexStrings.push_back(std::make_pair("[\\[\\]\\{\\}\\(\\)\\;\\,\\.]", PaletteIndex::Separator));
langDef.m_tokenRegexStrings.emplace_back(R"([ \t]*#[ \t]*[a-zA-Z_]+)", PaletteIndex::Directive);
langDef.m_tokenRegexStrings.emplace_back(R"(L?\"(\\.|[^\"])*\")", PaletteIndex::StringLiteral);
langDef.m_tokenRegexStrings.emplace_back(R"(\'\\?[^\']\')", PaletteIndex::CharLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[+-]?[0-9]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[0-7]+[Uu]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?", PaletteIndex::NumericLiteral);
langDef.m_tokenRegexStrings.emplace_back("[a-zA-Z_][a-zA-Z0-9_]*", PaletteIndex::Identifier);
langDef.m_tokenRegexStrings.emplace_back(R"([\!\%\^\&\*\-\+\=\~\|\<\>\?\/])", PaletteIndex::Operator);
langDef.m_tokenRegexStrings.emplace_back(R"([\[\]\{\}\(\)\;\,\.])", PaletteIndex::Separator);
langDef.m_commentStart = "--[[";
langDef.m_commentEnd = "]]";
@@ -1001,10 +1001,11 @@ namespace hex::ui {
}
// handle escape character for "
if (*p == '\\' && p + 1 < in_end && p[1] == '\\')
p++;
else if (*p == '\\' && p + 1 < in_end && p[1] == '"')
p++;
if (*p == '\\' && p + 1 < in_end) {
if (p[1] == '\\' || p[1] == '"') {
p++;
}
}
p++;
}
@@ -1169,9 +1170,9 @@ namespace hex::ui {
out_begin = in_begin;
out_end = in_begin + 1;
return true;
default:
return false;
}
return false;
}
bool tokenizeCStyleSeparator(strConstIter in_begin, strConstIter in_end, strConstIter &out_begin, strConstIter &out_end) {

View File

@@ -4,7 +4,7 @@
namespace hex::ui {
bool isWordChar(char c) {
static bool isWordChar(char c) {
auto asUChar = static_cast<u8>(c);
return std::isalnum(asUChar) || c == '_' || asUChar > 0x7F;
}
@@ -237,13 +237,13 @@ namespace hex::ui {
return;
i32 home;
if (!prefix.empty()) {
auto idx = prefix.find_first_not_of(" ");
auto idx = prefix.find_first_not_of(' ');
if (idx == std::string::npos) {
auto postIdx = postfix.find_first_of(" ");
auto postIdx = postfix.find_first_of(' ');
if (postIdx == std::string::npos || postIdx == 0)
home = 0;
else {
postIdx = postfix.find_first_not_of(" ");
postIdx = postfix.find_first_not_of(' ');
if (postIdx == std::string::npos)
home = this->lineMaxColumn(oldPos.m_line);
else if (postIdx == 0)
@@ -254,11 +254,11 @@ namespace hex::ui {
} else
home = idx;
} else {
auto postIdx = postfix.find_first_of(" ");
auto postIdx = postfix.find_first_of(' ');
if (postIdx == std::string::npos)
home = 0;
else {
postIdx = postfix.find_first_not_of(" ");
postIdx = postfix.find_first_not_of(' ');
if (postIdx == std::string::npos)
home = lineMaxColumn(oldPos.m_line);
else
@@ -360,9 +360,7 @@ namespace hex::ui {
if (std::abs(m_line) > (i32) maxLine)
return false;
auto maxColumn = editor->lineMaxColumn(m_line);
if (std::abs(m_column) > maxColumn)
return false;
return true;
return std::abs(m_column) <= maxColumn;
}
TextEditor::Coordinates TextEditor::Coordinates::sanitize(TextEditor *editor) {
@@ -387,8 +385,8 @@ namespace hex::ui {
TextEditor::Coordinates TextEditor::setCoordinates(i32 line, i32 column) {
if (isEmpty())
return Coordinates(0, 0);
return Coordinates(this, line, column);
return {0, 0};
return {this, line, column};
}
TextEditor::Coordinates TextEditor::setCoordinates(const Coordinates &value) {
@@ -400,11 +398,11 @@ namespace hex::ui {
auto start = setCoordinates(value.m_start);
auto end = setCoordinates(value.m_end);
if (start == Invalid || end == Invalid)
return Range(Invalid, Invalid);
return {Invalid, Invalid};
if (start > end) {
std::swap(start, end);
}
return Range(start, end);
return {start, end};
}
void TextEditor::advance(Coordinates &coordinates) const {

View File

@@ -453,7 +453,7 @@ namespace hex::ui {
}
}
// Draw breakpoints
if (m_breakpoints.count(lineNo + 1) != 0) {
if (m_breakpoints.contains(lineNo + 1)) {
auto end = ImVec2(lineNoStartScreenPos.x + contentSize.x + m_lineNumberFieldWidth, lineStartScreenPos.y + m_charAdvance.y);
drawList->AddRectFilled(ImVec2(position.x, lineStartScreenPos.y), end, m_palette[(i32) PaletteIndex::Breakpoint]);
@@ -501,7 +501,7 @@ namespace hex::ui {
std::string errorLineColumn;
bool found = false;
for (auto text: m_clickableText) {
if (lineText.find(text) == 0) {
if (lineText.starts_with(text)) {
errorLineColumn = lineText.substr(text.size());
if (!errorLineColumn.empty()) {
found = true;
@@ -511,7 +511,7 @@ namespace hex::ui {
}
if (found) {
i32 currLine = 0, currColumn = 0;
if (auto idx = errorLineColumn.find(":"); idx != std::string::npos) {
if (auto idx = errorLineColumn.find(':'); idx != std::string::npos) {
auto errorLine = errorLineColumn.substr(0, idx);
if (!errorLine.empty())
currLine = std::stoi(errorLine) - 1;
@@ -532,12 +532,12 @@ namespace hex::ui {
}
}
}
if (m_cursorBoxes.find(gotoKey) != m_cursorBoxes.end()) {
if (m_cursorBoxes.contains(gotoKey)) {
auto box = m_cursorBoxes[gotoKey];
if (box.trigger()) box.callback();
}
if (m_errorGotoBoxes.find(gotoKey) != m_errorGotoBoxes.end()) {
if (m_errorGotoBoxes.contains(gotoKey)) {
auto box = m_errorGotoBoxes[gotoKey];
if (box.trigger()) box.callback();
}
@@ -568,7 +568,7 @@ namespace hex::ui {
ErrorHoverBox box = ErrorHoverBox(ImRect({begin, end}), key, errorMessage.c_str());
m_errorHoverBoxes[key] = box;
}
if (m_errorHoverBoxes.find(key) != m_errorHoverBoxes.end()) {
if (m_errorHoverBoxes.contains(key)) {
auto box = m_errorHoverBoxes[key];
if (box.trigger()) box.callback();
}
@@ -626,7 +626,7 @@ namespace hex::ui {
ImVec2 TextEditor::calculateCharAdvance() const {
/* Compute mCharAdvance regarding scaled font size (Ctrl + mouse wheel)*/
const float fontSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, "#", nullptr, nullptr).x;
return ImVec2(fontSize, GImGui->FontSize * m_lineSpacing);
return {fontSize, GImGui->FontSize * m_lineSpacing};
}
float TextEditor::textDistanceToLineStart(const Coordinates &aFrom) {

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <ui/text_editor.hpp>
#include <hex/helpers/logger.hpp>
#include <algorithm>
@@ -37,11 +38,11 @@ namespace hex::ui {
}
Coordinates Coordinates::operator+(const Coordinates &o) const {
return Coordinates(m_line + o.m_line, m_column + o.m_column);
return {m_line + o.m_line, m_column + o.m_column};
}
Coordinates Coordinates::operator-(const Coordinates &o) const {
return Coordinates(m_line - o.m_line, m_column - o.m_column);
return {m_line - o.m_line, m_column - o.m_column};
}
bool Range::operator==(const Range &o) const {
@@ -52,13 +53,13 @@ namespace hex::ui {
}
Coordinates Range::getSelectedLines() {
return Coordinates(m_start.m_line, m_end.m_line);
return {m_start.m_line, m_end.m_line};
}
Coordinates Range::getSelectedColumns() {
if (isSingleLine())
return Coordinates(m_start.m_column, m_end.m_column - m_start.m_column);
return Coordinates(m_start.m_column, m_end.m_column);
return {m_start.m_column, m_end.m_column - m_start.m_column};
return {m_start.m_column, m_end.m_column};
}
bool Range::isSingleLine() {
@@ -209,14 +210,7 @@ namespace hex::ui {
return iter;
}
Line &Line::operator=(const Line &line) {
m_chars = line.m_chars;
m_colors = line.m_colors;
m_flags = line.m_flags;
m_colorized = line.m_colorized;
m_lineMaxColumn = line.m_lineMaxColumn;
return *this;
}
Line &Line::operator=(const Line &line) = default;
Line &Line::operator=(Line &&line) noexcept {
m_chars = std::move(line.m_chars);
@@ -899,11 +893,11 @@ namespace hex::ui {
std::string wordLower = m_findWord;
if (!getMatchCase())
std::transform(wordLower.begin(), wordLower.end(), wordLower.begin(), ::tolower);
std::ranges::transform(wordLower, wordLower.begin(), ::tolower);
std::string textSrc = editor->getText();
if (!getMatchCase())
std::transform(textSrc.begin(), textSrc.end(), textSrc.begin(), ::tolower);
std::ranges::transform(textSrc, textSrc.begin(), ::tolower);
u64 textLoc;
// TODO: use regexp find iterator in all cases
@@ -1010,7 +1004,6 @@ namespace hex::ui {
editor->m_state = saveState;
editor->ensureCursorVisible();
return;
}

View File

@@ -196,7 +196,7 @@ namespace hex::ui {
auto result = getCharacterCoordinates(lineNo, count - increase);
result = setCoordinates(result);
if (result == Invalid)
return Coordinates(0, 0);
return {0, 0};
return result;
}
@@ -205,7 +205,7 @@ namespace hex::ui {
return Invalid;
const auto &line = m_lines[coordinates.m_line];
return Coordinates(coordinates.m_line,line.columnIndex(coordinates.m_column));
return {coordinates.m_line,line.columnIndex(coordinates.m_column)};
}
i32 TextEditor::lineCoordinatesToIndex(const Coordinates &coordinates) const {
@@ -218,7 +218,7 @@ namespace hex::ui {
TextEditor::Coordinates TextEditor::getCharacterCoordinates(i32 lineIndex, i32 strIndex) {
if (lineIndex < 0 || lineIndex >= (i32) m_lines.size())
return Coordinates(0, 0);
return {0, 0};
auto &line = m_lines[lineIndex];
return setCoordinates(lineIndex, line.indexColumn(strIndex));
}
@@ -233,7 +233,7 @@ namespace hex::ui {
TextEditor::Coordinates TextEditor::stringIndexToCoordinates(i32 strIndex, const std::string &input) {
if (strIndex < 0 || strIndex > (i32) input.size())
return TextEditor::Coordinates(0, 0);
return {0, 0};
std::string str = input.substr(0, strIndex);
auto line = std::count(str.begin(), str.end(), '\n');
auto index = str.find_last_of('\n');