[project @ 2005-03-14 15:22:51 by simonmar]
[ghc-base.git] / Data / Char.hs
1 {-# OPTIONS_GHC -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  Data.Char
5 -- Copyright   :  (c) The University of Glasgow 2001
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- 
8 -- Maintainer  :  libraries@haskell.org
9 -- Stability   :  stable
10 -- Portability :  portable
11 --
12 -- The Char type and associated operations.
13 --
14 -----------------------------------------------------------------------------
15
16 module Data.Char 
17     (
18       Char
19
20     , String
21
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
31
32     , GeneralCategory(..), generalCategory
33
34     -- * Case conversion
35     , toUpper, toLower, toTitle  -- :: Char -> Char
36
37     -- * Single digit characters
38     , digitToInt        -- :: Char -> Int
39     , intToDigit        -- :: Int  -> Char
40
41     -- * Numeric representations
42     , ord               -- :: Char -> Int
43     , chr               -- :: Int  -> Char
44
45     -- * String representations
46     , showLitChar       -- :: Char -> ShowS
47     , lexLitChar        -- :: ReadS String
48     , readLitChar       -- :: ReadS Char 
49
50      -- Implementation checked wrt. Haskell 98 lib report, 1/99.
51     ) where
52
53 #ifdef __GLASGOW_HASKELL__
54 import GHC.Base
55 import GHC.Show
56 import GHC.Read (readLitChar, lexLitChar)
57 import GHC.Unicode
58 import GHC.Num
59 #endif
60
61 #ifdef __HUGS__
62 import Hugs.Char
63 #endif
64
65 #ifdef __NHC__
66 import Prelude
67 import Prelude(Char,String)
68 import Char
69 #endif
70
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
76 digitToInt c
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