@@ -1,43 +1,69 @@
1+-- | Functions operating over Char's
1module Prelude.Char
2module Prelude.Char
3import Builtins
4import Builtins
6+-- | Return the ASCII representation of the character.
8+chr x = prim__intToChar x
10+-- | Convert the number to its ASCII equivalent.
12+ord x = prim__charToInt x
14+-- | Returns true if the character is in the range [A-Z].
5isUpper : Char -> Bool
15isUpper : Char -> Bool
6isUpper x = x >= 'A' && x <= 'Z'
16isUpper x = x >= 'A' && x <= 'Z'
18+-- | Returns true if the character is in the range [a-z]
8isLower : Char -> Bool
19isLower : Char -> Bool
9isLower x = x >= 'a' && x <= 'z'
20isLower x = x >= 'a' && x <= 'z'
22+-- | Returns true if the character is in the ranges [A-Z][a-z].
11isAlpha : Char -> Bool
23isAlpha : Char -> Bool
12isAlpha x = isUpper x || isLower x
24isAlpha x = isUpper x || isLower x
26+-- | Returns true if the character is in the range [0-9]
14isDigit : Char -> Bool
27isDigit : Char -> Bool
15isDigit x = (x >= '0' && x <= '9')
28isDigit x = (x >= '0' && x <= '9')
30+-- | Returns true if the character is in the ranges [A-Z][a-z][0-9]
17isAlphaNum : Char -> Bool
31isAlphaNum : Char -> Bool
18isAlphaNum x = isDigit x || isAlpha x
32isAlphaNum x = isDigit x || isAlpha x
34+-- | Returns true if the character is a whitespace character.
20isSpace : Char -> Bool
35isSpace : Char -> Bool
21isSpace x = x == ' ' || x == '\t' || x == '\r' ||
36isSpace x = x == ' ' || x == '\t' || x == '\r' ||
22 x == '\n' || x == '\f' || x == '\v' ||
37 x == '\n' || x == '\f' || x == '\v' ||
23 x == '\xa0'
38 x == '\xa0'
40+-- | Returns true if the character represents a new line.
25isNL : Char -> Bool
41isNL : Char -> Bool
26isNL x = x == '\r' || x == '\n'
42isNL x = x == '\r' || x == '\n'
44+-- | Convert a letter to the corresponding upper-case letter, if any.
45+-- Non-letters are ignored.
28toUpper : Char -> Char
46toUpper : Char -> Char
29toUpper x = if (isLower x)
47toUpper x = if (isLower x)
30 then (prim__intToChar (prim__charToInt x - 32))
48 then (prim__intToChar (prim__charToInt x - 32))
51+-- | Convert a letter to the corresponding lower-case letter, if any.
52+-- Non-letters are ignored.
33toLower : Char -> Char
53toLower : Char -> Char
34toLower x = if (isUpper x)
54toLower x = if (isUpper x)
35 then (prim__intToChar (prim__charToInt x + 32))
55 then (prim__intToChar (prim__charToInt x + 32))
58+-- | Returns true if the character is a hexadecimal digit i.e. in the range [0-9][a-f][A-F]
38isHexDigit : Char -> Bool
59isHexDigit : Char -> Bool
39isHexDigit x = elem (toUpper x) hexChars where
60isHexDigit x = elem (toUpper x) hexChars where
40 hexChars : List Char
61 hexChars : List Char
41 hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
62 hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42 'A', 'B', 'C', 'D', 'E', 'F']
63 'A', 'B', 'C', 'D', 'E', 'F']
65+-- | Returns true if the character is an octal digit.
66+isOctDigit : Char -> Bool
67+isOctDigit x = (x >= '0' && x <= '7')
69+-- --------------------------------------------------------------------- [ EOF ]