Fix for bytestring versions less than 0.10.8

This commit is contained in:
Julian Ospald 2016-05-24 03:26:01 +02:00
parent ae9a806c2e
commit b55cf6d9f3
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 11 additions and 4 deletions

View File

@ -32,7 +32,7 @@ library
System.Posix.FD,
System.Posix.FilePath
build-depends: base >= 4.2 && <5
, bytestring >= 0.10.8.0
, bytestring >= 0.9.2.0
, deepseq
, exceptions
, hspec

View File

@ -12,6 +12,7 @@
-- Not all functions of "System.FilePath" are implemented yet. Feel free to contribute!
{-# LANGUAGE CPP #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -Wall #-}
@ -86,7 +87,9 @@ import qualified System.Posix.Env.ByteString as PE
import Data.Maybe (isJust)
import Data.Word8
#if !MIN_VERSION_bytestring(0,10,8)
import qualified Data.List as L
#endif
import Control.Arrow (second)
-- $setup
@ -319,12 +322,16 @@ takeExtensions = snd . splitExtensions
stripExtension :: ByteString -> RawFilePath -> Maybe RawFilePath
stripExtension bs path
| BS.null bs = Just path
| otherwise = BS.stripSuffix dotExt path
| otherwise = stripSuffix' dotExt path
where
dotExt = if isExtSeparator $ BS.head bs
then bs
else extSeparator `BS.cons` bs
#if MIN_VERSION_bytestring(0,10,8)
stripSuffix' = BS.stripSuffix
#else
stripSuffix' xs ys = fmap (BS.pack . reverse) $ stripPrefix (reverse $ BS.unpack xs) (reverse $ BS.unpack ys)
#endif
------------------------