From b73d175514bf13467807c06abeb944ce20d2f83b Mon Sep 17 00:00:00 2001 From: Max Ulidtko Date: Mon, 13 May 2024 17:51:13 +0200 Subject: [PATCH] Add instance for ShortByteString Closes #23 --- CHANGELOG | 4 ++++ Data/CaseInsensitive/Internal.hs | 15 +++++++++++++++ test/test.hs | 1 + 3 files changed, 20 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 33a4f6d..64bfa78 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +1.2.2.0 + +* Add instance for ShortByteString + 1.2.1.0 * Add traverse diff --git a/Data/CaseInsensitive/Internal.hs b/Data/CaseInsensitive/Internal.hs index 50f396f..d15e7f0 100644 --- a/Data/CaseInsensitive/Internal.hs +++ b/Data/CaseInsensitive/Internal.hs @@ -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 ) @@ -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 diff --git a/test/test.hs b/test/test.hs index 3a6cf30..89dbf84 100644 --- a/test/test.hs +++ b/test/test.hs @@ -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)