X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FStringBuffer.lhs;h=61a0321d718aa39f1e8307a0eaa393efc4263934;hb=423d477bfecd490de1449c59325c8776f91d7aac;hp=1a7020ba9a7b946c621f6171c093f950f23f381b;hpb=98744cef7b82e7eefbb1c6f1d8b9e28c415939c4;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/StringBuffer.lhs b/ghc/compiler/utils/StringBuffer.lhs index 1a7020b..61a0321 100644 --- a/ghc/compiler/utils/StringBuffer.lhs +++ b/ghc/compiler/utils/StringBuffer.lhs @@ -8,7 +8,8 @@ Buffers for scanning string input stored in external arrays. \begin{code} module StringBuffer ( - StringBuffer, + StringBuffer(..), + -- non-abstract for vs/HaskellService -- * Creation/destruction hGetStringBuffer, -- :: FilePath -> IO StringBuffer @@ -26,6 +27,9 @@ module StringBuffer -- * Conversion lexemeToString, -- :: StringBuffer -> Int -> String lexemeToFastString, -- :: StringBuffer -> Int -> FastString + + -- * Parsing integers + parseInteger, ) where #include "HsVersions.h" @@ -97,7 +101,7 @@ hGetStringBuffer fname = do r <- hGetBufBA h arr size_i #else arr <- newArray_ (0,size_i-1) - r <- hGetArray h arr size_i + r <- if size_i == 0 then return 0 else hGetArray h arr size_i #endif if (r /= size_i) then ioError (userError "short read of file") @@ -173,4 +177,13 @@ lexemeToFastString :: StringBuffer -> Int -> FastString lexemeToFastString _ 0 = mkFastString "" lexemeToFastString (StringBuffer fo _ current#) (I# len) = mkFastSubStringBA# fo current# len + +-- ----------------------------------------------------------------------------- +-- Parsing integer strings in various bases + +parseInteger :: StringBuffer -> Int -> Integer -> (Char->Int) -> Integer +parseInteger buf len radix to_int + = go 0 0 + where go i x | i == len = x + | otherwise = go (i+1) (x * radix + toInteger (to_int (lookAhead buf i))) \end{code}