Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instance for ShortByteString #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.2.2.0

* Add instance for ShortByteString

1.2.1.0

* Add traverse
Expand Down
17 changes: 16 additions & 1 deletion Data/CaseInsensitive/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ import Prelude ( fromInteger )
-- from bytestring:
import qualified Data.ByteString as B ( ByteString, map )
import qualified Data.ByteString.Lazy as BL ( ByteString, map )
-- ShortByteString appears in 0.10.4.0, without a map function but with a Data instance.
import qualified Data.ByteString.Short as BS ( ShortByteString )
#if MIN_VERSION_bytestring(0,11,3)
-- This map function is better optimized, but is included only @since 0.11.3.0
import qualified Data.ByteString.Short as BS ( map )
#elif MIN_VERSION_bytestring(0,10,4)
-- For maximum compatibility, we use Data's gfoldl method before bytestring-0.11.3.0
import Data.Data (gfoldl)
#endif

-- from text:
import qualified Data.Text as T ( Text, toCaseFold )
Expand Down Expand Up @@ -121,7 +130,7 @@ instance Semigroup s => Semigroup (CI s) where

instance Monoid s => Monoid (CI s) where
mempty = CI mempty mempty
CI o1 l1 `mappend` CI o2 l2 = CI (o1 `mappend` o2) (l1 `mappend` l2)
mappend = (<>)

instance Eq s => Eq (CI s) where
(==) = (==) `on` foldedCase
Expand Down Expand Up @@ -167,6 +176,12 @@ instance FoldCase B.ByteString where foldCase = B.map toLower8
-- | Note that @foldCase@ on @'BL.ByteString's@ is only guaranteed to be correct for ISO-8859-1 encoded strings!
instance FoldCase BL.ByteString where foldCase = BL.map toLower8

#if MIN_VERSION_bytestring(0,11,3)
instance FoldCase BS.ShortByteString where foldCase = BS.map toLower8
#elif MIN_VERSION_bytestring(0,10,4)
instance FoldCase BS.ShortByteString where foldCase = gfoldl id toLower8
#endif

instance FoldCase Char where
foldCase = toLower
foldCaseList = TL.unpack . TL.toCaseFold . TL.pack
Expand Down
1 change: 1 addition & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ main = defaultMain
(CI.mk ( BC8.map toUpper asciiBs))
, testCase "Lazy.ByteString" $ assertEqual "" (CI.mk asciiLBs)
(CI.mk (BLC8.map toUpper asciiLBs))
-- TODO ShortByteString ?
, testCase "Text" $ assertEqual "" (CI.mk asciiTxt)
(CI.mk ( T.toUpper asciiTxt))
, testCase "Lazy.Text" $ assertEqual "" (CI.mk asciiLTxt)
Expand Down