help get optional string indices
(start: Option<PyIntRef>, end: Option<PyIntRef>, len: usize)
| 86 | |
| 87 | // help get optional string indices |
| 88 | pub 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 | |
| 108 | pub trait StringRange { |
| 109 | fn is_normal(&self) -> bool; |