(w: &Wtf8, range: impl RangeBounds<usize>)
| 376 | } |
| 377 | |
| 378 | pub 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 | |
| 397 | pub fn get_codepoints(w: &Wtf8, range: impl RangeBounds<usize>) -> &Wtf8 { |
| 398 | try_get_codepoints(w, range).unwrap() |
no test coverage detected