X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FShow.lhs;h=dd931b8248799a2a67fcfb71b28b4f3ac475afd5;hb=6c656aa79cadc214c2afe8492bb90514f6ca664a;hp=9a14dae68e8f6bb42c7a9d4cd2280b178e4dd05f;hpb=260e7f2ed9a43c6ecf5a556d77817f39ed2893ab;p=ghc-base.git diff --git a/GHC/Show.lhs b/GHC/Show.lhs index 9a14dae..dd931b8 100644 --- a/GHC/Show.lhs +++ b/GHC/Show.lhs @@ -1,14 +1,18 @@ -% ------------------------------------------------------------------------------ -% $Id: Show.lhs,v 1.4 2001/12/21 15:07:25 simonmar Exp $ -% -% (c) The University of Glasgow, 1992-2000 -% - -\section{Module @GHC.Show@} - - \begin{code} {-# OPTIONS -fno-implicit-prelude #-} +----------------------------------------------------------------------------- +-- | +-- Module : GHC.Show +-- Copyright : (c) The University of Glasgow, 1992-2002 +-- License : see libraries/base/LICENSE +-- +-- Maintainer : cvs-ghc@haskell.org +-- Stability : internal +-- Portability : non-portable (GHC Extensions) +-- +-- The 'Show' class, and related operations. +-- +----------------------------------------------------------------------------- module GHC.Show ( @@ -19,7 +23,7 @@ module GHC.Show -- Show support code shows, showChar, showString, showParen, showList__, showSpace, showLitChar, protectEsc, - intToDigit, showSignedInt, + intToDigit, digitToInt, showSignedInt, -- Character operations isAscii, isLatin1, isControl, isPrint, isSpace, isUpper, @@ -34,6 +38,7 @@ module GHC.Show import {-# SOURCE #-} GHC.Err ( error ) import GHC.Base +import GHC.Enum import Data.Maybe import Data.Either import GHC.List ( (!!), break, dropWhile @@ -216,18 +221,26 @@ protectEsc :: (Char -> Bool) -> ShowS -> ShowS protectEsc p f = f . cont where cont s@(c:_) | p c = "\\&" ++ s cont s = s +\end{code} + +Code specific for Ints. +\begin{code} intToDigit :: Int -> Char intToDigit (I# i) | i >=# 0# && i <=# 9# = unsafeChr (ord '0' `plusInt` I# i) - | i >=# 10# && i <=# 15# = unsafeChr (ord 'a' `minusInt` I# 10# `plusInt` I# i) + | i >=# 10# && i <=# 15# = unsafeChr (ord 'a' `minusInt` ten `plusInt` I# i) | otherwise = error ("Char.intToDigit: not a digit " ++ show (I# i)) -\end{code} +digitToInt :: Char -> Int +digitToInt c + | isDigit c = ord c `minusInt` ord '0' + | c >= 'a' && c <= 'f' = ord c `minusInt` ord 'a' `plusInt` ten + | c >= 'A' && c <= 'F' = ord c `minusInt` ord 'A' `plusInt` ten + | otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh -Code specific for Ints. +ten = I# 10# -\begin{code} showSignedInt :: Int -> Int -> ShowS showSignedInt (I# p) (I# n) r | n <# 0# && p ># 6# = '(' : itos n (')' : r) @@ -250,6 +263,7 @@ itos n# cs itos' (n# `quotInt#` 10#) (C# c# : cs) } \end{code} + %********************************************************* %* * \subsection{Character stuff} @@ -309,7 +323,6 @@ toUpper c@(C# c#) = c - toLower c@(C# c#) | isAsciiUpper c = C# (chr# (ord# c# +# 32#)) | isAscii c = c