Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,11 @@ impl PyStr {
let mut swapped_str = Wtf8Buf::with_capacity(self.data.len());
for c_orig in self.as_wtf8().code_points() {
let c = c_orig.to_char_lossy();
// to_uppercase returns an iterator, to_ascii_uppercase returns the char
// to_uppercase returns an iterator because case changes may be multiple bytes
if c.is_lowercase() {
swapped_str.push_char(c.to_ascii_uppercase());
swapped_str.extend(c.to_uppercase());
} else if c.is_uppercase() {
swapped_str.push_char(c.to_ascii_lowercase());
swapped_str.extend(c.to_lowercase());
} else {
swapped_str.push(c_orig);
}
Expand Down
2 changes: 2 additions & 0 deletions extra_tests/snippets/builtin_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@
assert not "😂".isidentifier()
assert not "123".isidentifier()

assert "Σίσυφος".swapcase() == "σΊΣΥΦΟΣ"

# String Formatting
assert "{} {}".format(1, 2) == "1 2"
assert "{0} {1}".format(2, 3) == "2 3"
Expand Down
Loading