We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
std.ascii
toLower
toUpper
1 parent b56a667 commit 8ddce90Copy full SHA for 8ddce90
lib/std/ascii.zig
@@ -182,20 +182,14 @@ pub const isASCII = isAscii;
182
183
/// Uppercases the character and returns it as-is if already uppercase or not a letter.
184
pub fn toUpper(c: u8) u8 {
185
- if (isLower(c)) {
186
- return c & 0b11011111;
187
- } else {
188
- return c;
189
- }
+ const mask = @as(u8, @intFromBool(isLower(c))) << 5;
+ return c ^ mask;
190
}
191
192
/// Lowercases the character and returns it as-is if already lowercase or not a letter.
193
pub fn toLower(c: u8) u8 {
194
- if (isUpper(c)) {
195
- return c | 0b00100000;
196
197
198
+ const mask = @as(u8, @intFromBool(isUpper(c))) << 5;
+ return c | mask;
199
200
201
test "ASCII character classes" {
0 commit comments