Skip to content

Commit

Permalink
Add instance for ShortByteString
Browse files Browse the repository at this point in the history
  • Loading branch information
ulidtko committed May 13, 2024
1 parent 66c5835 commit b73d175
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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
15 changes: 15 additions & 0 deletions 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 @@ -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

0 comments on commit b73d175

Please sign in to comment.