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

Function try_get_codepoints

crates/common/src/str.rs:378–395  ·  view source on GitHub ↗
(w: &Wtf8, range: impl RangeBounds<usize>)

Source from the content-addressed store, hash-verified

376}
377
378pub fn try_get_codepoints(w: &Wtf8, range: impl RangeBounds<usize>) -> Option<&Wtf8> {
379 let mut chars = w.code_points();
380 let start = match range.start_bound() {
381 Bound::Included(&i) => i,
382 Bound::Excluded(&i) => i + 1,
383 Bound::Unbounded => 0,
384 };
385 for _ in 0..start {
386 chars.next()?;
387 }
388 let s = chars.as_wtf8();
389 let range_len = match range.end_bound() {
390 Bound::Included(&i) => i + 1 - start,
391 Bound::Excluded(&i) => i - start,
392 Bound::Unbounded => return Some(s),
393 };
394 codepoint_range_end(s, range_len).map(|end| &s[..end])
395}
396
397pub fn get_codepoints(w: &Wtf8, range: impl RangeBounds<usize>) -> &Wtf8 {
398 try_get_codepoints(w, range).unwrap()

Callers 1

get_codepointsFunction · 0.85

Calls 6

codepoint_range_endFunction · 0.85
code_pointsMethod · 0.80
SomeClass · 0.50
nextMethod · 0.45
as_wtf8Method · 0.45
mapMethod · 0.45

Tested by

no test coverage detected