X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FStringBuffer.lhs;h=61a0321d718aa39f1e8307a0eaa393efc4263934;hb=423d477bfecd490de1449c59325c8776f91d7aac;hp=6c5d6533bcc875a180ad2eefa2e2eae31a126907;hpb=553e90d9a32ee1b1809430f260c401cc4169c6c7;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/StringBuffer.lhs b/ghc/compiler/utils/StringBuffer.lhs index 6c5d653..61a0321 100644 --- a/ghc/compiler/utils/StringBuffer.lhs +++ b/ghc/compiler/utils/StringBuffer.lhs @@ -27,6 +27,9 @@ module StringBuffer -- * Conversion lexemeToString, -- :: StringBuffer -> Int -> String lexemeToFastString, -- :: StringBuffer -> Int -> FastString + + -- * Parsing integers + parseInteger, ) where #include "HsVersions.h" @@ -174,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}