mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:57:45 +00:00
HexEditor: Replace DeprecatedString in ValueInspectorModel
This commit is contained in:
parent
4b87714700
commit
7a2ad83c07
2 changed files with 60 additions and 58 deletions
|
@ -316,13 +316,13 @@ void HexEditorWidget::update_inspector_values(size_t position)
|
||||||
else
|
else
|
||||||
unsigned_byte_value = (unsigned_64_bit_int >> (64 - 8)) & 0xFF;
|
unsigned_byte_value = (unsigned_64_bit_int >> (64 - 8)) & 0xFF;
|
||||||
|
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, DeprecatedString::number(static_cast<i8>(unsigned_byte_value)));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, String::number(static_cast<i8>(unsigned_byte_value)));
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, DeprecatedString::number(unsigned_byte_value));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, String::number(unsigned_byte_value));
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, DeprecatedString::formatted("{:c}", static_cast<char>(unsigned_byte_value)));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, String::formatted("{:c}", static_cast<char>(unsigned_byte_value)));
|
||||||
} else {
|
} else {
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, ""_string);
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, ""_string);
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, ""_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (byte_read_count >= 2) {
|
if (byte_read_count >= 2) {
|
||||||
|
@ -332,11 +332,11 @@ void HexEditorWidget::update_inspector_values(size_t position)
|
||||||
else
|
else
|
||||||
unsigned_short_value = (unsigned_64_bit_int >> (64 - 16)) & 0xFFFF;
|
unsigned_short_value = (unsigned_64_bit_int >> (64 - 16)) & 0xFFFF;
|
||||||
|
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, DeprecatedString::number(static_cast<i16>(unsigned_short_value)));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, String::number(static_cast<i16>(unsigned_short_value)));
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, DeprecatedString::number(unsigned_short_value));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, String::number(unsigned_short_value));
|
||||||
} else {
|
} else {
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, ""_string);
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, ""_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (byte_read_count >= 4) {
|
if (byte_read_count >= 4) {
|
||||||
|
@ -346,23 +346,23 @@ void HexEditorWidget::update_inspector_values(size_t position)
|
||||||
else
|
else
|
||||||
unsigned_int_value = (unsigned_64_bit_int >> 32) & 0xFFFFFFFF;
|
unsigned_int_value = (unsigned_64_bit_int >> 32) & 0xFFFFFFFF;
|
||||||
|
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, DeprecatedString::number(static_cast<i32>(unsigned_int_value)));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, String::number(static_cast<i32>(unsigned_int_value)));
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, DeprecatedString::number(unsigned_int_value));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, String::number(unsigned_int_value));
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, DeprecatedString::number(bit_cast<float>(unsigned_int_value)));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, String::number(bit_cast<float>(unsigned_int_value)));
|
||||||
} else {
|
} else {
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, ""_string);
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, ""_string);
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, ""_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (byte_read_count >= 8) {
|
if (byte_read_count >= 8) {
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, DeprecatedString::number(static_cast<i64>(unsigned_64_bit_int)));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, String::number(static_cast<i64>(unsigned_64_bit_int)));
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, DeprecatedString::number(unsigned_64_bit_int));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, String::number(unsigned_64_bit_int));
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, DeprecatedString::number(bit_cast<double>(unsigned_64_bit_int)));
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, String::number(bit_cast<double>(unsigned_64_bit_int)));
|
||||||
} else {
|
} else {
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, ""_string);
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, ""_string);
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, ""_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This probably doesn't honour endianness correctly.
|
// FIXME: This probably doesn't honour endianness correctly.
|
||||||
|
@ -370,41 +370,43 @@ void HexEditorWidget::update_inspector_values(size_t position)
|
||||||
size_t valid_bytes;
|
size_t valid_bytes;
|
||||||
utf8_view.validate(valid_bytes);
|
utf8_view.validate(valid_bytes);
|
||||||
if (valid_bytes == 0)
|
if (valid_bytes == 0)
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8, ""_string);
|
||||||
else
|
else {
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8, utf8_view.unicode_substring_view(0, 1).as_string());
|
auto utf8 = String::from_utf8(utf8_view.unicode_substring_view(0, 1).as_string());
|
||||||
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8, move(utf8));
|
||||||
|
}
|
||||||
|
|
||||||
if (byte_read_count % 2 == 0) {
|
if (byte_read_count % 2 == 0) {
|
||||||
Utf16View utf16_view { ReadonlySpan<u16> { reinterpret_cast<u16 const*>(&unsigned_64_bit_int), 4 } };
|
Utf16View utf16_view { ReadonlySpan<u16> { reinterpret_cast<u16 const*>(&unsigned_64_bit_int), 4 } };
|
||||||
size_t valid_code_units;
|
size_t valid_code_units;
|
||||||
utf16_view.validate(valid_code_units);
|
utf16_view.validate(valid_code_units);
|
||||||
if (valid_code_units == 0)
|
if (valid_code_units == 0)
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, ""_string);
|
||||||
else
|
else
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, utf16_view.unicode_substring_view(0, 1).to_deprecated_string().release_value_but_fixme_should_propagate_errors());
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, utf16_view.unicode_substring_view(0, 1).to_utf8().release_value_but_fixme_should_propagate_errors());
|
||||||
} else {
|
} else {
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, ""_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto selected_bytes = m_editor->get_selected_bytes();
|
auto selected_bytes = m_editor->get_selected_bytes();
|
||||||
|
|
||||||
auto ascii_string = DeprecatedString { ReadonlyBytes { selected_bytes } };
|
auto ascii_string = String::from_utf8(ReadonlyBytes { selected_bytes });
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCIIString, ascii_string);
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCIIString, move(ascii_string));
|
||||||
|
|
||||||
Utf8View utf8_string_view { ReadonlyBytes { selected_bytes } };
|
Utf8View utf8_string_view { ReadonlyBytes { selected_bytes } };
|
||||||
utf8_string_view.validate(valid_bytes);
|
utf8_string_view.validate(valid_bytes);
|
||||||
if (valid_bytes == 0)
|
if (valid_bytes == 0)
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, "");
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, ""_string);
|
||||||
else
|
else
|
||||||
// FIXME: replace control chars with something else - we don't want line breaks here ;)
|
// FIXME: replace control chars with something else - we don't want line breaks here ;)
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, utf8_string_view.as_string());
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, String::from_utf8(utf8_string_view.as_string()));
|
||||||
|
|
||||||
// FIXME: Parse as other values like Timestamp etc
|
// FIXME: Parse as other values like Timestamp etc
|
||||||
|
|
||||||
auto decoder = TextCodec::decoder_for(m_value_inspector_little_endian ? "utf-16le"sv : "utf-16be"sv);
|
auto decoder = TextCodec::decoder_for(m_value_inspector_little_endian ? "utf-16le"sv : "utf-16be"sv);
|
||||||
DeprecatedString utf16_string = decoder->to_utf8(StringView(selected_bytes.span())).release_value_but_fixme_should_propagate_errors().to_deprecated_string();
|
ErrorOr<String> utf16_string = decoder->to_utf8(StringView(selected_bytes.span()));
|
||||||
|
|
||||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16String, utf16_string);
|
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16String, move(utf16_string));
|
||||||
|
|
||||||
m_value_inspector->set_model(value_inspector_model);
|
m_value_inspector->set_model(value_inspector_model);
|
||||||
m_value_inspector->update();
|
m_value_inspector->update();
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Hex.h>
|
#include <AK/Hex.h>
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <AK/Utf16View.h>
|
#include <AK/Utf16View.h>
|
||||||
|
@ -45,12 +44,13 @@ public:
|
||||||
: m_is_little_endian(is_little_endian)
|
: m_is_little_endian(is_little_endian)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ValueType::__Count; i++)
|
for (int i = 0; i < ValueType::__Count; i++)
|
||||||
set_parsed_value(static_cast<ValueType>(i), "");
|
set_parsed_value(static_cast<ValueType>(i), ""_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_parsed_value(ValueType type, DeprecatedString value)
|
void set_parsed_value(ValueType type, ErrorOr<String> value)
|
||||||
{
|
{
|
||||||
m_values[type] = value;
|
if (!value.is_error())
|
||||||
|
m_values[type] = value.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override
|
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override
|
||||||
|
@ -74,43 +74,43 @@ public:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString inspector_value_type_to_deprecated_string(ValueType type) const
|
String inspector_value_type_to_string(ValueType type) const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SignedByte:
|
case SignedByte:
|
||||||
return "Signed Byte";
|
return "Signed Byte"_string;
|
||||||
case UnsignedByte:
|
case UnsignedByte:
|
||||||
return "Unsigned Byte";
|
return "Unsigned Byte"_string;
|
||||||
case SignedShort:
|
case SignedShort:
|
||||||
return "Signed Short";
|
return "Signed Short"_string;
|
||||||
case UnsignedShort:
|
case UnsignedShort:
|
||||||
return "Unsigned Short";
|
return "Unsigned Short"_string;
|
||||||
case SignedInt:
|
case SignedInt:
|
||||||
return "Signed Int";
|
return "Signed Int"_string;
|
||||||
case UnsignedInt:
|
case UnsignedInt:
|
||||||
return "Unsigned Int";
|
return "Unsigned Int"_string;
|
||||||
case SignedLong:
|
case SignedLong:
|
||||||
return "Signed Long";
|
return "Signed Long"_string;
|
||||||
case UnsignedLong:
|
case UnsignedLong:
|
||||||
return "Unsigned Long";
|
return "Unsigned Long"_string;
|
||||||
case Float:
|
case Float:
|
||||||
return "Float";
|
return "Float"_string;
|
||||||
case Double:
|
case Double:
|
||||||
return "Double";
|
return "Double"_string;
|
||||||
case ASCII:
|
case ASCII:
|
||||||
return "ASCII";
|
return "ASCII"_string;
|
||||||
case UTF8:
|
case UTF8:
|
||||||
return "UTF-8";
|
return "UTF-8"_string;
|
||||||
case UTF16:
|
case UTF16:
|
||||||
return "UTF-16";
|
return "UTF-16"_string;
|
||||||
case ASCIIString:
|
case ASCIIString:
|
||||||
return "ASCII String";
|
return "ASCII String"_string;
|
||||||
case UTF8String:
|
case UTF8String:
|
||||||
return "UTF-8 String";
|
return "UTF-8 String"_string;
|
||||||
case UTF16String:
|
case UTF16String:
|
||||||
return "UTF-16 String";
|
return "UTF-16 String"_string;
|
||||||
default:
|
default:
|
||||||
return "";
|
return ""_string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
if (role == GUI::ModelRole::Display) {
|
if (role == GUI::ModelRole::Display) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case Column::Type:
|
case Column::Type:
|
||||||
return inspector_value_type_to_deprecated_string(static_cast<ValueType>(index.row()));
|
return inspector_value_type_to_string(static_cast<ValueType>(index.row())).to_deprecated_string();
|
||||||
case Column::Value:
|
case Column::Value:
|
||||||
return m_values.at(index.row());
|
return m_values.at(index.row());
|
||||||
}
|
}
|
||||||
|
@ -165,5 +165,5 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_is_little_endian = false;
|
bool m_is_little_endian = false;
|
||||||
Array<DeprecatedString, ValueType::__Count> m_values = {};
|
Array<String, ValueType::__Count> m_values = {};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue