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
|
||||
build-depends: base >= 4 && <5
|
||||
, bytestring
|
||||
, encoding
|
||||
, exceptions
|
||||
, deepseq
|
||||
, word8
|
||||
|
15
src/HPath.hs
15
src/HPath.hs
@ -63,6 +63,7 @@ module HPath
|
||||
,dropTrailingPathSeparator
|
||||
,dropWhileEnd
|
||||
,equalFilePath
|
||||
,fpToString
|
||||
,joinPath
|
||||
,normalise
|
||||
,splitDirectories
|
||||
@ -70,6 +71,7 @@ module HPath
|
||||
,splitPath
|
||||
,stripPrefix
|
||||
,takeDirectory
|
||||
,userStringToFP
|
||||
-- * Queries
|
||||
,hasDot
|
||||
,hasDoublePS
|
||||
@ -91,6 +93,8 @@ import Control.Monad.Catch (MonadThrow(..))
|
||||
import Data.ByteString(ByteString)
|
||||
import qualified Data.ByteString as B
|
||||
import Data.Data
|
||||
import Data.Encoding(decodeStrictByteString, encodeStrictByteString)
|
||||
import Data.Encoding.UTF8(UTF8(..))
|
||||
import qualified Data.List as L
|
||||
import Data.Maybe
|
||||
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)
|
||||
|
||||
|
||||
-- |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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user