MCPcopy Index your code
hub / github.com/RustPython/RustPython / try_get_chars

Function try_get_chars

crates/common/src/str.rs:343–360  ·  view source on GitHub ↗
(s: &str, range: impl RangeBounds<usize>)

Source from the content-addressed store, hash-verified

341}
342
343pub fn try_get_chars(s: &str, range: impl RangeBounds<usize>) -> Option<&str> {
344 let mut chars = s.chars();
345 let start = match range.start_bound() {
346 Bound::Included(&i) => i,
347 Bound::Excluded(&i) => i + 1,
348 Bound::Unbounded => 0,
349 };
350 for _ in 0..start {
351 chars.next()?;
352 }
353 let s = chars.as_str();
354 let range_len = match range.end_bound() {
355 Bound::Included(&i) => i + 1 - start,
356 Bound::Excluded(&i) => i - start,
357 Bound::Unbounded => return Some(s),
358 };
359 char_range_end(s, range_len).map(|end| &s[..end])
360}
361
362pub fn get_chars(s: &str, range: impl RangeBounds<usize>) -> &str {
363 try_get_chars(s, range).unwrap()

Callers 1

get_charsFunction · 0.85

Calls 6

char_range_endFunction · 0.85
charsMethod · 0.80
SomeClass · 0.50
nextMethod · 0.45
as_strMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected