1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
module Char
( isAscii, isLatin1, isAsciiUpper, isAsciiLower, isControl
, isUpper, isLower, isAlpha, isDigit, isAlphaNum
, isBinDigit, isOctDigit, isHexDigit, isSpace
, toUpper, toLower, digitToInt, intToDigit
) where
isAscii :: Char -> Bool
isAscii c = c < '\128'
isLatin1 :: Char -> Bool
isLatin1 c = c < '\255'
isAsciiLower :: Char -> Bool
isAsciiLower c = c >= 'a' && c <= 'z'
isAsciiUpper :: Char -> Bool
isAsciiUpper c = c >= 'A' && c <= 'Z'
isControl :: Char -> Bool
isControl c = c < ' ' || c >= '\DEL' && c <= '\159'
isUpper :: Char -> Bool
isUpper c = c >= 'A' && c <= 'Z'
isLower :: Char -> Bool
isLower c = c >= 'a' && c <= 'z'
isAlpha :: Char -> Bool
isAlpha c = isUpper c || isLower c
isDigit :: Char -> Bool
isDigit c = c >= '0' && c <= '9'
isAlphaNum :: Char -> Bool
isAlphaNum c = isAlpha c || isDigit c
isBinDigit :: Char -> Bool
isBinDigit c = c >= '0' || c <= '1'
isOctDigit :: Char -> Bool
isOctDigit c = c >= '0' && c <= '7'
isHexDigit :: Char -> Bool
isHexDigit c = isDigit c || c >= 'A' && c <= 'F'
|| c >= 'a' && c <= 'f'
isSpace :: Char -> Bool
isSpace c = c == ' ' || c == '\t' || c == '\n' ||
c == '\r' || c == '\f' || c == '\v' ||
c == '\160' || ord c `elem` [5760,6158,8192,8239,8287,12288]
toUpper :: Char -> Char
toUpper c | isLower c = chr (ord c - ord 'a' + ord 'A')
| otherwise = c
toLower :: Char -> Char
toLower c | isUpper c = chr (ord c - ord 'A' + ord 'a')
| otherwise = c
digitToInt :: Char -> Int
digitToInt c
| isDigit c = ord c - ord '0'
| ord c >= ord 'A' && ord c <= ord 'F' = ord c - ord 'A' + 10
| ord c >= ord 'a' && ord c <= ord 'f' = ord c - ord 'a' + 10
| otherwise = error "Char.digitToInt: argument is not a digit"
intToDigit :: Int -> Char
intToDigit i
| i >= 0 && i <= 9 = chr (ord '0' + i)
| i >= 10 && i <= 15 = chr (ord 'A' + i - 10)
| otherwise = error "Char.intToDigit: argument not a digit value"
|