Changeset 11937 for third-party
- Timestamp:
- 08/06/06 07:55:48 (2 years ago)
- Location:
- third-party/fps
- Files:
-
- 8 modified
-
Data/ByteString.hs (modified) (20 diffs)
-
Data/ByteString/Base.hs (modified) (7 diffs)
-
Data/ByteString/Char8.hs (modified) (8 diffs)
-
Data/ByteString/Lazy.hs (modified) (10 diffs)
-
Data/ByteString/Lazy/Char8.hs (modified) (14 diffs)
-
README (modified) (3 diffs)
-
TODO (modified) (2 diffs)
-
fps.cabal.in (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
third-party/fps/Data/ByteString.hs
r10591 r11937 168 168 zip, -- :: ByteString -> ByteString -> [(Word8,Word8)] 169 169 zipWith, -- :: (Word8 -> Word8 -> c) -> ByteString -> ByteString -> [c] 170 zipWith', 170 171 unzip, -- :: [(Word8,Word8)] -> (ByteString,ByteString) 171 172 … … 182 183 -- ** Using ByteStrings as CStrings 183 184 useAsCString, -- :: ByteString -> (CString -> IO a) -> IO a 184 unsafeUseAsCString, -- :: ByteString -> (CString -> IO a) -> IO a 185 unsafeUseAsCStringLen, -- :: ByteString -> (CStringLen -> IO a) -> IO a 185 useAsCStringLen, -- :: ByteString -> (CStringLen -> IO a) -> IO a 186 186 187 187 -- ** Copying ByteStrings … … 194 194 195 195 -- ** Standard input and output 196 197 #if defined(__GLASGOW_HASKELL__)198 196 getLine, -- :: IO ByteString 199 #endif200 197 getContents, -- :: IO ByteString 201 198 putStr, -- :: ByteString -> IO () 202 199 putStrLn, -- :: ByteString -> IO () 200 interact, -- :: (ByteString -> ByteString) -> IO () 203 201 204 202 -- ** Files … … 209 207 210 208 -- ** I\/O with Handles 211 #if defined(__GLASGOW_HASKELL__)212 209 getArgs, -- :: IO [ByteString] 213 210 hGetLine, -- :: Handle -> IO ByteString 214 211 hGetLines, -- :: Handle -> IO [ByteString] 215 hGetNonBlocking, -- :: Handle -> Int -> IO ByteString216 #endif217 212 hGetContents, -- :: Handle -> IO ByteString 218 213 hGet, -- :: Handle -> Int -> IO ByteString 214 hGetNonBlocking, -- :: Handle -> Int -> IO ByteString 219 215 hPut, -- :: Handle -> ByteString -> IO () 220 216 hPutStr, -- :: Handle -> ByteString -> IO () … … 236 232 ,scanl,scanl1,scanr,scanr1 237 233 ,readFile,writeFile,appendFile,replicate 238 ,getContents,getLine,putStr,putStrLn 234 ,getContents,getLine,putStr,putStrLn,interact 239 235 ,zip,zipWith,unzip,notElem) 240 236 … … 261 257 262 258 -- hGetBuf and hPutBuf not available in yhc or nhc 263 import System.IO (stdin,stdout,hClose,hFileSize 264 ,hGetBuf,hPutBuf,openBinaryFile 265 ,Handle,IOMode(..)) 259 import System.IO (stdin,stdout,hClose,hFileSize,hIsEOF 260 ,hGetBuf,hPutBuf,Handle,IOMode(..),openBinaryFile) 266 261 267 262 import Data.Monoid (Monoid, mempty, mappend, mconcat) … … 269 264 #if !defined(__GLASGOW_HASKELL__) 270 265 import System.IO.Unsafe 266 import qualified System.Environment 267 import qualified System.IO (hGetLine) 271 268 #endif 272 269 … … 449 446 {-# INLINE unpack #-} 450 447 448 -- 449 -- critical this isn't strict in the acc 450 -- as it will break in the presence of list fusion. this is a known 451 -- issue with seq and build/foldr rewrite rules, which rely on lazy 452 -- demanding to avoid bottoms in the list. 453 -- 454 unpackFoldr :: ByteString -> (Word8 -> a -> a) -> a -> a 455 unpackFoldr (PS fp off len) f ch = withPtr fp $ \p -> do 456 let loop q n _ | q `seq` n `seq` False = undefined -- n.b. 457 loop _ (-1) acc = return acc 458 loop q n acc = do 459 a <- peekByteOff q n 460 loop q (n-1) (a `f` acc) 461 loop (p `plusPtr` off) (len-1) ch 462 {-# INLINE [0] unpackFoldr #-} 463 451 464 unpackList :: ByteString -> [Word8] 452 465 unpackList (PS fp off len) = withPtr fp $ \p -> do … … 461 474 "unpack-list" [1] forall p . unpackFoldr p (:) [] = unpackList p 462 475 #-} 463 464 unpackFoldr :: ByteString -> (Word8 -> a -> a) -> a -> a465 unpackFoldr (PS fp off len) f ch = withPtr fp $ \p -> do466 let STRICT3(loop)467 loop _ (-1) acc = return acc468 loop q n acc = do469 a <- peekByteOff q n470 loop q (n-1) (a `f` acc)471 loop (p `plusPtr` off) (len-1) ch472 {-# INLINE [0] unpackFoldr #-}473 474 -- TODO just use normal foldr here.475 --476 -- or477 -- unpack xs | null xs = []478 -- | otherwise = unsafeHead xs : unpack (unsafeTail xs)479 --480 -- ?481 476 482 477 #endif … … 747 742 -- | Map a function over a 'ByteString' and concatenate the results 748 743 concatMap :: (Word8 -> ByteString) -> ByteString -> ByteString 749 concatMap f = foldr (append . f) empty 750 -- A silly function for ByteStrings anyway. 744 concatMap f = concat . foldr ((:) . f) [] 745 746 -- foldr (append . f) empty 751 747 752 748 -- | /O(n)/ Applied to a predicate and a ByteString, 'any' determines if … … 833 829 ------------------------------------------------------------------------ 834 830 831 -- | The 'mapAccumL' function behaves like a combination of 'map' and 832 -- 'foldl'; it applies a function to each element of a ByteString, 833 -- passing an accumulating parameter from left to right, and returning a 834 -- final value of this accumulator together with the new list. 835 835 mapAccumL :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 836 836 #if !defined(LOOPU_FUSION) … … 841 841 {-# INLINE mapAccumL #-} 842 842 843 -- | The 'mapAccumR' function behaves like a combination of 'map' and 844 -- 'foldr'; it applies a function to each element of a ByteString, 845 -- passing an accumulating parameter from right to left, and returning a 846 -- final value of this accumulator together with the new ByteString. 843 847 mapAccumR :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 844 848 mapAccumR f z = unSP . loopDown (mapAccumEFL f) z … … 1527 1531 -- the first argument, instead of a tupling function. For example, 1528 1532 -- @'zipWith' (+)@ is applied to two ByteStrings to produce the list of 1529 -- corresponding sums. 1533 -- corresponding sums. 1530 1534 zipWith :: (Word8 -> Word8 -> a) -> ByteString -> ByteString -> [a] 1531 1535 zipWith f ps qs 1532 1536 | null ps || null qs = [] 1533 1537 | otherwise = f (unsafeHead ps) (unsafeHead qs) : zipWith f (unsafeTail ps) (unsafeTail qs) 1538 1539 -- 1540 -- | A specialised version of zipWith for the common case of a 1541 -- simultaneous map over two bytestrings, to build a 3rd. Rewrite rules 1542 -- are used to automatically covert zipWith into zipWith' when a pack is 1543 -- performed on the result of zipWith, but we also export it for 1544 -- convenience. 1545 -- 1546 zipWith' :: (Word8 -> Word8 -> Word8) -> ByteString -> ByteString -> ByteString 1547 zipWith' f (PS fp s l) (PS fq t m) = inlinePerformIO $ 1548 withForeignPtr fp $ \a -> 1549 withForeignPtr fq $ \b -> 1550 create len $ zipWith_ 0 (a `plusPtr` s) (b `plusPtr` t) 1551 where 1552 zipWith_ :: Int -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> IO () 1553 STRICT4(zipWith_) 1554 zipWith_ n p1 p2 r 1555 | n >= len = return () 1556 | otherwise = do 1557 x <- peekByteOff p1 n 1558 y <- peekByteOff p2 n 1559 pokeByteOff r n (f x y) 1560 zipWith_ (n+1) p1 p2 r 1561 1562 len = min l m 1563 {-# INLINE zipWith' #-} 1564 1565 {-# RULES 1566 1567 "Specialise zipWith" forall (f :: Word8 -> Word8 -> Word8) p q . 1568 pack (zipWith f p q) = zipWith' f p q 1569 #-} 1534 1570 1535 1571 -- | /O(n)/ 'unzip' transforms a list of pairs of bytes into a pair of … … 1614 1650 return $! PS fp 0 (fromIntegral len) 1615 1651 1616 -- | /O(n) construction/ Use a @ByteString@ with a function requiring a null-terminated @CString@. 1617 -- The @CString@ should not be freed afterwards. This is a memcpy(3). 1652 -- | /O(n) construction/ Use a @ByteString@ with a function requiring a 1653 -- null-terminated @CString@. The @CString@ will be freed 1654 -- automatically. This is a memcpy(3). 1618 1655 useAsCString :: ByteString -> (CString -> IO a) -> IO a 1619 1656 useAsCString (PS ps s l) = bracket alloc (c_free.castPtr) 1620 where 1621 alloc = withForeignPtr ps $ \p -> do 1622 buf <- c_malloc (fromIntegral l+1) 1623 memcpy (castPtr buf) (castPtr p `plusPtr` s) (fromIntegral l) 1624 poke (buf `plusPtr` l) (0::Word8) -- n.b. 1625 return $! castPtr buf 1626 1627 -- | /O(1) construction/ Use a @ByteString@ with a function requiring a @CString@. 1628 -- Warning: modifying the @CString@ will affect the @ByteString@. 1629 -- Why is this function unsafe? It relies on the null byte at the end of 1630 -- the ByteString to be there. This is /not/ the case if your ByteString 1631 -- has been spliced from a larger string (i.e. with take or drop). 1632 -- Unless you can guarantee the null byte, you should use the safe 1633 -- version, which will copy the string first. 1634 -- 1635 unsafeUseAsCString :: ByteString -> (CString -> IO a) -> IO a 1636 unsafeUseAsCString (PS ps s _) ac = withForeignPtr ps $ \p -> ac (castPtr p `plusPtr` s) 1657 where alloc = withForeignPtr ps $ \p -> do 1658 buf <- c_malloc (fromIntegral l+1) 1659 memcpy (castPtr buf) (castPtr p `plusPtr` s) (fromIntegral l) 1660 poke (buf `plusPtr` l) (0::Word8) -- n.b. 1661 return (castPtr buf) 1662 1663 -- | /O(1) construction/ Use a @ByteString@ with a function requiring a @CStringLen@. 1664 useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a 1665 useAsCStringLen = unsafeUseAsCStringLen 1666 1667 -- 1668 -- why were we doing this? 1669 -- 1670 -- useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a 1671 -- useAsCStringLen (PS ps s l) = bracket alloc (c_free.castPtr.fst) 1672 -- where 1673 -- alloc = withForeignPtr ps $ \p -> do 1674 -- buf <- c_malloc (fromIntegral l+1) 1675 -- memcpy (castPtr buf) (castPtr p `plusPtr` s) (fromIntegral l) 1676 -- poke (buf `plusPtr` l) (0::Word8) -- n.b. 1677 -- return $! (castPtr buf, l) 1678 -- 1637 1679 1638 1680 -- | /O(n)/ Make a copy of the 'ByteString' with its own storage. … … 1657 1699 memcpy p (castPtr cstr) (fromIntegral len) 1658 1700 1659 -- | /O(1) construction/ Use a @ByteString@ with a function requiring a @CStringLen@.1660 -- Warning: modifying the @CStringLen@ will affect the @ByteString@.1661 -- This is analogous to unsafeUseAsCString, and comes with the same safety requirements.1662 unsafeUseAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a1663 unsafeUseAsCStringLen (PS ps s l) ac = withForeignPtr ps $ \p -> ac (castPtr p `plusPtr` s,l)1664 1665 1701 -- --------------------------------------------------------------------- 1666 1702 -- line IO 1667 1703 1668 #if defined(__GLASGOW_HASKELL__) 1669 1670 -- | getLine, read a line from stdin. 1704 -- | Read a line from stdin. 1671 1705 getLine :: IO ByteString 1672 1706 getLine = hGetLine stdin 1673 1707 1674 1708 -- | Lazily construct a list of lines of ByteStrings. This will be much 1675 -- better on memory consumption than using lines =<< getContents. 1709 -- better on memory consumption than using 'hGetContents >>= lines' 1710 -- If you're considering this, a better choice might be to use 1711 -- Data.ByteString.Lazy 1676 1712 hGetLines :: Handle -> IO [ByteString] 1677 1713 hGetLines h = go 1678 1714 where 1679 1715 go = unsafeInterleaveIO $ do 1680 ms <- catch (hGetLine h >>= return . Just) 1681 (\_ -> return Nothing) 1682 case ms of 1683 Nothing -> return [] 1684 Just s -> do ss <- go 1685 return (s:ss) 1686 1687 -- | hGetLine. read a ByteString from a handle 1716 e <- hIsEOF h 1717 if e 1718 then return [] 1719 else do 1720 x <- hGetLine h 1721 xs <- go 1722 return (x:xs) 1723 1724 -- | Read a line from a handle 1725 1688 1726 hGetLine :: Handle -> IO ByteString 1727 #if !defined(__GLASGOW_HASKELL__) 1728 hGetLine h = do 1729 string <- System.IO.hGetLine h 1730 return $ packWith c2w string 1731 #else 1689 1732 hGetLine h = wantReadableHandle "Data.ByteString.hGetLine" h $ \ handle_ -> do 1690 1733 case haBufferMode handle_ of … … 1787 1830 hGet h i = createAndTrim i $ \p -> hGetBuf h p i 1788 1831 1789 #if defined(__GLASGOW_HASKELL__)1790 1832 -- | hGetNonBlocking is identical to 'hGet', except that it will never block 1791 1833 -- waiting for data to become available, instead it returns only whatever data 1792 1834 -- is available. 1793 1835 hGetNonBlocking :: Handle -> Int -> IO ByteString 1836 #if defined(__GLASGOW_HASKELL__) 1794 1837 hGetNonBlocking _ 0 = return empty 1795 1838 hGetNonBlocking h i = createAndTrim i $ \p -> hGetBufNonBlocking h p i 1839 #else 1840 hGetNonBlocking = hGet 1796 1841 #endif 1797 1842 … … 1831 1876 getContents = hGetContents stdin 1832 1877 1878 -- | The interact function takes a function of type @ByteString -> ByteString@ 1879 -- as its argument. The entire input from the standard input device is passed 1880 -- to this function as its argument, and the resulting string is output on the 1881 -- standard output device. It's great for writing one line programs! 1882 interact :: (ByteString -> ByteString) -> IO () 1883 interact transformer = putStr . transformer =<< getContents 1884 1833 1885 -- | Read an entire file strictly into a 'ByteString'. This is far more 1834 1886 -- efficient than reading the characters into a 'String' and then using 1835 1887 -- 'pack'. It also may be more efficient than opening the file and 1836 -- reading it using hGet. 1888 -- reading it using hGet. Files are read using 'binary mode' on Windows, 1889 -- for 'text mode' use the Char8 version of this function. 1837 1890 readFile :: FilePath -> IO ByteString 1838 1891 readFile f = bracket (openBinaryFile f ReadMode) hClose … … 1841 1894 -- | Write a 'ByteString' to a file. 1842 1895 writeFile :: FilePath -> ByteString -> IO () 1843 writeFile f ps= bracket (openBinaryFile f WriteMode) hClose1844 (\h -> hPut h ps)1896 writeFile f txt = bracket (openBinaryFile f WriteMode) hClose 1897 (\h -> hPut h txt) 1845 1898 1846 1899 -- | Append a 'ByteString' to a file. 1847 1900 appendFile :: FilePath -> ByteString -> IO () 1848 1901 appendFile f txt = bracket (openBinaryFile f AppendMode) hClose 1849 (\h dl -> hPut hdltxt)1902 (\h -> hPut h txt) 1850 1903 1851 1904 {- … … 1907 1960 -} 1908 1961 1962 -- 1963 -- | A ByteString equivalent for getArgs. More efficient for large argument lists 1964 -- 1965 getArgs :: IO [ByteString] 1909 1966 #if defined(__GLASGOW_HASKELL__) 1910 --1911 -- | A ByteString equivalent for getArgs. More efficient for large argument lists1912 --1913 getArgs :: IO [ByteString]1914 1967 getArgs = 1915 1968 alloca $ \ p_argc -> … … 1919 1972 argv <- peek p_argv 1920 1973 P.map packCString `fmap` peekArray (p - 1) (advancePtr argv 1) 1974 #else 1975 getArgs = do 1976 stringArgs <- System.Environment.getArgs 1977 return $ List.map (packWith c2w) stringArgs 1921 1978 #endif 1922 1979 -
third-party/fps/Data/ByteString/Base.hs
r10593 r11937 31 31 createAndTrim, -- :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString 32 32 createAndTrim', -- :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a) 33 mallocByteString, -- :: Int -> IO (ForeignPtr a) 33 34 34 35 unsafeCreate, -- :: Int -> (Ptr Word8 -> IO ()) -> ByteString 36 unsafeUseAsCString, -- :: ByteString -> (CString -> IO a) -> IO a 37 unsafeUseAsCStringLen, -- :: ByteString -> (CStringLen -> IO a) -> IO a 35 38 36 39 fromForeignPtr, -- :: ForeignPtr Word8 -> Int -> ByteString … … 86 89 import Foreign.Storable (Storable(..)) 87 90 import Foreign.C.Types 88 import Foreign.C.String (CString )91 import Foreign.C.String (CString, CStringLen) 89 92 90 93 import Control.Exception (assert) … … 200 203 {-# INLINE unsafeCreate #-} 201 204 202 -- | Wrapper of mallocForeignPtrBytes.205 -- | Create ByteString of size @l@ and use action @f@ to fill it's contents. 203 206 create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString 204 207 create l f = do 205 #if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 206 fp <- mallocForeignPtrBytes l 207 #else 208 fp <- mallocPlainForeignPtrBytes l 209 #endif 208 fp <- mallocByteString l 210 209 withForeignPtr fp $ \p -> f p 211 210 return $! PS fp 0 l … … 221 220 createAndTrim :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString 222 221 createAndTrim l f = do 223 #if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 224 fp <- mallocForeignPtrBytes l 225 #else 226 fp <- mallocPlainForeignPtrBytes l 227 #endif 222 fp <- mallocByteString l 228 223 withForeignPtr fp $ \p -> do 229 224 l' <- f p … … 234 229 createAndTrim' :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a) 235 230 createAndTrim' l f = do 236 #if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 237 fp <- mallocForeignPtrBytes l 238 #else 239 fp <- mallocPlainForeignPtrBytes l 240 #endif 231 fp <- mallocByteString l 241 232 withForeignPtr fp $ \p -> do 242 233 (off, l', res) <- f p … … 246 237 memcpy p' (p `plusPtr` off) (fromIntegral l') 247 238 return $! (ps, res) 239 240 -- | Wrapper of mallocForeignPtrBytes with faster implementation 241 -- for GHC 6.5 builds newer than 06/06/06 242 mallocByteString :: Int -> IO (ForeignPtr a) 243 mallocByteString l = do 244 #if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 245 mallocForeignPtrBytes l 246 #else 247 mallocPlainForeignPtrBytes l 248 #endif 248 249 249 250 #if defined(__GLASGOW_HASKELL__) … … 362 363 go (i + 1) 363 364 365 -- | /O(1) construction/ Use a @ByteString@ with a function requiring a 366 -- @CString@. Warning: modifying the @CString@ will affect the 367 -- @ByteString@. Why is this function unsafe? It relies on the null 368 -- byte at the end of the ByteString to be there. Unless you can 369 -- guarantee the null byte, you should use the safe version, which will 370 -- copy the string first. 371 unsafeUseAsCString :: ByteString -> (CString -> IO a) -> IO a 372 unsafeUseAsCString (PS ps s _) ac = withForeignPtr ps $ \p -> ac (castPtr p `plusPtr` s) 373 374 -- | /O(1) construction/ Use a @ByteString@ with a function requiring a 375 -- @CStringLen@. 376 unsafeUseAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a 377 unsafeUseAsCStringLen (PS ps s l) f = withForeignPtr ps $ \p -> f (castPtr p `plusPtr` s,l) 378 364 379 -- --------------------------------------------------------------------- 365 380 -- -
third-party/fps/Data/ByteString/Char8.hs
r10591 r11937 181 181 sort, -- :: ByteString -> ByteString 182 182 183 -- * Unchecked access183 -- * Conversion 184 184 w2c, -- :: Word8 -> Char 185 185 c2w, -- :: Char -> Word8 … … 188 188 readInt, -- :: ByteString -> Maybe Int 189 189 190 -- * Low level CString conversions 191 192 -- ** Packing CStrings and pointers 193 packCString, -- :: CString -> ByteString 194 packCStringLen, -- :: CString -> ByteString 195 packMallocCString, -- :: CString -> ByteString 196 197 -- ** Using ByteStrings as CStrings 198 useAsCString, -- :: ByteString -> (CString -> IO a) -> IO a 199 useAsCStringLen, -- :: ByteString -> (CStringLen -> IO a) -> IO a 200 190 201 -- * Copying ByteStrings 191 202 copy, -- :: ByteString -> ByteString 203 copyCString, -- :: CString -> IO ByteString 204 copyCStringLen, -- :: CStringLen -> IO ByteString 192 205 193 206 -- * I\/O with @ByteString@s 194 207 195 208 -- ** Standard input and output 196 197 #if defined(__GLASGOW_HASKELL__)198 209 getLine, -- :: IO ByteString 199 #endif200 210 getContents, -- :: IO ByteString 201 211 putStr, -- :: ByteString -> IO () 202 212 putStrLn, -- :: ByteString -> IO () 213 interact, -- :: (ByteString -> ByteString) -> IO () 203 214 204 215 -- ** Files … … 209 220 210 221 -- ** I\/O with Handles 211 #if defined(__GLASGOW_HASKELL__)212 222 getArgs, -- :: IO [ByteString] 213 223 hGetLine, -- :: Handle -> IO ByteString 214 224 hGetLines, -- :: Handle -> IO ByteString 215 225 hGetNonBlocking, -- :: Handle -> Int -> IO ByteString 216 #endif217 226 hGetContents, -- :: Handle -> IO ByteString 218 227 hGet, -- :: Handle -> Int -> IO ByteString … … 242 251 ,dropWhile,span,break,elem,filter,unwords 243 252 ,words,maximum,minimum,all,concatMap,scanl,scanl1 244 ,foldl1,foldr1,readFile,writeFile,appendFile,replicate 245 ,getContents,getLine,putStr,putStrLn 253 ,appendFile,readFile,writeFile 254 ,foldl1,foldr1,replicate 255 ,getContents,getLine,putStr,putStrLn,interact 246 256 ,zip,zipWith,unzip,notElem) 247 257 … … 256 266 ,findSubstrings,copy,group 257 267 258 ,getContents, putStr, putStrLn 259 ,readFile, {-mmapFile,-} writeFile, appendFile 268 ,getLine, getContents, putStr, putStrLn, interact 260 269 ,hGetContents, hGet, hPut, hPutStr, hPutStrLn 270 ,getArgs, hGetLine, hGetLines, hGetNonBlocking 271 ,packCString,packCStringLen, packMallocCString 272 ,useAsCString,useAsCStringLen, copyCString,copyCStringLen 261 273 #if defined(__GLASGOW_HASKELL__) 262 ,getLine, getArgs, hGetLine, hGetLines, hGetNonBlocking263 274 ,unpackList 264 275 #endif … … 275 286 import qualified Data.List as List (intersperse) 276 287 288 import System.IO (openFile,hClose,hFileSize,IOMode(..)) 289 import Control.Exception (bracket) 277 290 import Foreign 278 291 … … 826 839 {-# INLINE lines #-} 827 840 828 {- #Bogus rule, wrong if there's not \n at end of line841 {- Bogus rule, wrong if there's not \n at end of line 829 842 830 843 "length.lines/count" 831 844 P.length . lines = count '\n' 832 845 833 #-}846 -} 834 847 835 848 {- … … 1001 1014 filter' :: (Char -> Bool) -> ByteString -> ByteString 1002 1015 filter' f = B.filter' (f . w2c) 1016 1017 -- | Read an entire file strictly into a 'ByteString'. This is far more 1018 -- efficient than reading the characters into a 'String' and then using 1019 -- 'pack'. It also may be more efficient than opening the file and 1020 -- reading it using hGet. 1021 readFile :: FilePath -> IO ByteString 1022 readFile f = bracket (openFile f ReadMode) hClose 1023 (\h -> hFileSize h >>= hGet h . fromIntegral) 1024 1025 -- | Write a 'ByteString' to a file. 1026 writeFile :: FilePath -> ByteString -> IO () 1027 writeFile f txt = bracket (openFile f WriteMode) hClose 1028 (\h -> hPut h txt) 1029 1030 -- | Append a 'ByteString' to a file. 1031 appendFile :: FilePath -> ByteString -> IO () 1032 appendFile f txt = bracket (openFile f AppendMode) hClose 1033 (\h -> hPut h txt) 1034 -
third-party/fps/Data/ByteString/Lazy.hs
r10591 r11937 1 {-# OPTIONS_GHC -cpp -optc-O1 -fffi -fglasgow-exts -fno-warn-incomplete-patterns #-} 2 -- 3 -- -optc-O2 breaks with 4.0.4 gcc on debian 1 {-# OPTIONS_GHC -cpp -fffi -fglasgow-exts -fno-warn-incomplete-patterns #-} 4 2 -- 5 3 -- Module : ByteString.Lazy … … 70 68 map, -- :: (Word8 -> Word8) -> ByteString -> ByteString 71 69 reverse, -- :: ByteString -> ByteString 72 intersperse, -- :: Word8 -> ByteString -> ByteString70 -- intersperse, -- :: Word8 -> ByteString -> ByteString 73 71 transpose, -- :: [ByteString] -> [ByteString] 74 72 … … 97 95 98 96 -- ** Accumulating maps 99 mapAccumL, -- :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 100 -- mapAccumR, -- :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 101 mapIndexed, -- :: (Int64 -> Word8 -> Word8) -> ByteString -> ByteString 97 mapAccumL, -- :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 98 mapIndexed, -- :: (Int64 -> Word8 -> Word8) -> ByteString -> ByteString 102 99 103 100 -- ** Infinite ByteStrings … … 189 186 hGet, -- :: Handle -> Int -> IO ByteString 190 187 hGetN, &n
