diff options
author | asynts <asynts@gmail.com> | 2020-10-05 18:26:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-06 15:04:37 +0200 |
commit | aea5fff0d1750ef6c485d244672cc470394e9d33 (patch) | |
tree | 93f1934a3729f8148f3944c8c05b13b6f1e4725e /Applications/HexEditor | |
parent | c776d76b71695f64b4281ad02144c30a0844e965 (diff) | |
download | serenity-aea5fff0d1750ef6c485d244672cc470394e9d33.zip |
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.
Diffstat (limited to 'Applications/HexEditor')
-rw-r--r-- | Applications/HexEditor/HexEditor.cpp | 26 | ||||
-rw-r--r-- | Applications/HexEditor/HexEditorWidget.cpp | 14 |
2 files changed, 19 insertions, 21 deletions
diff --git a/Applications/HexEditor/HexEditor.cpp b/Applications/HexEditor/HexEditor.cpp index 45866a9558..1b4d20d385 100644 --- a/Applications/HexEditor/HexEditor.cpp +++ b/Applications/HexEditor/HexEditor.cpp @@ -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); } } } diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 3c4ff08367..f63fc88117 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -54,11 +54,11 @@ HexEditorWidget::HexEditorWidget() m_editor = add<HexEditor>(); m_editor->on_status_change = [this](int position, HexEditor::EditMode edit_mode, int selection_start, int selection_end) { - m_statusbar->set_text(0, String::format("Offset: %8X", position)); - m_statusbar->set_text(1, String::format("Edit Mode: %s", edit_mode == HexEditor::EditMode::Hex ? "Hex" : "Text")); - m_statusbar->set_text(2, String::format("Selection Start: %d", selection_start)); - m_statusbar->set_text(3, String::format("Selection End: %d", selection_end)); - m_statusbar->set_text(4, String::format("Selected Bytes: %d", abs(selection_end - selection_start) + 1)); + m_statusbar->set_text(0, String::formatted("Offset: {:#010X}", position)); + m_statusbar->set_text(1, String::formatted("Edit Mode: {}", edit_mode == HexEditor::EditMode::Hex ? "Hex" : "Text")); + m_statusbar->set_text(2, String::formatted("Selection Start: {}", selection_start)); + m_statusbar->set_text(3, String::formatted("Selection End: {}", selection_end)); + m_statusbar->set_text(4, String::formatted("Selected Bytes: {}", abs(selection_end - selection_start) + 1)); }; m_editor->on_change = [this] { @@ -126,7 +126,7 @@ HexEditorWidget::HexEditorWidget() m_document_dirty = false; set_path(LexicalPath(save_path.value())); - dbg() << "Wrote document to " << save_path.value(); + dbgln("Wrote document to {}", save_path.value()); }); auto menubar = GUI::MenuBar::construct(); @@ -227,7 +227,7 @@ void HexEditorWidget::open_file(const String& path) { auto file = Core::File::construct(path); if (!file->open(Core::IODevice::ReadOnly)) { - GUI::MessageBox::show(window(), String::format("Opening \"%s\" failed: %s", path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error); + GUI::MessageBox::show(window(), String::formatted("Opening \"{}\" failed: {}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error); return; } |