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

Method title

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

Source from the content-addressed store, hash-verified

1011
1012 #[pymethod]
1013 fn title(&self) -> Wtf8Buf {
1014 let mut title = Wtf8Buf::with_capacity(self.data.len());
1015 let mut previous_is_cased = false;
1016 for c_orig in self.as_wtf8().code_points() {
1017 let c = c_orig.to_char_lossy();
1018 if c.is_lowercase() {
1019 if !previous_is_cased {
1020 title.extend(c.to_titlecase());
1021 } else {
1022 title.push_char(c);
1023 }
1024 previous_is_cased = true;
1025 } else if c.is_uppercase() || c.is_titlecase() {
1026 if previous_is_cased {
1027 title.extend(c.to_lowercase());
1028 } else {
1029 title.push_char(c);
1030 }
1031 previous_is_cased = true;
1032 } else {
1033 previous_is_cased = false;
1034 title.push(c_orig);
1035 }
1036 }
1037 title
1038 }
1039
1040 #[pymethod]
1041 fn swapcase(&self) -> Wtf8Buf {

Callers

nothing calls this directly

Calls 10

code_pointsMethod · 0.80
to_lowercaseMethod · 0.80
lenMethod · 0.45
as_wtf8Method · 0.45
to_char_lossyMethod · 0.45
is_lowercaseMethod · 0.45
extendMethod · 0.45
push_charMethod · 0.45
is_uppercaseMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected