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

Function adjust_indices

crates/vm/src/anystr.rs:88–106  ·  view source on GitHub ↗

help get optional string indices

(start: Option<PyIntRef>, end: Option<PyIntRef>, len: usize)

Source from the content-addressed store, hash-verified

86
87// help get optional string indices
88pub fn adjust_indices(start: Option<PyIntRef>, end: Option<PyIntRef>, len: usize) -> Range<usize> {
89 let mut start = start.map_or(0, saturate_to_isize);
90 let mut end = end.map_or(len as isize, saturate_to_isize);
91 if end > len as isize {
92 end = len as isize;
93 } else if end < 0 {
94 end += len as isize;
95 if end < 0 {
96 end = 0;
97 }
98 }
99 if start < 0 {
100 start += len as isize;
101 if start < 0 {
102 start = 0;
103 }
104 }
105 start as usize..end as usize
106}
107
108pub trait StringRange {
109 fn is_normal(&self) -> bool;

Callers 3

get_valueMethod · 0.85
get_valueMethod · 0.85
get_valueMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected