%
-% (c) The GRASP/AQUA Project, Glasgow University, 1997
+% (c) The GRASP/AQUA Project, Glasgow University, 1997-1998
%
\section{String buffers}
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
#else
# if __GLASGOW_HASKELL__ <= 302
import PrelIOBase ( IOError(..), IOErrorType(..) )
-import PrelHandle ( readHandle, writeHandle )
+import PrelHandle ( readHandle, writeHandle, filePtr )
# endif
import PrelPack ( unpackCStringBA )
#endif
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
| 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#) =
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#)