1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:57:45 +00:00

HexEditor: Find

Added search submenu with options to find or find again.
Find allows to search for ASII string or sequence of Hex value.
This commit is contained in:
Camisul 2021-01-22 23:22:00 +03:00 committed by Andreas Kling
parent 509e39ac00
commit 0678dab7dc
7 changed files with 294 additions and 1 deletions

View file

@ -582,3 +582,28 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
}
}
}
int HexEditor::find_and_highlight(ByteBuffer& needle, int start)
{
if (m_buffer.is_empty())
return -1;
if (needle.is_null()) {
dbgln("needle is null");
return -1;
}
auto raw_offset = memmem(m_buffer.data() + start, m_buffer.size(), needle.data(), needle.size());
if (raw_offset == NULL)
return -1;
int relative_offset = static_cast<const u8*>(raw_offset) - m_buffer.data();
dbgln("find_and_highlight: start={} raw_offset={} relative_offset={}", start, raw_offset, relative_offset);
auto end_of_match = relative_offset + needle;
set_position(relative_offset);
m_selection_start = relative_offset;
m_selection_end = end_of_match;
return end_of_match;
}