Returns the smallest possible index of the next valid UTF-8 sequence starting after `i`.
(text: &[u8], i: usize)
| 22 | /// Returns the smallest possible index of the next valid UTF-8 sequence |
| 23 | /// starting after `i`. |
| 24 | pub fn next_utf8(text: &[u8], i: usize) -> usize { |
| 25 | let b = match text.get(i) { |
| 26 | None => return i + 1, |
| 27 | Some(&b) => b, |
| 28 | }; |
| 29 | let inc = if b <= 0x7F { |
| 30 | 1 |
| 31 | } else if b <= 0b110_11111 { |
| 32 | 2 |
| 33 | } else if b <= 0b1110_1111 { |
| 34 | 3 |
| 35 | } else { |
| 36 | 4 |
| 37 | }; |
| 38 | i + inc |
| 39 | } |
| 40 | |
| 41 | /// Decode a single UTF-8 sequence into a single Unicode codepoint from `src`. |
| 42 | /// |