From f94c23d64d33deb848c02684bd6eab4303c51262 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 26 Oct 2023 17:13:59 +0200 Subject: [PATCH] fix: Copy As -> Go Array producing syntactically invalid code Fixes #1391 --- plugins/builtin/source/content/data_formatters.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/builtin/source/content/data_formatters.cpp b/plugins/builtin/source/content/data_formatters.cpp index 7503f3805..106880768 100644 --- a/plugins/builtin/source/content/data_formatters.cpp +++ b/plugins/builtin/source/content/data_formatters.cpp @@ -8,7 +8,7 @@ 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) { + 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) { constexpr static auto NewLineIndent = "\n "; constexpr static auto LineLength = 16; @@ -31,8 +31,8 @@ namespace hex::plugin::builtin { index++; } - // Remove trailing comma - if (provider->getActualSize() > 0) { + // Remove trailing delimiter if required + if (removeFinalDelimiter && size > 0) { result.pop_back(); result.pop_back(); } @@ -79,7 +79,7 @@ namespace hex::plugin::builtin { }); ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.go", [](prv::Provider *provider, u64 offset, size_t size) { - return formatLanguageArray(provider, offset, size, "data := [...]byte {", "0x{0:02X}, ", "}"); + return formatLanguageArray(provider, offset, size, "data := [...]byte{", "0x{0:02X}, ", "}", false); }); ContentRegistry::DataFormatter::add("hex.builtin.view.hex_editor.copy.crystal", [](prv::Provider *provider, u64 offset, size_t size) {