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

Method strip

crates/vm/src/builtins/str.rs:827–856  ·  view source on GitHub ↗
(&self, chars: OptionalOption<PyStrRef>)

Source from the content-addressed store, hash-verified

825
826 #[pymethod]
827 fn strip(&self, chars: OptionalOption<PyStrRef>) -> Self {
828 match self.as_str_kind() {
829 PyKindStr::Ascii(s) => s
830 .py_strip(
831 chars,
832 |s, chars| {
833 let s = s
834 .as_str()
835 .trim_matches(|c| memchr::memchr(c as _, chars.as_bytes()).is_some());
836 unsafe { AsciiStr::from_ascii_unchecked(s.as_bytes()) }
837 },
838 |s| s.trim(),
839 )
840 .into(),
841 PyKindStr::Utf8(s) => s
842 .py_strip(
843 chars,
844 |s, chars| s.trim_matches(|c| chars.contains(c)),
845 |s| s.trim(),
846 )
847 .into(),
848 PyKindStr::Wtf8(w) => w
849 .py_strip(
850 chars,
851 |s, chars| s.trim_matches(|c| chars.code_points().contains(&c)),
852 |s| s.trim(),
853 )
854 .into(),
855 }
856 }
857
858 #[pymethod]
859 fn lstrip(

Callers

nothing calls this directly

Calls 8

py_stripMethod · 0.80
trim_matchesMethod · 0.80
trimMethod · 0.80
code_pointsMethod · 0.80
as_str_kindMethod · 0.45
as_strMethod · 0.45
as_bytesMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected