MCPcopy Create free account
hub / github.com/davidblewett/rure-python / next_utf8

Function next_utf8

regex/src/utf8.rs:24–39  ·  view source on GitHub ↗

Returns the smallest possible index of the next valid UTF-8 sequence starting after `i`.

(text: &[u8], i: usize)

Source from the content-addressed store, hash-verified

22/// Returns the smallest possible index of the next valid UTF-8 sequence
23/// starting after `i`.
24pub 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///

Callers 1

next_after_emptyMethod · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected