packages feed

base62 0.1.0.3 → 0.1.1.0

raw patch · 3 files changed

+31/−3 lines, 3 filesdep +bytestringdep +textdep +text-short

Dependencies added: bytestring, text, text-short

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for base62 +## 0.1.1.0 -- 2023-08-08++* Add `shortText128`.+* Add `text128`.+* Drop support for `text` earlier than 2.0.+ ## 0.1.0.3 -- 2023-07-25  * Support GHC 9.4. Drop support for all versions of GHC before 9.4.
base62.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: base62-version: 0.1.0.3+version: 0.1.1.0 synopsis: Base62 encoding and decoding description:   Encode and decode using the base62 encoding scheme.@@ -19,10 +19,13 @@     Data.Word.Base62   build-depends:     , base >=4.17 && <5+    , bytebuild >=0.3.4 && <0.4     , byteslice >=0.2 && <0.3+    , bytestring >=0.11.4     , natural-arithmetic >=0.1 && <0.2     , primitive >=0.7 && <0.10-    , bytebuild >=0.3.4 && <0.4+    , text >=2.0.2+    , text-short >=0.1.5     , wide-word >=0.1.0.8 && <0.2   hs-source-dirs: src   default-language: Haskell2010
src/Data/Word/Base62.hs view
@@ -24,18 +24,23 @@   , decode64     -- * 128-bit Word   , encode128+  , shortText128+  , text128   , builder128   , decode128   ) where +import Data.ByteString.Short.Internal (ShortByteString(SBS)) import Data.Bytes.Builder.Bounded.Unsafe (Builder(..)) import Data.Bytes.Types (Bytes(Bytes)) import Data.Char (ord) import Data.Primitive (ByteArray(..),readByteArray,writeByteArray) import Data.Primitive (MutableByteArray(MutableByteArray))+import Data.Text (Text)+import Data.Text.Short (ShortText) import Data.WideWord.Word128 (Word128(Word128))-import GHC.Exts (Char(C#),Word64#,Word8#,quotRemWord#,indexCharArray#) import GHC.Exts (ByteArray#,Int#,Int(I#),(+#),(-#))+import GHC.Exts (Char(C#),Word64#,Word8#,quotRemWord#,indexCharArray#) import GHC.Exts (isTrue#,(>#)) import GHC.Exts (wordToWord64#,word64ToWord#) import GHC.ST (ST(ST))@@ -45,6 +50,8 @@ import qualified Data.Bytes as Bytes import qualified Data.Bytes.Builder.Bounded as Builder import qualified GHC.Exts as Exts+import qualified Data.Text.Short as TS+import qualified Data.Text.Short.Unsafe as TS  -- $setup -- >>> :set -XNumericUnderscores@@ -71,7 +78,19 @@ -- >>> putStrLn (Bytes.toLatinString (Bytes.fromByteArray (encode128 octillion))) -- 1IdHllabYuAOlNK4 encode128 :: Word128 -> ByteArray+{-# inline encode128 #-} encode128 = Builder.run Nat.constant . builder128++-- | Base62 encode a 128-bit word as @ShortText@.+shortText128 :: Word128 -> ShortText+{-# inline shortText128 #-}+shortText128 !w = case encode128 w of+  ByteArray x -> TS.fromShortByteStringUnsafe (SBS x)++-- | Base62 encode a 128-bit word as @Text@.+text128 :: Word128 -> Text+{-# inline text128 #-}+text128 = TS.toText . shortText128  -- | Base62 encode a 128-bit word as a builder. builder128 :: Word128 -> Builder 22