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

Method get_decoded_chars

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

returns str, str.char_len() (it might not be cached in the str yet but we calculate it anyway in this method)

(
            &mut self,
            n: usize,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

3928 /// returns str, str.char_len() (it might not be cached in the str yet but we calculate it
3929 /// anyway in this method)
3930 fn get_decoded_chars(
3931 &mut self,
3932 n: usize,
3933 vm: &VirtualMachine,
3934 ) -> Option<(PyStrRef, usize)> {
3935 if n == 0 {
3936 return None;
3937 }
3938 let decoded_chars = self.decoded_chars.as_ref()?;
3939 let avail = &decoded_chars.as_wtf8()[self.decoded_chars_used.bytes..];
3940 if avail.is_empty() {
3941 return None;
3942 }
3943 let avail_chars = decoded_chars.char_len() - self.decoded_chars_used.chars;
3944 let (chars, chars_used) = if n >= avail_chars {
3945 if self.decoded_chars_used.bytes == 0 {
3946 (decoded_chars.clone(), avail_chars)
3947 } else {
3948 (PyStr::from(avail).into_ref(&vm.ctx), avail_chars)
3949 }
3950 } else {
3951 let s = crate::common::str::get_codepoints(avail, 0..n);
3952 (PyStr::from(s).into_ref(&vm.ctx), n)
3953 };
3954 self.decoded_chars_used += Utf8size {
3955 bytes: chars.byte_len(),
3956 chars: chars_used,
3957 };
3958 Some((chars, chars_used))
3959 }
3960
3961 fn set_decoded_chars(&mut self, s: Option<PyStrRef>) {
3962 self.decoded_chars = s;

Callers 1

readMethod · 0.80

Calls 9

get_codepointsFunction · 0.85
SomeClass · 0.50
as_refMethod · 0.45
as_wtf8Method · 0.45
is_emptyMethod · 0.45
char_lenMethod · 0.45
cloneMethod · 0.45
into_refMethod · 0.45
byte_lenMethod · 0.45

Tested by

no test coverage detected