X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=Data%2FChar.hs;h=2ec1e66ad4bd1fad318af3de3f87967a21b4c548;hb=0a41af38169035a4359c0c29bc1219af564dce64;hp=e0c9566f5f4246a10cf1962140f138e2c683ee38;hpb=7f1f4e7a695c402ddd3a1dc2cc7114e649a78ebc;p=ghc-base.git diff --git a/Data/Char.hs b/Data/Char.hs index e0c9566..2ec1e66 100644 --- a/Data/Char.hs +++ b/Data/Char.hs @@ -1,16 +1,14 @@ -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fno-implicit-prelude #-} ----------------------------------------------------------------------------- --- +-- | -- Module : Data.Char -- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/core/LICENSE) +-- License : BSD-style (see the file libraries/base/LICENSE) -- -- Maintainer : libraries@haskell.org --- Stability : provisional +-- Stability : stable -- Portability : portable -- --- $Id: Char.hs,v 1.1 2001/06/28 14:15:02 simonmar Exp $ --- -- The Char type and associated operations. -- ----------------------------------------------------------------------------- @@ -19,23 +17,35 @@ 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). + , isAscii, isLatin1, isControl, isSpace + , isLower, isUpper, isAlpha, isAlphaNum, isPrint + , isDigit, isOctDigit, isHexDigit + , isAsciiUpper, isAsciiLower + , isLetter, isMark, isNumber, isPunctuation, isSymbol, isSeparator - , toUpper, toLower -- :: Char -> Char + , GeneralCategory(..), generalCategory + -- * Case conversion + , toUpper, toLower, toTitle -- :: 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 @@ -43,9 +53,28 @@ module Data.Char #ifdef __GLASGOW_HASKELL__ import GHC.Base import GHC.Show -import GHC.Read (readLitChar, lexLitChar, digitToInt) +import GHC.Read (readLitChar, lexLitChar) +import GHC.Unicode +import GHC.Num #endif #ifdef __HUGS__ -isLatin1 c = True +import Hugs.Char #endif + +#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