[project @ 1999-02-18 17:55:40 by simonm]
[ghc-hetmet.git] / ghc / compiler / utils / StringBuffer.lhs
index 4eca5d8..3f6bd0a 100644 (file)
@@ -1,5 +1,5 @@
 %
-% (c) The GRASP/AQUA Project, Glasgow University, 1997
+% (c) The GRASP/AQUA Project, Glasgow University, 1997-1998
 %
 \section{String buffers}
 
@@ -35,7 +35,8 @@ module StringBuffer
         stepOnUntil,      -- :: (Char -> Bool) -> StringBuffer -> StringBuffer
         stepOverLexeme,   -- :: StringBuffer   -> StringBuffer
        scanNumLit,       -- :: Int -> StringBuffer -> (Int, StringBuffer)
-        expandWhile,      -- :: (Char -> Bool) -> StringBuffer -> StringBuffer
+        expandWhile,      -- :: (Char  -> Bool) -> StringBuffer -> StringBuffer
+        expandWhile#,     -- :: (Char# -> Bool) -> StringBuffer -> StringBuffer
         expandUntilMatch, -- :: StrinBuffer -> String -> StringBuffer
          -- at or beyond end of buffer?
         bufferExhausted,  -- :: StringBuffer -> Bool
@@ -77,7 +78,7 @@ import PackBase       ( unpackCStringBA )
 #else
 # if __GLASGOW_HASKELL__ <= 302
 import PrelIOBase      ( IOError(..), IOErrorType(..) )
-import PrelHandle      ( readHandle, writeHandle )
+import PrelHandle      ( readHandle, writeHandle, filePtr )
 # endif
 import PrelPack                ( unpackCStringBA )
 #endif
@@ -113,7 +114,7 @@ hGetStringBuffer fname =
     return (StringBuffer a# read# 0# 0#)
 #else
     openFile fname ReadMode >>= \ hndl ->
-    hFileSize hndl          >>= \ len@(J# _ _ d#) ->
+    hFileSize hndl          >>= \ len ->
     let len_i = fromInteger len in
       -- Allocate an array for system call to store its bytes into.
       -- ToDo: make it robust
@@ -228,6 +229,15 @@ expandWhile pred (StringBuffer fo l# s# c#) =
         | ch# `eqChar#` '\NUL'# && c# >=# l# -> StringBuffer fo l# l# l# -- EOB, return immediately.
          | otherwise     -> StringBuffer fo l# s# c#
 
+expandWhile# :: (Char# -> Bool) -> StringBuffer -> StringBuffer
+expandWhile# pred (StringBuffer fo l# s# c#) =
+ loop c#
+  where
+   loop c# = 
+    case indexCharOffAddr# fo c# of
+     ch# | pred ch# -> loop (c# +# 1#)
+        | ch# `eqChar#` '\NUL'# && c# >=# l# -> StringBuffer fo l# s# c# -- EOB, return immediately.
+         | otherwise     -> StringBuffer fo l# s# c#
 
 scanNumLit :: Int -> StringBuffer -> (Int,StringBuffer)
 scanNumLit (I# acc#) (StringBuffer fo l# s# c#) =
@@ -236,7 +246,7 @@ scanNumLit (I# acc#) (StringBuffer fo l# s# c#) =
    loop acc# c# = 
     case indexCharOffAddr# fo c# of
      ch# | isDigit (C# ch#) -> loop (acc# *# 10# +# (ord# ch# -# ord# '0'#)) (c# +# 1#)
-        | ch# `eqChar#` '\NUL'# && c# >=# l# -> (I# acc#, StringBuffer fo l# l# l#) -- EOB, return immediately.
+        | ch# `eqChar#` '\NUL'# && c# >=# l# -> (I# acc#, StringBuffer fo l# s# c#) -- EOB, return immediately.
          | otherwise        -> (I# acc#,StringBuffer fo l# s# c#)