mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
HexEditor: Add UTF16 to the value inspector
This commit is contained in:
parent
ef113b2f91
commit
19f6ef3a0c
Notes:
sideshowbarker
2024-07-17 11:30:33 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/19f6ef3a0c Pull-request: https://github.com/SerenityOS/serenity/pull/13640 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/linusg
2 changed files with 24 additions and 1 deletions
|
@ -12,6 +12,7 @@
|
|||
#include "GoToOffsetDialog.h"
|
||||
#include "SearchResultsModel.h"
|
||||
#include "ValueInspectorModel.h"
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Applications/HexEditor/HexEditorWindowGML.h>
|
||||
|
@ -341,7 +342,19 @@ void HexEditorWidget::update_inspector_values(size_t position)
|
|||
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
|
||||
if (byte_read_count % 2 == 0) {
|
||||
Utf16View utf16_view { Span<u16 const> { reinterpret_cast<u16 const*>(&unsigned_64_bit_int), 4 } };
|
||||
size_t valid_code_units;
|
||||
utf8_view.validate(valid_code_units);
|
||||
if (valid_code_units == 0)
|
||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, "");
|
||||
else
|
||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, utf16_view.unicode_substring_view(0, 1).to_utf8());
|
||||
} else {
|
||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, "");
|
||||
}
|
||||
|
||||
// FIXME: Parse as other values like Timestamp etc
|
||||
|
||||
m_value_inspector->set_model(value_inspector_model);
|
||||
m_value_inspector->update();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Hex.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Utf16View.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Model.h>
|
||||
|
@ -28,6 +29,7 @@ public:
|
|||
Double,
|
||||
ASCII,
|
||||
UTF8,
|
||||
UTF16,
|
||||
__Count
|
||||
};
|
||||
|
||||
|
@ -96,6 +98,8 @@ public:
|
|||
return "ASCII";
|
||||
case UTF8:
|
||||
return "UTF-8";
|
||||
case UTF16:
|
||||
return "UTF-16";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
@ -137,6 +141,12 @@ public:
|
|||
return static_cast<i32>(utf8_view.byte_length());
|
||||
return 0;
|
||||
}
|
||||
case UTF16: {
|
||||
auto utf16_view = Utf16View(utf8_to_utf16(m_values.at(index.row())));
|
||||
if (utf16_view.validate())
|
||||
return static_cast<i32>(utf16_view.length_in_code_units() * 2);
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue