Skip to content

Commit abca149

Browse files
toLower/toUpper for ASCII
1 parent a3e6fa4 commit abca149

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libraries/common/char.effekt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,21 @@ def isASCII(c: Char): Bool = { c.toInt < 128 }
7979
/// Checks if a given character is an ASCII lower alphabetic character
8080
def isLower(c: Char): Bool = { c >= 'a' && c <= 'z' }
8181

82+
/// Lower-cases the given ASCII character
83+
def toLower(c: Char): Char =
84+
if (c >= 'A' && c <= 'Z') {
85+
('a'.toInt + (c.toInt - 'A'.toInt)).toChar
86+
} else { c }
87+
8288
/// Checks if a given character is an ASCII upper alphabetic character
8389
def isUpper(c: Char): Bool = { c >= 'A' && c <= 'Z' }
8490

91+
/// Upper-cases the given ASCII character
92+
def toUpper(c: Char): Char =
93+
if (c >= 'a' && c <= 'z') {
94+
('A'.toInt + (c.toInt - 'a'.toInt)).toChar
95+
} else { c }
96+
8597
/// Checks if a given character is an ASCII alphabetic or numeric character
8698
def isAlphanumeric(c: Char): Bool = isDigit(c) || isLower(c) || isUpper(c)
8799

0 commit comments

Comments
 (0)