crockford 0.1 → 0.2
raw patch · 2 files changed
+12/−39 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Codec.Crockford: decode :: (Integral i) => String -> Maybe i
+ Codec.Crockford: decode :: Integral i => String -> Maybe i
- Codec.Crockford: encode :: (Integral i) => i -> String
+ Codec.Crockford: encode :: Integral i => i -> String
Files
- crockford.cabal +3/−3
- src/Codec/Crockford.hs +9/−36
crockford.cabal view
@@ -1,7 +1,7 @@ Build-Type: Custom Name: crockford Category: Codec-Version: 0.1+Version: 0.2 Cabal-Version: >= 1.2 Synopsis: An implementation of Douglas Crockford's base32 encoding. Description:@@ -11,8 +11,8 @@ Copyright: (c) 2009 Henry Bucklow Author: Henry Bucklow Maintainer: Henry Bucklow <henry@elsie.org.uk>-Tested-With: GHC==6.10-Build-Depends: base>=3 && < 4, digits, safe, QuickCheck+Tested-With: GHC==6.12+Build-Depends: base>=4 && < 5, digits, safe, QuickCheck Exposed-Modules: Codec.Crockford Hs-Source-Dirs: src Extra-Source-Files: src/Tests.hs
src/Codec/Crockford.hs view
@@ -1,49 +1,20 @@+-- | This module implements Douglas Crockford's base32 encoding scheme to+-- store integers as text. See <http://www.crockford.com/wrmg/base32.html>+-- for more details on how this scheme works. module Codec.Crockford (encode, decode, prop_crockfordRoundTrip) where -import Control.Monad import Data.Char import Data.Digits (digits, unDigits) import Data.Maybe import Test.QuickCheck -{--0 0 O o 0-1 1 I i L l 1-2 2 2-3 3 3-4 4 4-5 5 5-6 6 6-7 7 7-8 8 8-9 9 9-10 A a A-11 B b B-12 C c C-13 D d D-14 E e E-15 F f F-16 G g G-17 H h H-18 J j J-19 K k K-20 M m M-21 N n N-22 P p P-23 Q q Q-24 R r R-25 S s S-26 T t T-27 V v V-28 W w W-29 X x X-30 Y y Y-31 Z z Z--}-+-- | Decodes a Crockford-encoded String into an integer, if possible. Returns+-- Nothing if the string is not a valid Crockford-encoded value. decode :: Integral i => String -> Maybe i decode s = mapM decodeChar s >>= return . unDigits 32 +-- | Encodes an integer into a String, using Douglas Crockford's base32+-- encoding. encode :: Integral i => i -> String encode = fromJust . mapM encodeChar . digits 32 @@ -122,6 +93,8 @@ 31 -> Just 'Z' _ -> Nothing +-- | A QuickCheck property that asserts a positive integer encoded and then+-- decoded using this module remains the same number. prop_crockfordRoundTrip :: Integer -- ^ The integer to test. -> Property