Clean exported ByteString custom functions

This commit is contained in:
Tissevert 2019-10-03 14:43:56 +02:00
parent 7a15113285
commit d07c286f8e
2 changed files with 8 additions and 15 deletions

View file

@ -2,15 +2,15 @@ module Data.ByteString.Char8.Util (
decodeHex decodeHex
, fromInt , fromInt
, hexString , hexString
, parseBytes
, previous , previous
, subBS , subBS
, toInt , toInt
, toBytes
, utf16BEToutf8 , utf16BEToutf8
) where ) where
import Data.ByteString (ByteString, snoc) import Data.ByteString (ByteString, snoc)
import qualified Data.ByteString as BS (foldl, pack, singleton) import qualified Data.ByteString as BS (empty, foldl, pack, singleton)
import qualified Data.ByteString.Char8 as Char8 (drop, index, take, unpack) import qualified Data.ByteString.Char8 as Char8 (drop, index, take, unpack)
import Data.Text.Encoding (encodeUtf8, decodeUtf16BE) import Data.Text.Encoding (encodeUtf8, decodeUtf16BE)
import Prelude hiding (length) import Prelude hiding (length)
@ -31,19 +31,15 @@ fromInt n
| n < 0x100 = BS.singleton $ toEnum n | n < 0x100 = BS.singleton $ toEnum n
| otherwise = fromInt (n `div` 0x100) `snoc` (toEnum (n `mod` 0x100)) | otherwise = fromInt (n `div` 0x100) `snoc` (toEnum (n `mod` 0x100))
toBytes :: Int -> Int -> ByteString
toBytes 0 _ = BS.empty
toBytes size n = toBytes (size - 1) (n `div` 0x100) `snoc` (toEnum (n `mod` 0x100))
toInt :: ByteString -> Int toInt :: ByteString -> Int
toInt = BS.foldl (\n w -> 0x100*n + fromEnum w) 0 toInt = BS.foldl (\n w -> 0x100*n + fromEnum w) 0
{-
encodeHex :: ByteString -> ByteString
encodeHex =
-}
decodeHex :: ByteString -> ByteString decodeHex :: ByteString -> ByteString
decodeHex = parseBytes . Char8.unpack decodeHex = BS.pack . fmap hexString . pairDigits . Char8.unpack
parseBytes :: String -> ByteString
parseBytes = BS.pack . fmap hexString . pairDigits
where where
pairDigits "" = [] pairDigits "" = []
pairDigits [c] = [[c]] pairDigits [c] = [[c]]

View file

@ -27,7 +27,6 @@ module PDF.Object (
, magicNumber , magicNumber
, name , name
, number , number
, parseBytes
, regular , regular
, stringObject , stringObject
, structure , structure
@ -36,14 +35,12 @@ module PDF.Object (
import Control.Applicative ((<|>), many) import Control.Applicative ((<|>), many)
import Data.Attoparsec.ByteString.Char8 (choice, count, option, sepBy) import Data.Attoparsec.ByteString.Char8 (choice, count, option, sepBy)
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import qualified Data.ByteString as BS (concat, pack) import qualified Data.ByteString as BS (concat)
import qualified Data.ByteString.Char8 as Char8 (cons, pack, singleton, unpack) import qualified Data.ByteString.Char8 as Char8 (cons, pack, singleton, unpack)
import Data.ByteString.Char8.Util (hexString, parseBytes)
import Data.Map (Map, (!), mapWithKey) import Data.Map (Map, (!), mapWithKey)
import qualified Data.Map as Map ( import qualified Data.Map as Map (
delete, empty, fromList, lookup, minViewWithKey, toList, union delete, empty, fromList, lookup, minViewWithKey, toList, union
) )
import Data.Text.Encoding (decodeUtf16BE, encodeUtf8)
import qualified PDF.EOL as EOL (charset, parser) import qualified PDF.EOL as EOL (charset, parser)
import qualified PDF.Output as Output (concat, line, string) import qualified PDF.Output as Output (concat, line, string)
import PDF.Output ( import PDF.Output (