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

Function wchar_to_utf8_count

crates/vm/src/stdlib/_io.rs:6985–7019  ·  view source on GitHub ↗

Find how many UTF-8 bytes correspond to n wide chars.

(data: &[u8], mut len: usize, mut n: u32)

Source from the content-addressed store, hash-verified

6983
6984 /// Find how many UTF-8 bytes correspond to n wide chars.
6985 fn wchar_to_utf8_count(data: &[u8], mut len: usize, mut n: u32) -> usize {
6986 let mut start: usize = 0;
6987 loop {
6988 let mut mid = 0;
6989 for i in (len / 2)..=len {
6990 mid = find_last_utf8_boundary(data, i);
6991 if mid != 0 {
6992 break;
6993 }
6994 }
6995 if mid == len {
6996 return start + len;
6997 }
6998 if mid == 0 {
6999 mid = if len > 1 { len - 1 } else { 1 };
7000 }
7001 let wlen = unsafe {
7002 MultiByteToWideChar(
7003 CP_UTF8,
7004 0,
7005 data[start..].as_ptr(),
7006 mid as i32,
7007 core::ptr::null_mut(),
7008 0,
7009 )
7010 } as u32;
7011 if wlen <= n {
7012 start += mid;
7013 len -= mid;
7014 n -= wlen;
7015 } else {
7016 len = mid;
7017 }
7018 }
7019 }
7020
7021 impl Destructor for WindowsConsoleIO {
7022 fn slot_del(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<()> {

Callers 1

writeMethod · 0.85

Calls 2

find_last_utf8_boundaryFunction · 0.85
as_ptrMethod · 0.45

Tested by

no test coverage detected