diff --git a/ghc/compiler/utils/FastString.lhs b/ghc/compiler/utils/FastString.lhs index c0bc7813477e4509c19ad55794e094279b827c33..b0a12b18e22748b98f2698a5b92769dde53e6934 100644 --- a/ghc/compiler/utils/FastString.lhs +++ b/ghc/compiler/utils/FastString.lhs @@ -39,6 +39,7 @@ module FastString tailFS, -- :: FastString -> FastString concatFS, -- :: [FastString] -> FastString consFS, -- :: Char -> FastString -> FastString + indexFS, -- :: FastString -> Int -> Char hPutFS -- :: Handle -> FastString -> IO () ) where @@ -176,6 +177,18 @@ headFS f@(FastString _ l# ba#) = headFS f@(CharStr a# l#) = if l# ># 0# then C# (indexCharOffAddr# a# 0#) else error ("headFS: empty FS: " ++ unpackFS f) +indexFS :: FastString -> Int -> Char +indexFS f i@(I# i#) = + case f of + FastString _ l# ba# + | l# ># 0# && l# ># i# -> C# (indexCharArray# ba# i#) + | otherwise -> error (msg (I# l#)) + CharStr a# l# + | l# ># 0# && l# ># i# -> C# (indexCharOffAddr# a# i#) + | otherwise -> error (msg (I# l#)) + where + msg l = "indexFS: out of range: " ++ show (l,i) + tailFS :: FastString -> FastString tailFS (FastString _ l# ba#) = mkFastSubStringBA# ba# 1# (l# -# 1#)