on master help sign in
Merge pull request #679 from jfdm/prelude/chars

Changes to Prelude.Char

commit3752f8e880fd09e988c366ab74bd7b3b50d63f5e authorEdwin Brady <edwin.brady@gmail.com> dateWed 27 Nov 2013, 11:56 (13 years ago) parentab67612cfe6962
1 file changed+26
libs/prelude/Prelude/Chars.idr+26
libs/prelude/Prelude/Chars.idr+26
@@ -1,43 +1,69 @@
1+-- | Functions operating over Char's
12module Prelude.Char
23
34import Builtins
45
6+-- | Return the ASCII representation of the character.
7+chr : Int -> Char
8+chr x = prim__intToChar x
9+
10+-- | Convert the number to its ASCII equivalent.
11+ord : Char -> Int
12+ord x = prim__charToInt x
13+
14+-- | Returns true if the character is in the range [A-Z].
515isUpper : Char -> Bool
616isUpper x = x >= 'A' && x <= 'Z'
717
18+-- | Returns true if the character is in the range [a-z]
819isLower : Char -> Bool
920isLower x = x >= 'a' && x <= 'z'
1021
22+-- | Returns true if the character is in the ranges [A-Z][a-z].
1123isAlpha : Char -> Bool
1224isAlpha x = isUpper x || isLower x
1325
26+-- | Returns true if the character is in the range [0-9]
1427isDigit : Char -> Bool
1528isDigit x = (x >= '0' && x <= '9')
1629
30+-- | Returns true if the character is in the ranges [A-Z][a-z][0-9]
1731isAlphaNum : Char -> Bool
1832isAlphaNum x = isDigit x || isAlpha x
1933
34+-- | Returns true if the character is a whitespace character.
2035isSpace : Char -> Bool
2136isSpace x = x == ' ' || x == '\t' || x == '\r' ||
2237 x == '\n' || x == '\f' || x == '\v' ||
2338 x == '\xa0'
2439
40+-- | Returns true if the character represents a new line.
2541isNL : Char -> Bool
2642isNL x = x == '\r' || x == '\n'
2743
44+-- | Convert a letter to the corresponding upper-case letter, if any.
45+-- Non-letters are ignored.
2846toUpper : Char -> Char
2947toUpper x = if (isLower x)
3048 then (prim__intToChar (prim__charToInt x - 32))
3149 else x
3250
51+-- | Convert a letter to the corresponding lower-case letter, if any.
52+-- Non-letters are ignored.
3353toLower : Char -> Char
3454toLower x = if (isUpper x)
3555 then (prim__intToChar (prim__charToInt x + 32))
3656 else x
3757
58+-- | Returns true if the character is a hexadecimal digit i.e. in the range [0-9][a-f][A-F]
3859isHexDigit : Char -> Bool
3960isHexDigit x = elem (toUpper x) hexChars where
4061 hexChars : List Char
4162 hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
4263 'A', 'B', 'C', 'D', 'E', 'F']
4364
65+-- | Returns true if the character is an octal digit.
66+isOctDigit : Char -> Bool
67+isOctDigit x = (x >= '0' && x <= '7')
68+
69+-- --------------------------------------------------------------------- [ EOF ]