1
0
mirror of synced 2025-01-10 21:41:53 +01:00

feat: Added option to copy data as escaped string

#2026
This commit is contained in:
WerWolv 2024-12-25 16:45:34 +01:00
parent 0454a369e5
commit 0be539b8a5
2 changed files with 14 additions and 5 deletions

View File

@ -797,6 +797,7 @@
"hex.builtin.view.hex_editor.copy.crystal": "Crystal Array",
"hex.builtin.view.hex_editor.copy.csharp": "C# Array",
"hex.builtin.view.hex_editor.copy.custom_encoding": "Custom Encoding",
"hex.builtin.view.hex_editor.copy.escaped_string": "Escaped String",
"hex.builtin.view.hex_editor.copy.go": "Go Array",
"hex.builtin.view.hex_editor.copy.hex_view": "Hex View",
"hex.builtin.view.hex_editor.copy.html": "HTML",

View File

@ -14,12 +14,12 @@
namespace hex::plugin::builtin {
static std::string formatLanguageArray(prv::Provider *provider, u64 offset, size_t size, const std::string &start, const std::string &byteFormat, const std::string &end, bool removeFinalDelimiter= false) {
static std::string formatLanguageArray(prv::Provider *provider, u64 offset, size_t size, const std::string &start, const std::string &byteFormat, const std::string &end, bool removeFinalDelimiter = false, bool newLines = true) {
constexpr static auto NewLineIndent = "\n ";
constexpr static auto LineLength = 16;
std::string result;
result.reserve(start.size() + hex::format(byteFormat, 0x00).size() * size + + std::string(NewLineIndent).size() / LineLength + end.size());
result.reserve(start.size() + hex::format(byteFormat, 0x00).size() * size + std::string(NewLineIndent).size() / LineLength + end.size());
result += start;
@ -29,8 +29,11 @@ namespace hex::plugin::builtin {
u64 index = 0x00;
for (u8 byte : reader) {
if ((index % LineLength) == 0x00)
result += NewLineIndent;
if (newLines) {
if ((index % LineLength) == 0x00)
result += NewLineIndent;
}
result += hex::format(byteFormat, byte);
@ -43,7 +46,8 @@ namespace hex::plugin::builtin {
result.pop_back();
}
result += "\n" + end;
if (newLines) result += "\n";
result += end;
return result;
}
@ -176,6 +180,10 @@ namespace hex::plugin::builtin {
return result;
});
ContentRegistry::DataFormatter::addExportMenuEntry("hex.builtin.view.hex_editor.copy.escaped_string", [](prv::Provider *provider, u64 offset, size_t size) {
return formatLanguageArray(provider, offset, size, "\"", "\\x{0:02X}", "\"", false, false);
});
ContentRegistry::DataFormatter::addFindExportFormatter("csv", "csv", [](const std::vector<ContentRegistry::DataFormatter::impl::FindOccurrence>& occurrences, const auto &transformFunc) {
export_fmt::ExportFormatterCsv formatter;
return formatter.format(occurrences, transformFunc);