MCPcopy Index your code
hub / github.com/RustPython/RustPython / check_utf8_boundary

Function check_utf8_boundary

crates/wtf8/src/lib.rs:1308–1325  ·  view source on GitHub ↗
(slice: &Wtf8, index: usize)

Source from the content-addressed store, hash-verified

1306#[track_caller]
1307#[inline]
1308pub fn check_utf8_boundary(slice: &Wtf8, index: usize) {
1309 if index == 0 {
1310 return;
1311 }
1312 match slice.bytes.get(index) {
1313 Some(0xED) => (), // Might be a surrogate
1314 Some(&b) if (b as i8) >= -0x40 => return,
1315 Some(_) => panic!("byte index {index} is not a codepoint boundary"),
1316 None if index == slice.len() => return,
1317 None => panic!("byte index {index} is out of bounds"),
1318 }
1319 if slice.bytes[index + 1] >= 0xA0 {
1320 // There's a surrogate after index. Now check before index.
1321 if index >= 3 && slice.bytes[index - 3] == 0xED && slice.bytes[index - 2] >= 0xA0 {
1322 panic!("byte index {index} lies between surrogate codepoints");
1323 }
1324 }
1325}
1326
1327/// Copied from core::str::raw::slice_unchecked
1328///

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected