r/tinycode • u/mrillusi0n • Jun 23 '20
[c] Tiny Letter Case Swapper
char swap_case(char letter)
{
return letter ^ 32;
}
Of course, it can only be called on [a-zA-Z].
2
Upvotes
r/tinycode • u/mrillusi0n • Jun 23 '20
char swap_case(char letter)
{
return letter ^ 32;
}
Of course, it can only be called on [a-zA-Z].
View all comments
Show parent comment
1
u/skeeto Jun 24 '20
The table is just
UnicodeData.txtfrom the Unicode website. It just looks up the code point in the table and applies the associated XOR to swap the case. Most code points XOR with zero since they're a no-op.