diff --git a/plugins/builtin/source/content/data_visualizers.cpp b/plugins/builtin/source/content/data_visualizers.cpp index 34d946910..d63a4e017 100644 --- a/plugins/builtin/source/content/data_visualizers.cpp +++ b/plugins/builtin/source/content/data_visualizers.cpp @@ -23,6 +23,19 @@ namespace hex::plugin::builtin { else static_assert(hex::always_false::value, "Invalid data type!"); } + template + constexpr const char *getFormatLengthSpecifier() { + if constexpr (std::same_as) return "hh"; + else if constexpr (std::same_as) return "h"; + else if constexpr (std::same_as) return "l"; + else if constexpr (std::same_as) return "ll"; + else if constexpr (std::same_as) return "hh"; + else if constexpr (std::same_as) return "h"; + else if constexpr (std::same_as) return "l"; + else if constexpr (std::same_as) return "ll"; + else static_assert(hex::always_false::value, "Invalid data type!"); + } + template class DataVisualizerHexadecimal : public hex::ContentRegistry::HexEditor::DataVisualizer { public: @@ -51,8 +64,8 @@ namespace hex::plugin::builtin { constexpr static inline auto ByteCount = sizeof(T); constexpr static inline auto CharCount = ByteCount * 2; - const static inline auto FormattingUpperCase = hex::format("%0{}llX", CharCount); - const static inline auto FormattingLowerCase = hex::format("%0{}llx", CharCount); + const static inline auto FormattingUpperCase = hex::format("%0{}{}X", CharCount, getFormatLengthSpecifier()); + const static inline auto FormattingLowerCase = hex::format("%0{}{}x", CharCount, getFormatLengthSpecifier()); const char *getFormatString(bool upperCase) { if (upperCase) @@ -104,8 +117,8 @@ namespace hex::plugin::builtin { constexpr static inline auto ByteCount = 1; constexpr static inline auto CharCount = ByteCount * 2; - const static inline auto FormattingUpperCase = hex::format("%0{}llX", CharCount); - const static inline auto FormattingLowerCase = hex::format("%0{}llx", CharCount); + const static inline auto FormattingUpperCase = hex::format("%0{}{}}X", CharCount, getFormatLengthSpecifier()); + const static inline auto FormattingLowerCase = hex::format("%0{}{}x", CharCount, getFormatLengthSpecifier()); static const char *getFormatString(bool upperCase) { if (upperCase) @@ -154,7 +167,7 @@ namespace hex::plugin::builtin { constexpr static inline auto ByteCount = sizeof(T); constexpr static inline auto CharCount = std::numeric_limits::digits10 + 2; - const static inline auto FormatString = hex::format("%{}{}", CharCount, std::is_signed::value ? "lld" : "llu"); + const static inline auto FormatString = hex::format("%{}{}{}", CharCount, getFormatLengthSpecifier(), std::is_signed::value ? "d" : "u"); const char *getFormatString() { return FormatString.c_str();