| 1135 | } |
| 1136 | |
| 1137 | pub fn get(&self, range: impl ops::RangeBounds<usize>) -> Option<&Self> { |
| 1138 | let start = match range.start_bound() { |
| 1139 | ops::Bound::Included(&i) => i, |
| 1140 | ops::Bound::Excluded(&i) => i.saturating_add(1), |
| 1141 | ops::Bound::Unbounded => 0, |
| 1142 | }; |
| 1143 | let end = match range.end_bound() { |
| 1144 | ops::Bound::Included(&i) => i.saturating_add(1), |
| 1145 | ops::Bound::Excluded(&i) => i, |
| 1146 | ops::Bound::Unbounded => self.len(), |
| 1147 | }; |
| 1148 | // is_code_point_boundary checks that the index is in [0, .len()] |
| 1149 | if start <= end && is_code_point_boundary(self, start) && is_code_point_boundary(self, end) |
| 1150 | { |
| 1151 | Some(unsafe { slice_unchecked(self, start, end) }) |
| 1152 | } else { |
| 1153 | None |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | pub fn ends_with(&self, w: impl AsRef<Wtf8>) -> bool { |
| 1158 | self.bytes.ends_with_str(w.as_ref()) |