Skip to content

Commit

Permalink
sl-std: Extend SubsliceOffset to return full range
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed Sep 21, 2023
1 parent b1e7ea3 commit 25dad16
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sl-std/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl SubsliceOffset for str {
fn subslice_offset(&self, inner: &str) -> Option<usize> {
let outer = self.as_ptr() as usize;
let inner = inner.as_ptr() as usize;
if (outer..outer + self.len()).contains(&inner) {
if (outer..=outer + self.len()).contains(&inner) {
Some(inner.wrapping_sub(outer))
} else {
None
Expand All @@ -34,7 +34,7 @@ impl SubsliceOffset for str {
let outer = self.as_ptr() as usize;
let end = start + inner.len();

if !(outer..outer + self.len()).contains(&end) {
if outer + self.len() < end {
return None;
}

Expand Down

0 comments on commit 25dad16

Please sign in to comment.