| ... | ... | @@ -182,20 +182,14 @@ pub const isASCII = isAscii; |
| 182 | 182 | |
| 183 | 183 | /// Uppercases the character and returns it as-is if already uppercase or not a letter. |
| 184 | 184 | pub fn toUpper(c: u8) u8 { |
| 185 | | if (isLower(c)) { |
| 186 | | return c & 0b11011111; |
| 187 | | } else { |
| 188 | | return c; |
| 189 | | } |
| 185 | const mask = @as(u8, @intFromBool(isLower(c))) << 5; |
| 186 | return c ^ mask; |
| 190 | 187 | } |
| 191 | 188 | |
| 192 | 189 | /// Lowercases the character and returns it as-is if already lowercase or not a letter. |
| 193 | 190 | pub fn toLower(c: u8) u8 { |
| 194 | | if (isUpper(c)) { |
| 195 | | return c | 0b00100000; |
| 196 | | } else { |
| 197 | | return c; |
| 198 | | } |
| 191 | const mask = @as(u8, @intFromBool(isUpper(c))) << 5; |
| 192 | return c | mask; |
| 199 | 193 | } |
| 200 | 194 | |
| 201 | 195 | test "ASCII character classes" { |