diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index e9b7b06cb93..7f6c1936b1e 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -316,13 +316,13 @@ void HexEditorWidget::update_inspector_values(size_t position) else unsigned_byte_value = (unsigned_64_bit_int >> (64 - 8)) & 0xFF; - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, DeprecatedString::number(static_cast(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::ASCII, DeprecatedString::formatted("{:c}", static_cast(unsigned_byte_value))); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, String::number(static_cast(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, String::formatted("{:c}", static_cast(unsigned_byte_value))); } else { - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, ""); - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, ""); - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, ""); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedByte, ""_string); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedByte, ""_string); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCII, ""_string); } if (byte_read_count >= 2) { @@ -332,11 +332,11 @@ void HexEditorWidget::update_inspector_values(size_t position) else unsigned_short_value = (unsigned_64_bit_int >> (64 - 16)) & 0xFFFF; - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, DeprecatedString::number(static_cast(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::SignedShort, String::number(static_cast(unsigned_short_value))); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, String::number(unsigned_short_value)); } else { - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, ""); - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, ""); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedShort, ""_string); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedShort, ""_string); } if (byte_read_count >= 4) { @@ -346,23 +346,23 @@ void HexEditorWidget::update_inspector_values(size_t position) else unsigned_int_value = (unsigned_64_bit_int >> 32) & 0xFFFFFFFF; - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, DeprecatedString::number(static_cast(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::Float, DeprecatedString::number(bit_cast(unsigned_int_value))); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, String::number(static_cast(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, String::number(bit_cast(unsigned_int_value))); } else { - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, ""); - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, ""); - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, ""); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedInt, ""_string); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedInt, ""_string); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Float, ""_string); } if (byte_read_count >= 8) { - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, DeprecatedString::number(static_cast(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::Double, DeprecatedString::number(bit_cast(unsigned_64_bit_int))); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, String::number(static_cast(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, String::number(bit_cast(unsigned_64_bit_int))); } else { - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, ""); - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, ""); - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, ""); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::SignedLong, ""_string); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UnsignedLong, ""_string); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::Double, ""_string); } // FIXME: This probably doesn't honour endianness correctly. @@ -370,41 +370,43 @@ void HexEditorWidget::update_inspector_values(size_t position) 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()); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8, ""_string); + else { + 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) { Utf16View utf16_view { ReadonlySpan { reinterpret_cast(&unsigned_64_bit_int), 4 } }; size_t valid_code_units; utf16_view.validate(valid_code_units); 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 - 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 { - 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 ascii_string = DeprecatedString { ReadonlyBytes { selected_bytes } }; - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCIIString, ascii_string); + auto ascii_string = String::from_utf8(ReadonlyBytes { selected_bytes }); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCIIString, move(ascii_string)); Utf8View utf8_string_view { ReadonlyBytes { selected_bytes } }; utf8_string_view.validate(valid_bytes); if (valid_bytes == 0) - value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, ""); + value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, ""_string); else // 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 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 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->update(); diff --git a/Userland/Applications/HexEditor/ValueInspectorModel.h b/Userland/Applications/HexEditor/ValueInspectorModel.h index 58550e7b03c..da5f0ebf213 100644 --- a/Userland/Applications/HexEditor/ValueInspectorModel.h +++ b/Userland/Applications/HexEditor/ValueInspectorModel.h @@ -6,7 +6,6 @@ #pragma once -#include #include #include #include @@ -45,12 +44,13 @@ public: : m_is_little_endian(is_little_endian) { for (int i = 0; i < ValueType::__Count; i++) - set_parsed_value(static_cast(i), ""); + set_parsed_value(static_cast(i), ""_string); } - void set_parsed_value(ValueType type, DeprecatedString value) + void set_parsed_value(ValueType type, ErrorOr 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 @@ -74,43 +74,43 @@ public: VERIFY_NOT_REACHED(); } - DeprecatedString inspector_value_type_to_deprecated_string(ValueType type) const + String inspector_value_type_to_string(ValueType type) const { switch (type) { case SignedByte: - return "Signed Byte"; + return "Signed Byte"_string; case UnsignedByte: - return "Unsigned Byte"; + return "Unsigned Byte"_string; case SignedShort: - return "Signed Short"; + return "Signed Short"_string; case UnsignedShort: - return "Unsigned Short"; + return "Unsigned Short"_string; case SignedInt: - return "Signed Int"; + return "Signed Int"_string; case UnsignedInt: - return "Unsigned Int"; + return "Unsigned Int"_string; case SignedLong: - return "Signed Long"; + return "Signed Long"_string; case UnsignedLong: - return "Unsigned Long"; + return "Unsigned Long"_string; case Float: - return "Float"; + return "Float"_string; case Double: - return "Double"; + return "Double"_string; case ASCII: - return "ASCII"; + return "ASCII"_string; case UTF8: - return "UTF-8"; + return "UTF-8"_string; case UTF16: - return "UTF-16"; + return "UTF-16"_string; case ASCIIString: - return "ASCII String"; + return "ASCII String"_string; case UTF8String: - return "UTF-8 String"; + return "UTF-8 String"_string; case UTF16String: - return "UTF-16 String"; + return "UTF-16 String"_string; default: - return ""; + return ""_string; } } @@ -121,7 +121,7 @@ public: if (role == GUI::ModelRole::Display) { switch (index.column()) { case Column::Type: - return inspector_value_type_to_deprecated_string(static_cast(index.row())); + return inspector_value_type_to_string(static_cast(index.row())).to_deprecated_string(); case Column::Value: return m_values.at(index.row()); } @@ -165,5 +165,5 @@ public: private: bool m_is_little_endian = false; - Array m_values = {}; + Array m_values = {}; };