@@ 455,19 455,19 @@ impl Document
None => return None,
};
- let mut off = match directive.direction {
+ let mut off: isize = match directive.direction {
FindDirection::All => 0,
FindDirection::Backward => {
match &self.selection {
- Some(selection) => selection.byte_range.start - 1,
+ Some(selection) => selection.byte_range.start as isize - 1,
None => 0,
}
},
FindDirection::Forward => {
match &self.selection {
- Some(selection) => selection.byte_range.end,
+ Some(selection) => selection.byte_range.end as isize,
None => 0,
}
}
@@ 482,30 482,29 @@ impl Document
FindNeedle::Text(s) => s.as_bytes(),
FindNeedle::Value(v) => v.as_slice(),
};
- let needle_len = needle_bytes.len();
+ let needle_len = needle_bytes.len() as isize;
- while off < data.len() {
- let mut bytes_checked = 0;
+ while off >= 0 && off < data.len() as isize {
+ let mut bytes_checked: isize = 0;
while bytes_checked < needle_len {
- if data[off] != needle_bytes[bytes_checked] {
+ if data[(off + bytes_checked) as usize] != needle_bytes[bytes_checked as usize] {
break;
}
bytes_checked += 1;
- off += 1;
}
if bytes_checked == needle_len {
return Some(DocumentLocation {
- byte_offset: off - bytes_checked,
+ byte_offset: off as usize,
region: match directive.needle {
FindNeedle::Value(_) => DocumentRegion::HexText,
FindNeedle::Text(_) => DocumentRegion::ASCIIText,
}
})
} else {
- off = ((off as isize) + inc) as usize;
+ off = off + inc;
}
}