1 {-# OPTIONS_GHC -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 , isAscii, isLatin1, isControl, isSpace
27 , isLower, isUpper, isAlpha, isAlphaNum, isPrint
28 , isDigit, isOctDigit, isHexDigit
29 , isAsciiUpper, isAsciiLower
30 , isLetter, isMark, isNumber, isPunctuation, isSymbol, isSeparator
32 , GeneralCategory(..), generalCategory
35 , toUpper, toLower, toTitle -- :: Char -> Char
37 -- * Single digit characters
38 , digitToInt -- :: Char -> Int
39 , intToDigit -- :: Int -> Char
41 -- * Numeric representations
42 , ord -- :: Char -> Int
43 , chr -- :: Int -> Char
45 -- * String representations
46 , showLitChar -- :: Char -> ShowS
47 , lexLitChar -- :: ReadS String
48 , readLitChar -- :: ReadS Char
50 -- Implementation checked wrt. Haskell 98 lib report, 1/99.
53 #ifdef __GLASGOW_HASKELL__
56 import GHC.Read (readLitChar, lexLitChar)
67 import Prelude(Char,String)
71 -- | Convert a single digit 'Char' to the corresponding 'Int'.
72 -- This function fails unless its argument satisfies 'isHexDigit',
73 -- but recognises both upper and lower-case hexadecimal digits
74 -- (i.e. @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@).
75 digitToInt :: Char -> Int
77 | isDigit c = ord c - ord '0'
78 | c >= 'a' && c <= 'f' = ord c - ord 'a' + 10
79 | c >= 'A' && c <= 'F' = ord c - ord 'A' + 10
80 | otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh