Implement String -> ByteString and vice versa conversion for filepaths
This commit is contained in:
parent
877d8c4089
commit
148eeb619f
@ -18,6 +18,7 @@ library
|
|||||||
exposed-modules: HPath, HPath.Foreign, HPath.Internal
|
exposed-modules: HPath, HPath.Foreign, HPath.Internal
|
||||||
build-depends: base >= 4 && <5
|
build-depends: base >= 4 && <5
|
||||||
, bytestring
|
, bytestring
|
||||||
|
, encoding
|
||||||
, exceptions
|
, exceptions
|
||||||
, deepseq
|
, deepseq
|
||||||
, word8
|
, word8
|
||||||
|
15
src/HPath.hs
15
src/HPath.hs
@ -63,6 +63,7 @@ module HPath
|
|||||||
,dropTrailingPathSeparator
|
,dropTrailingPathSeparator
|
||||||
,dropWhileEnd
|
,dropWhileEnd
|
||||||
,equalFilePath
|
,equalFilePath
|
||||||
|
,fpToString
|
||||||
,joinPath
|
,joinPath
|
||||||
,normalise
|
,normalise
|
||||||
,splitDirectories
|
,splitDirectories
|
||||||
@ -70,6 +71,7 @@ module HPath
|
|||||||
,splitPath
|
,splitPath
|
||||||
,stripPrefix
|
,stripPrefix
|
||||||
,takeDirectory
|
,takeDirectory
|
||||||
|
,userStringToFP
|
||||||
-- * Queries
|
-- * Queries
|
||||||
,hasDot
|
,hasDot
|
||||||
,hasDoublePS
|
,hasDoublePS
|
||||||
@ -91,6 +93,8 @@ import Control.Monad.Catch (MonadThrow(..))
|
|||||||
import Data.ByteString(ByteString)
|
import Data.ByteString(ByteString)
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import Data.Data
|
import Data.Data
|
||||||
|
import Data.Encoding(decodeStrictByteString, encodeStrictByteString)
|
||||||
|
import Data.Encoding.UTF8(UTF8(..))
|
||||||
import qualified Data.List as L
|
import qualified Data.List as L
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Word8
|
import Data.Word8
|
||||||
@ -441,6 +445,17 @@ stripPrefix :: ByteString -> ByteString -> Maybe ByteString
|
|||||||
stripPrefix a b = B.pack `fmap` L.stripPrefix (B.unpack a) (B.unpack b)
|
stripPrefix a b = B.pack `fmap` L.stripPrefix (B.unpack a) (B.unpack b)
|
||||||
|
|
||||||
|
|
||||||
|
-- |Uses UTF-8 decoding to convert the bytestring into a String.
|
||||||
|
fpToString :: ByteString -> String
|
||||||
|
fpToString = decodeStrictByteString UTF8
|
||||||
|
|
||||||
|
|
||||||
|
-- |Uses UTF-8 encoding to convert a user provides String into
|
||||||
|
-- a ByteString, which represents a filepath.
|
||||||
|
userStringToFP :: String -> ByteString
|
||||||
|
userStringToFP = encodeStrictByteString UTF8
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- ByteString Query functions
|
-- ByteString Query functions
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user