[project @ 2003-08-19 16:39:13 by simonmar]
[haskell-directory.git] / Data / Char.hs
1 {-# OPTIONS -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   :  provisional
10 -- Portability :  portable
11 --
12 -- The Char type and associated operations.
13 --
14 -----------------------------------------------------------------------------
15
16 module Data.Char 
17     (
18       Char
19
20     , isAscii, isLatin1, isControl
21     , isPrint, isSpace,  isUpper
22     , isLower, isAlpha,  isDigit
23     , isOctDigit, isHexDigit, isAlphaNum  -- :: Char -> Bool
24
25     , toUpper, toLower  -- :: Char -> Char
26
27     , digitToInt        -- :: Char -> Int
28     , intToDigit        -- :: Int  -> Char
29
30     , ord               -- :: Char -> Int
31     , chr               -- :: Int  -> Char
32     , readLitChar       -- :: ReadS Char 
33     , showLitChar       -- :: Char -> ShowS
34     , lexLitChar        -- :: ReadS String
35
36     , String
37
38      -- Implementation checked wrt. Haskell 98 lib report, 1/99.
39     ) where
40
41 #ifdef __GLASGOW_HASKELL__
42 import GHC.Base
43 import GHC.Show
44 import GHC.Read (readLitChar, lexLitChar)
45 import GHC.Unicode
46 import GHC.Num
47 #endif
48
49 #ifdef __HUGS__
50 import Hugs.Char
51 #endif
52
53 #ifdef __NHC__
54 import Prelude
55 import Prelude(Char,String)
56 import Char
57 #endif
58
59
60 digitToInt :: Char -> Int
61 digitToInt c
62  | isDigit c            =  ord c - ord '0'
63  | c >= 'a' && c <= 'f' =  ord c - ord 'a' + 10
64  | c >= 'A' && c <= 'F' =  ord c - ord 'A' + 10
65  | otherwise            =  error ("Char.digitToInt: not a digit " ++ show c) -- sigh