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

Function strxfrm

crates/stdlib/src/locale.rs:159–171  ·  view source on GitHub ↗
(string: PyUtf8StrRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

157
158 #[pyfunction]
159 fn strxfrm(string: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult {
160 // https://github.com/python/cpython/blob/eaae563b6878aa050b4ad406b67728b6b066220e/Modules/_localemodule.c#L390-L442
161 let n1 = string.byte_len() + 1;
162 let mut buff = vec![0u8; n1];
163
164 let cstr = CString::new(string.as_str()).map_err(|e| e.to_pyexception(vm))?;
165 let n2 = unsafe { libc::strxfrm(buff.as_mut_ptr() as _, cstr.as_ptr(), n1) };
166 buff = vec![0u8; n2 + 1];
167 unsafe {
168 libc::strxfrm(buff.as_mut_ptr() as _, cstr.as_ptr(), n2 + 1);
169 }
170 Ok(vm.new_pyobj(String::from_utf8(buff).expect("strxfrm returned invalid utf-8 string")))
171 }
172
173 #[pyfunction]
174 fn localeconv(vm: &VirtualMachine) -> PyResult<PyDictRef> {

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
as_mut_ptrMethod · 0.80
new_pyobjMethod · 0.80
byte_lenMethod · 0.45
as_strMethod · 0.45
to_pyexceptionMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected