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

Function next_code_point_reverse

crates/sre_engine/src/string.rs:274–309  ·  view source on GitHub ↗
(ptr: &mut *const u8)

Source from the content-addressed store, hash-verified

272/// `bytes` must produce a valid UTF-8-like (UTF-8 or WTF-8) string
273#[inline]
274const unsafe fn next_code_point_reverse(ptr: &mut *const u8) -> u32 {
275 // Decode UTF-8
276 *ptr = unsafe { ptr.offset(-1) };
277 let w = match unsafe { **ptr } {
278 next_byte if next_byte < 128 => return next_byte as u32,
279 back_byte => back_byte,
280 };
281
282 // Multibyte case follows
283 // Decode from a byte combination out of: [x [y [z w]]]
284 let mut ch;
285 // SAFETY: `bytes` produces an UTF-8-like string,
286 // so the iterator must produce a value here.
287 *ptr = unsafe { ptr.offset(-1) };
288 let z = unsafe { **ptr };
289 ch = utf8_first_byte(z, 2);
290 if utf8_is_cont_byte(z) {
291 // SAFETY: `bytes` produces an UTF-8-like string,
292 // so the iterator must produce a value here.
293 *ptr = unsafe { ptr.offset(-1) };
294 let y = unsafe { **ptr };
295 ch = utf8_first_byte(y, 3);
296 if utf8_is_cont_byte(y) {
297 // SAFETY: `bytes` produces an UTF-8-like string,
298 // so the iterator must produce a value here.
299 *ptr = unsafe { ptr.offset(-1) };
300 let x = unsafe { **ptr };
301 ch = utf8_first_byte(x, 4);
302 ch = utf8_acc_cont_byte(ch, y);
303 }
304 ch = utf8_acc_cont_byte(ch, z);
305 }
306 ch = utf8_acc_cont_byte(ch, w);
307
308 ch
309}
310
311/// Returns the initial codepoint accumulator for the first byte.
312/// The first byte is special, only want bottom 5 bits for width 2, 4 bits

Callers 3

back_advanceMethod · 0.70
back_peekMethod · 0.70
back_skipMethod · 0.70

Calls 4

utf8_first_byteFunction · 0.70
utf8_is_cont_byteFunction · 0.70
utf8_acc_cont_byteFunction · 0.70
offsetMethod · 0.45

Tested by

no test coverage detected