Skip to content

Commit

Permalink
Simplify the consumption of the iterator
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Cattermole <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps and adam-cattermole committed Nov 5, 2024
1 parent 7f9fb6a commit d79b574
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/data/cel/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub fn substring(This(this): This<Arc<String>>, Arguments(args): Arguments) -> R
),
})?,
};
let mut end = if count == 2 {
let end = if count == 2 {
match &args[1] {
Value::Int(i) => *i as usize,
Value::UInt(u) => *u as usize,
Expand All @@ -253,18 +253,10 @@ pub fn substring(This(this): This<Arc<String>>, Arguments(args): Arguments) -> R
message: format!("Can't have end be before the start: `{end} < {start}"),
})?
}
end -= start;
Ok(this
.chars()
.skip(start)
.take_while(|_| {
if let Some(v) = end.checked_sub(1) {
end = v;
true
} else {
false
}
})
.take(end - start)
.collect::<String>()
.into())
}
Expand Down

0 comments on commit d79b574

Please sign in to comment.