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

Method do_slice

crates/vm/src/builtins/str.rs:1815–1831  ·  view source on GitHub ↗
(&self, range: Range<usize>)

Source from the content-addressed store, hash-verified

1813 }
1814
1815 fn do_slice(&self, range: Range<usize>) -> Self::Sliced {
1816 match self.as_str_kind() {
1817 PyKindStr::Ascii(s) => s[range].into(),
1818 PyKindStr::Utf8(s) => {
1819 let char_len = range.len();
1820 let out = rustpython_common::str::get_chars(s, range);
1821 // SAFETY: char_len is accurate
1822 unsafe { Self::new_with_char_len(out, char_len) }
1823 }
1824 PyKindStr::Wtf8(w) => {
1825 let char_len = range.len();
1826 let out = rustpython_common::str::get_codepoints(w, range);
1827 // SAFETY: char_len is accurate
1828 unsafe { Self::new_with_char_len(out, char_len) }
1829 }
1830 }
1831 }
1832
1833 fn do_slice_reverse(&self, range: Range<usize>) -> Self::Sliced {
1834 match self.as_str_kind() {

Callers

nothing calls this directly

Calls 4

get_charsFunction · 0.85
get_codepointsFunction · 0.85
as_str_kindMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected