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

Method swapcase

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

Source from the content-addressed store, hash-verified

1039
1040 #[pymethod]
1041 fn swapcase(&self) -> Wtf8Buf {
1042 let mut swapped_str = Wtf8Buf::with_capacity(self.data.len());
1043 for c_orig in self.as_wtf8().code_points() {
1044 let c = c_orig.to_char_lossy();
1045 // to_uppercase returns an iterator, to_ascii_uppercase returns the char
1046 if c.is_lowercase() {
1047 swapped_str.push_char(c.to_ascii_uppercase());
1048 } else if c.is_uppercase() {
1049 swapped_str.push_char(c.to_ascii_lowercase());
1050 } else {
1051 swapped_str.push(c_orig);
1052 }
1053 }
1054 swapped_str
1055 }
1056
1057 #[pymethod]
1058 fn isalpha(&self) -> bool {

Callers

nothing calls this directly

Calls 10

code_pointsMethod · 0.80
to_ascii_uppercaseMethod · 0.80
to_ascii_lowercaseMethod · 0.80
lenMethod · 0.45
as_wtf8Method · 0.45
to_char_lossyMethod · 0.45
is_lowercaseMethod · 0.45
push_charMethod · 0.45
is_uppercaseMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected