X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FChar.hs;h=1debe79ee552b40b567b43ead79dd45caf9f9136;hb=ca42310d56e946d3e266ae89b525f1d297ce15c0;hp=505d7358e03a1b2bd11faff8696c218ce5a4d9a5;hpb=9c39b06a2f4dd90de7981af27d073e247250ab5c;p=ghc-base.git diff --git a/Data/Char.hs b/Data/Char.hs index 505d735..1debe79 100644 --- a/Data/Char.hs +++ b/Data/Char.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fno-implicit-prelude #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Char @@ -6,7 +6,7 @@ -- License : BSD-style (see the file libraries/base/LICENSE) -- -- Maintainer : libraries@haskell.org --- Stability : provisional +-- Stability : stable -- Portability : portable -- -- The Char type and associated operations. @@ -17,23 +17,33 @@ module Data.Char ( Char - , isAscii, isLatin1, isControl - , isPrint, isSpace, isUpper - , isLower, isAlpha, isDigit - , isOctDigit, isHexDigit, isAlphaNum -- :: Char -> Bool + , String + + -- * Character classification + -- | Unicode characters are divided into letters, numbers, marks, + -- punctuation, symbols, separators (including spaces) and others + -- (including control characters). + -- The full set of Unicode character attributes is not accessible + -- in this library. + , isAscii, isLatin1, isControl, isSpace + , isLower, isUpper, isAlpha, isAlphaNum, isPrint + , isDigit, isOctDigit, isHexDigit -- :: Char -> Bool + -- * Case conversion , toUpper, toLower -- :: Char -> Char + -- * Single digit characters , digitToInt -- :: Char -> Int , intToDigit -- :: Int -> Char + -- * Numeric representations , ord -- :: Char -> Int , chr -- :: Int -> Char - , readLitChar -- :: ReadS Char + + -- * String representations , showLitChar -- :: Char -> ShowS , lexLitChar -- :: ReadS String - - , String + , readLitChar -- :: ReadS Char -- Implementation checked wrt. Haskell 98 lib report, 1/99. ) where @@ -42,11 +52,27 @@ module Data.Char import GHC.Base import GHC.Show import GHC.Read (readLitChar, lexLitChar) +import GHC.Unicode +import GHC.Num #endif #ifdef __HUGS__ -import PrelImpl +import Hugs.Char +#endif -isLatin1 c = True +#ifdef __NHC__ +import Prelude +import Prelude(Char,String) +import Char #endif +-- | Convert a single digit 'Char' to the corresponding 'Int'. +-- This function fails unless its argument satisfies 'isHexDigit', +-- but recognises both upper and lower-case hexadecimal digits +-- (i.e. @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@). +digitToInt :: Char -> Int +digitToInt c + | isDigit c = ord c - ord '0' + | c >= 'a' && c <= 'f' = ord c - ord 'a' + 10 + | c >= 'A' && c <= 'F' = ord c - ord 'A' + 10 + | otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh