1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +00:00

HexEditor: Add UTF8 to the value inspector

This commit is contained in:
kleines Filmröllchen 2022-04-12 19:00:36 +02:00 committed by Linus Groh
parent e5736cdf2f
commit ef113b2f91
2 changed files with 19 additions and 1 deletions

View file

@ -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<u8 const*>(&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();

View file

@ -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<i32>(utf8_view.byte_length());
return 0;
}
default:
return 0;
}