diff options
author | Pascal Kuthe | 2023-07-11 12:26:11 +0000 |
---|---|---|
committer | GitHub | 2023-07-11 12:26:11 +0000 |
commit | 1adb19464f002926e1042027b41acef4c81585f6 (patch) | |
tree | 39f72c0907426f9cb0c36135cae751ac255167bf /helix-core/src/rope_reader.rs | |
parent | 541d2b76d6e5d4518e1a9d903a39738a5c08b228 (diff) |
search buffer contents during global search (#5652)
Diffstat (limited to 'helix-core/src/rope_reader.rs')
-rw-r--r-- | helix-core/src/rope_reader.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/helix-core/src/rope_reader.rs b/helix-core/src/rope_reader.rs new file mode 100644 index 00000000..20ed7bac --- /dev/null +++ b/helix-core/src/rope_reader.rs @@ -0,0 +1,37 @@ +use std::io; + +use ropey::iter::Chunks; +use ropey::RopeSlice; + +pub struct RopeReader<'a> { + current_chunk: &'a [u8], + chunks: Chunks<'a>, +} + +impl<'a> RopeReader<'a> { + pub fn new(rope: RopeSlice<'a>) -> RopeReader<'a> { + RopeReader { + current_chunk: &[], + chunks: rope.chunks(), + } + } +} + +impl io::Read for RopeReader<'_> { + fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> { + let buf_len = buf.len(); + loop { + let read_bytes = self.current_chunk.read(buf)?; + buf = &mut buf[read_bytes..]; + if buf.is_empty() { + return Ok(buf_len); + } + + if let Some(next_chunk) = self.chunks.next() { + self.current_chunk = next_chunk.as_bytes(); + } else { + return Ok(buf_len - buf.len()); + } + } + } +} |