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

Method capitalize

crates/vm/src/builtins/str.rs:731–763  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

729
730 #[pymethod]
731 fn capitalize(&self) -> Wtf8Buf {
732 match self.as_str_kind() {
733 PyKindStr::Ascii(s) => {
734 let mut s = s.to_owned();
735 if let [first, rest @ ..] = s.as_mut_slice() {
736 first.make_ascii_uppercase();
737 ascii::AsciiStr::make_ascii_lowercase(rest.into());
738 }
739 s.into()
740 }
741 PyKindStr::Utf8(s) => {
742 let mut chars = s.chars();
743 let mut out = String::with_capacity(s.len());
744 if let Some(c) = chars.next() {
745 out.extend(c.to_titlecase());
746 out.push_str(&chars.as_str().to_lowercase());
747 }
748 out.into()
749 }
750 PyKindStr::Wtf8(s) => {
751 let mut out = Wtf8Buf::with_capacity(s.len());
752 let mut chars = s.code_points();
753 if let Some(ch) = chars.next() {
754 match ch.to_char() {
755 Some(ch) => out.extend(ch.to_titlecase()),
756 None => out.push(ch),
757 }
758 out.push_wtf8(&chars.as_wtf8().to_lowercase());
759 }
760 out
761 }
762 }
763 }
764
765 #[pymethod]
766 fn split(zelf: &Py<Self>, args: SplitArgs, vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> {

Callers

nothing calls this directly

Calls 15

make_ascii_uppercaseMethod · 0.80
charsMethod · 0.80
to_lowercaseMethod · 0.80
code_pointsMethod · 0.80
push_wtf8Method · 0.80
as_str_kindMethod · 0.45
to_ownedMethod · 0.45
as_mut_sliceMethod · 0.45
lenMethod · 0.45
nextMethod · 0.45
extendMethod · 0.45
push_strMethod · 0.45

Tested by

no test coverage detected