mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
HexEditor: Use new format functions.
I changed the formatting for some numbers when it made sense, because I believe '0x00000020' to be more expressive than ' 20' for example.
This commit is contained in:
parent
c776d76b71
commit
aea5fff0d1
2 changed files with 19 additions and 21 deletions
|
@ -135,9 +135,8 @@ bool HexEditor::copy_selected_hex_to_clipboard()
|
|||
return false;
|
||||
|
||||
StringBuilder output_string_builder;
|
||||
for (int i = m_selection_start; i <= m_selection_end; i++) {
|
||||
output_string_builder.appendf("%02X ", m_buffer.data()[i]);
|
||||
}
|
||||
for (int i = m_selection_start; i <= m_selection_end; i++)
|
||||
output_string_builder.appendff("{:02X} ", m_buffer.data()[i]);
|
||||
|
||||
GUI::Clipboard::the().set_plain_text(output_string_builder.to_string());
|
||||
return true;
|
||||
|
@ -149,9 +148,8 @@ bool HexEditor::copy_selected_text_to_clipboard()
|
|||
return false;
|
||||
|
||||
StringBuilder output_string_builder;
|
||||
for (int i = m_selection_start; i <= m_selection_end; i++) {
|
||||
output_string_builder.appendf("%c", isprint(m_buffer.data()[i]) ? m_buffer[i] : '.');
|
||||
}
|
||||
for (int i = m_selection_start; i <= m_selection_end; i++)
|
||||
output_string_builder.append(isprint(m_buffer.data()[i]) ? m_buffer[i] : '.');
|
||||
|
||||
GUI::Clipboard::the().set_plain_text(output_string_builder.to_string());
|
||||
return true;
|
||||
|
@ -163,10 +161,10 @@ bool HexEditor::copy_selected_hex_to_clipboard_as_c_code()
|
|||
return false;
|
||||
|
||||
StringBuilder output_string_builder;
|
||||
output_string_builder.appendf("unsigned char raw_data[%d] = {\n", (m_selection_end - m_selection_start) + 1);
|
||||
output_string_builder.appendff("unsigned char raw_data[{}] = {{\n", (m_selection_end - m_selection_start) + 1);
|
||||
output_string_builder.append(" ");
|
||||
for (int i = m_selection_start, j = 1; i <= m_selection_end; i++, j++) {
|
||||
output_string_builder.appendf("0x%02X", m_buffer.data()[i]);
|
||||
output_string_builder.appendff("{:#04X}", m_buffer.data()[i]);
|
||||
if (i != m_selection_end)
|
||||
output_string_builder.append(", ");
|
||||
if ((j % 12) == 0) {
|
||||
|
@ -223,7 +221,7 @@ void HexEditor::mousedown_event(GUI::MouseEvent& event)
|
|||
return;
|
||||
|
||||
#ifdef HEX_DEBUG
|
||||
printf("HexEditor::mousedown_event(hex): offset=%d\n", offset);
|
||||
outln("HexEditor::mousedown_event(hex): offset={}", offset);
|
||||
#endif
|
||||
|
||||
m_edit_mode = EditMode::Hex;
|
||||
|
@ -245,7 +243,7 @@ void HexEditor::mousedown_event(GUI::MouseEvent& event)
|
|||
return;
|
||||
|
||||
#ifdef HEX_DEBUG
|
||||
printf("HexEditor::mousedown_event(text): offset=%d\n", offset);
|
||||
outln("HexEditor::mousedown_event(text): offset={}", offset);
|
||||
#endif
|
||||
|
||||
m_position = offset;
|
||||
|
@ -348,7 +346,7 @@ void HexEditor::scroll_position_into_view(int position)
|
|||
void HexEditor::keydown_event(GUI::KeyEvent& event)
|
||||
{
|
||||
#ifdef HEX_DEBUG
|
||||
printf("HexEditor::keydown_event key=%d\n", event.key());
|
||||
outln("HexEditor::keydown_event key={}", static_cast<u8>(event.key()));
|
||||
#endif
|
||||
|
||||
if (event.key() == KeyCode::Key_Up) {
|
||||
|
@ -518,7 +516,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
|||
};
|
||||
|
||||
bool is_current_line = (m_position / bytes_per_row()) == i;
|
||||
auto line = String::format("0x%08X", i * bytes_per_row());
|
||||
auto line = String::formatted("{:#010X}", i * bytes_per_row());
|
||||
painter.draw_text(
|
||||
side_offset_rect,
|
||||
line,
|
||||
|
@ -562,7 +560,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
|||
text_color = palette().inactive_selection_text();
|
||||
}
|
||||
|
||||
auto line = String::format("%02X", m_buffer[byte_position]);
|
||||
auto line = String::formatted("{:02X}", m_buffer[byte_position]);
|
||||
painter.draw_text(hex_display_rect, line, Gfx::TextAlignment::TopLeft, text_color);
|
||||
|
||||
Gfx::IntRect text_display_rect {
|
||||
|
@ -578,7 +576,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
|||
painter.fill_rect(text_display_rect, palette().inactive_selection());
|
||||
}
|
||||
|
||||
painter.draw_text(text_display_rect, String::format("%c", isprint(m_buffer[byte_position]) ? m_buffer[byte_position] : '.'), Gfx::TextAlignment::TopLeft, text_color);
|
||||
painter.draw_text(text_display_rect, String::formatted("{:c}", isprint(m_buffer[byte_position]) ? m_buffer[byte_position] : '.'), Gfx::TextAlignment::TopLeft, text_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue