From ef113b2f9166cedbebded18b8512b98900140090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Tue, 12 Apr 2022 19:00:36 +0200 Subject: [PATCH] HexEditor: Add UTF8 to the value inspector --- Userland/Applications/HexEditor/HexEditorWidget.cpp | 11 ++++++++++- Userland/Applications/HexEditor/ValueInspectorModel.h | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index b158939dc4..513c89d916 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -332,7 +332,16 @@ void HexEditorWidget::update_inspector_values(size_t position) value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, ""); } - // FIXME: Parse as other values like ASCII, UTF8, UTF16, Timestamp etc + // FIXME: This probably doesn't honour endianness correctly. + Utf8View utf8_view { ReadonlyBytes { reinterpret_cast(&unsigned_64_bit_int), 4 } }; + size_t valid_bytes; + utf8_view.validate(valid_bytes); + if (valid_bytes == 0) + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8, ""); + else + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8, utf8_view.unicode_substring_view(0, 1).as_string()); + + // FIXME: Parse as other values like UTF16, Timestamp etc m_value_inspector->set_model(value_inspector_model); m_value_inspector->update(); diff --git a/Userland/Applications/HexEditor/ValueInspectorModel.h b/Userland/Applications/HexEditor/ValueInspectorModel.h index 64fcbf20dc..bd77d2872c 100644 --- a/Userland/Applications/HexEditor/ValueInspectorModel.h +++ b/Userland/Applications/HexEditor/ValueInspectorModel.h @@ -27,6 +27,7 @@ public: Float, Double, ASCII, + UTF8, __Count }; @@ -93,6 +94,8 @@ public: return "Double"; case ASCII: return "ASCII"; + case UTF8: + return "UTF-8"; default: return ""; } @@ -128,6 +131,12 @@ public: case UnsignedLong: case Double: return 8; + case UTF8: { + auto utf8_view = Utf8View(m_values.at(index.row())); + if (utf8_view.validate()) + return static_cast(utf8_view.byte_length()); + return 0; + } default: return 0; }