packages feed

text-short 0.1.3 → 0.1.4

raw patch · 5 files changed

+85/−14 lines, 5 filesdep +template-haskelldep ~basedep ~bytestringdep ~ghc-primsetup-changednew-uploader

Dependencies added: template-haskell

Dependency ranges changed: base, bytestring, ghc-prim, hashable, semigroups, tasty

Files

ChangeLog.md view
@@ -1,3 +1,9 @@+## 0.1.4++  * Fix `fromString` for single character strings.+    https://github.com/haskell-hvr/text-short/issues/20+  * Add Template Haskell `Lift ShortText` instance.+ ## 0.1.3    * Add `Data ShortText` instance
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
src-test/Tests.hs view
@@ -1,6 +1,12 @@+{-# LANGUAGE CPP               #-} {-# LANGUAGE OverloadedLists   #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell   #-} +#ifndef MIN_VERSION_GLASGOW_HASKELL+#define MIN_VERSION_GLASGOW_HASKELL(x,y,z,w) ((x*100 + y) >= __GLASGOW_HASKELL__)+#endif+ module Main(main) where  import           Data.Binary@@ -164,8 +170,11 @@   , testCase "IsString U+D800" $ "\xFFFD" @?= (IUT.fromString "\xD800") --  , testCase "IsString U+D800" $ (IUT.fromString "\xD800") @?= IUT.fromText ("\xD800" :: T.Text) +#if !(MIN_VERSION_bytestring(0,11,0) && MIN_VERSION_GLASGOW_HASKELL(9,0,1,0) && !MIN_VERSION_GLASGOW_HASKELL(9,0,2,0))+  -- https://gitlab.haskell.org/ghc/ghc/-/issues/19976   , testCase "Binary.encode" $ encode ("Hello \8364 & \171581!\NUL" :: IUT.ShortText) @?= "\NUL\NUL\NUL\NUL\NUL\NUL\NUL\DC2Hello \226\130\172 & \240\169\184\189!\NUL"   , testCase "Binary.decode" $ decode ("\NUL\NUL\NUL\NUL\NUL\NUL\NUL\DC2Hello \226\130\172 & \240\169\184\189!\NUL") @?= ("Hello \8364 & \171581!\NUL" :: IUT.ShortText)+#endif   , testCase "singleton" $ [ c | c <- [minBound..maxBound], IUT.singleton c /= IUT.fromText (T.singleton c) ] @?= []    , testCase "splitAtEnd" $ IUT.splitAtEnd 1 "€€" @?= ("€","€")@@ -188,6 +197,27 @@   , testCase "literal9"  $ [] @?= ("" :: IUT.ShortText)   , testCase "literal10" $ ['¤','€','$'] @?= ("¤€$" :: IUT.ShortText)   , testCase "literal12" $ IUT.unpack ['\xD800','\xD7FF','\xDFFF','\xE000'] @?= ['\xFFFD','\xD7FF','\xFFFD','\xE000']++    -- template haskell+  , testCase "TH.Lift" $ do+      testLit1 @?= $([| testLit1 |])+      testLit2 @?= $([| testLit2 |])+      testLit3 @?= $([| testLit3 |])+      testLit4 @?= $([| testLit4 |])+      testLit5 @?= $([| testLit5 |])+      testLit6 @?= $([| testLit6 |])+      testLit7 @?= $([| testLit7 |])+      testLit8 @?= $([| testLit8 |])++  , testCase "TTH.Lift" $ do+      testLit1 @?= $$([|| testLit1 ||])+      testLit2 @?= $$([|| testLit2 ||])+      testLit3 @?= $$([|| testLit3 ||])+      testLit4 @?= $$([|| testLit4 ||])+      testLit5 @?= $$([|| testLit5 ||])+      testLit6 @?= $$([|| testLit6 ||])+      testLit7 @?= $$([|| testLit7 ||])+      testLit8 @?= $$([|| testLit8 ||])  ]  -- isScalar :: Char -> Bool
src/Data/Text/Short/Internal.hs view
@@ -10,6 +10,12 @@ {-# LANGUAGE Unsafe                     #-} {-# LANGUAGE ViewPatterns               #-} +#if __GLASGOW_HASKELL__ >= 800+{-# LANGUAGE TemplateHaskellQuotes #-}+#else+{-# LANGUAGE TemplateHaskell #-}+#endif+ -- | -- Module      : Data.Text.Short.Internal -- Copyright   : © Herbert Valerio Riedel 2017@@ -141,6 +147,8 @@ import           Text.Printf                    (PrintfArg, formatArg,                                                  formatString) +import qualified Language.Haskell.TH.Syntax     as TH+ import qualified PrimOps  -- | A compact representation of Unicode strings.@@ -240,6 +248,18 @@           Just st -> return st #endif +-- | Since 0.1.3+instance TH.Lift ShortText where+    -- TODO: Use DeriveLift with bytestring-0.11.2.0+    lift t = [| fromString s |]+      where s = toString t++#if MIN_VERSION_template_haskell(2,17,0)+    liftTyped = TH.unsafeCodeCoerce . TH.lift+#elif MIN_VERSION_template_haskell(2,16,0)+    liftTyped = TH.unsafeTExpCoerce . TH.lift+#endif+ -- | \(\mathcal{O}(1)\) Test whether a 'ShortText' is empty. -- -- >>> null ""@@ -657,9 +677,10 @@ -- -- @since 0.1 fromString :: String -> ShortText-fromString []  = mempty-fromString [c] = singleton c-fromString s = ShortText . encodeStringShort utf8 . map r $ s+fromString s = case s of+  []  -> mempty+  [c] -> singleton $ r c+  _   -> ShortText . encodeStringShort utf8 . map r $ s   where     r c | isSurr (ord c) = '\xFFFD'         | otherwise      = c@@ -1271,7 +1292,12 @@ {-# INLINE writeWord8Array #-} writeWord8Array :: MBA s -> B -> Word -> ST s () writeWord8Array (MBA# mba#) (B (I# i#)) (W# w#)-  = ST $ \s -> case GHC.Exts.writeWord8Array# mba# i# w# s of+  = ST $ \s ->+#if __GLASGOW_HASKELL__ >= 902+      case GHC.Exts.writeWord8Array# mba# i# (GHC.Exts.wordToWord8# w#) s of+#else+      case GHC.Exts.writeWord8Array# mba# i# w# s of+#endif                  s' -> (# s', () #) {- not needed yet {-# INLINE indexWord8Array #-}
text-short.cabal view
@@ -1,7 +1,6 @@ cabal-version:       1.18- name:                text-short-version:             0.1.3+version:             0.1.4 synopsis:            Memory-efficient representation of Unicode text strings license:             BSD3 license-file:        LICENSE@@ -14,7 +13,7 @@                      .                      The main difference between 'Text' and 'ShortText' is that 'ShortText' uses UTF-8 instead of UTF-16 internally and also doesn't support zero-copy slicing (thereby saving 2 words). Consequently, the memory footprint of a (boxed) 'ShortText' value is 4 words (2 words when unboxed) plus the length of the UTF-8 encoded payload. -tested-with:         GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4+tested-with:         GHC==9.0.1, GHC==8.10.4, GHC==8.8.3, GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==9.2.0.20210821 extra-source-files:  ChangeLog.md  Source-Repository head@@ -33,14 +32,18 @@    other-modules:       Data.Text.Short.Internal -  build-depends:       base        >= 4.7    && < 4.13-                     , bytestring  >= 0.10.4 && < 0.11+  build-depends:       base        >= 4.7    && < 4.17+                     , bytestring  >= 0.10.4 && < 0.12                      , hashable    >= 1.2.6  && < 1.4                      , deepseq     >= 1.3    && < 1.5                      , text        >= 1.0    && < 1.3                      , binary      >= 0.7.1  && < 0.9-                     , ghc-prim    >= 0.3.1  && < 0.6+                     , ghc-prim    >= 0.3.1  && < 0.9+                     , template-haskell >= 2.9.0.0 && <2.19 +  if impl(ghc >=8.0)+    build-depends: bytestring >= 0.10.8.0+   if !impl(ghc >= 8.0)      build-depends: semigroups >= 0.18.2 && < 0.20 @@ -62,6 +65,11 @@                      , Trustworthy                      , Unsafe +  if impl(ghc >= 8)+    other-extensions: TemplateHaskellQuotes+  else+    other-extensions: TemplateHaskell+   c-sources: cbits/cbits.c    if flag(asserts)@@ -70,19 +78,22 @@      cc-options: -DNDEBUG=1    ghc-options: -Wall-  cc-options: -O3 -Wall+  cc-options: -Wall  test-suite tests   type:                exitcode-stdio-1.0   hs-source-dirs:      src-test   main-is:             Tests.hs +  -- bytestring dependency for cabal_macros.h   build-depends: base+               , bytestring                , binary                , text                , text-short+               , template-haskell                  -- deps which don't inherit constraints from library stanza:-               , tasty                >= 1.0.0  && < 1.3+               , tasty                >= 1.0.0  && < 1.5                , tasty-quickcheck     >= 0.10   && < 0.11                , tasty-hunit          >= 0.10.0 && < 0.11                , quickcheck-instances >= 0.3.14 && < 0.4