locators 0.2.3.1 → 0.2.4.1
raw patch · 3 files changed
+21/−7 lines, 3 files
Files
- locators.cabal +2/−2
- src/Data/Locator.hs +1/−0
- src/Data/Locator/Hashes.hs +18/−5
locators.cabal view
@@ -1,11 +1,11 @@ cabal-version: >= 1.10 name: locators-version: 0.2.3.1+version: 0.2.4.1 synopsis: Human exchangable identifiers and locators license: BSD3 author: Andrew Cowie <andrew@operationaldynamics.com> maintainer: Andrew Cowie <andrew@operationaldynamics.com>-copyright: © 2013 Operational Dynamics Consultin, Pty Ltd and Others+copyright: © 2013-2014 Operational Dynamics Consulting, Pty Ltd and Others category: Other tested-with: GHC == 7.6 stability: experimental
src/Data/Locator.hs view
@@ -63,6 +63,7 @@ -- * Base62 toBase62, fromBase62,+ padWithZeros, hashStringToBase62 ) where
src/Data/Locator/Hashes.hs view
@@ -13,7 +13,12 @@ {-# LANGUAGE OverloadedStrings #-} -module Data.Locator.Hashes ( toBase62, fromBase62, hashStringToBase62) where+module Data.Locator.Hashes (+ toBase62,+ fromBase62,+ padWithZeros,+ hashStringToBase62+) where import Prelude hiding (toInteger)@@ -41,13 +46,20 @@ toBase62 x = showIntAtBase 62 represent x "" -padWithZeros :: Int -> Integer -> String-padWithZeros digits x =+--+-- | Utility function to prepend \'0\' characters to a string representing a+-- number. This allows you to ensure a fixed width for numbers that are less+-- than the desired width in size. This comes up frequently when representing+-- numbers in other bases greater than 10 as they are inevitably presented as+-- text, and not having them evenly justified can (at best) be ugly and (at+-- worst) actually lead to parsing and conversion bugs.+--+padWithZeros :: Int -> String -> String+padWithZeros digits str = pad ++ str where pad = take len (replicate digits '0') len = digits - length str- str = toBase62 x value :: Char -> Int@@ -101,6 +113,7 @@ n = digest s -- SHA1 hash limit = 62 ^ digits x = mod n limit -- trim to specified number base62 chars- r = padWithZeros digits x -- convert to String+ str = toBase62 x+ r = padWithZeros digits str -- convert to String r' = S.pack r