1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : libraries@haskell.org
10 -- Portability : portable
12 -- The Char type and associated operations.
14 -----------------------------------------------------------------------------
22 -- * Character classification
23 -- | Unicode characters are divided into letters, numbers, marks,
24 -- punctuation, symbols, separators (including spaces) and others
25 -- (including control characters).
26 -- The full set of Unicode character attributes is not accessible
28 , isAscii, isLatin1, isControl, isSpace
29 , isLower, isUpper, isAlpha, isAlphaNum, isPrint
30 , isDigit, isOctDigit, isHexDigit -- :: Char -> Bool
33 , toUpper, toLower -- :: Char -> Char
35 -- * Single digit characters
36 , digitToInt -- :: Char -> Int
37 , intToDigit -- :: Int -> Char
39 -- * Numeric representations
40 , ord -- :: Char -> Int
41 , chr -- :: Int -> Char
43 -- * String representations
44 , showLitChar -- :: Char -> ShowS
45 , lexLitChar -- :: ReadS String
46 , readLitChar -- :: ReadS Char
48 -- Implementation checked wrt. Haskell 98 lib report, 1/99.
51 #ifdef __GLASGOW_HASKELL__
54 import GHC.Read (readLitChar, lexLitChar)
65 import Prelude(Char,String)
69 -- | Convert a single digit 'Char' to the corresponding 'Int'.
70 -- This function fails unless its argument satisfies 'isHexDigit',
71 -- but recognises both upper and lower-case hexadecimal digits
72 -- (i.e. @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@).
73 digitToInt :: Char -> Int
75 | isDigit c = ord c - ord '0'
76 | c >= 'a' && c <= 'f' = ord c - ord 'a' + 10
77 | c >= 'A' && c <= 'F' = ord c - ord 'A' + 10
78 | otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh