IPv6Addr 0.6.0.0 → 0.6.0.1
raw patch · 3 files changed
+18/−12 lines, 3 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- IPv6Addr.cabal +6/−2
- Text/IPv6Addr.hs +3/−2
- Text/IPv6Addr/Internal.hs +9/−8
IPv6Addr.cabal view
@@ -1,5 +1,5 @@ name: IPv6Addr-version: 0.6.0.0+version: 0.6.0.1 synopsis: Library to deal with IPv6 address text representations. description: Library to deal with IPv6 address text representations, canonization and manipulations. homepage: https://github.com/MichelBoucey/IPv6Addr@@ -13,11 +13,15 @@ extra-source-files: README.md cabal-version: >=1.10 +Source-Repository head+ Type: git+ Location: https://github.com/MichelBoucey/IPv6Addr.git+ library exposed-modules: Text.IPv6Addr, Text.IPv6Addr.Types, Text.IPv6Addr.Manip, Text.IPv6Addr.Internal -- other-modules: other-extensions: OverloadedStrings- build-depends: base >=4.7 && <4.8, text >=1.2 && <1.3, iproute >=1.3 && <1.4, network >=2.6 && <2.7, random >=1.1 && <1.2, attoparsec >=0.12 && <0.13, network-info >=0.2 && <0.3+ build-depends: base >=4.7 && <4.9, text >=1.2 && <1.3, iproute >=1.3 && <1.4, network >=2.6 && <2.7, random >=1.1 && <1.2, attoparsec >=0.12 && <0.13, network-info >=0.2 && <0.3 -- hs-source-dirs: default-language: Haskell2010
Text/IPv6Addr.hs view
@@ -34,6 +34,7 @@ import Control.Applicative (pure,(<$>)) import Data.IP (IPv6) import Data.Maybe (fromJust,isNothing)+import Data.Monoid ((<>)) import qualified Data.Text as T import Network (HostName) import System.Random (randomRIO)@@ -82,10 +83,10 @@ -- toIP6ARPA :: IPv6Addr -> T.Text toIP6ARPA a =- T.append (T.reverse $ T.concatMap trans $ fromIPv6Addr $ fromJust $ maybeFullIPv6Addr $ fromIPv6Addr a) "IP6.ARPA."+ T.reverse (T.concatMap trans $ fromIPv6Addr $ fromJust $ maybeFullIPv6Addr $ fromIPv6Addr a) <> "IP6.ARPA." where trans ':' = T.empty- trans c = T.append "." (T.pack [c])+ trans c = "." <> T.pack [c] -- | Given an 'IPv6Addr', returns the corresponding 'HostName'. toHostName :: IPv6Addr -> HostName
Text/IPv6Addr/Internal.hs view
@@ -32,6 +32,7 @@ import Control.Monad (replicateM) import Data.Attoparsec.Text import Data.Char (isDigit,isHexDigit,toLower)+import Data.Monoid ((<>)) import Control.Applicative ((<|>),(<*)) import Data.List (group,isSuffixOf,elemIndex,elemIndices,intersperse) import Numeric (showHex)@@ -44,15 +45,15 @@ tok0 = "0" --- | Returns the 'Text' of an IPv6 address.+-- | Returns the 'T.Text' of an IPv6 address. fromIPv6Addr :: IPv6Addr -> T.Text fromIPv6Addr (IPv6Addr t) = t --- | Given an arbitrary list of 'IPv6AddrToken', returns the corresponding 'Text'.+-- | Given an arbitrary list of 'IPv6AddrToken', returns the corresponding 'T.Text'. ipv6TokensToText :: [IPv6AddrToken] -> T.Text ipv6TokensToText l = T.concat $ map ipv6TokenToText l --- | Returns the corresponding 'Text' of an IPv6 address token.+-- | Returns the corresponding 'T.Text' of an IPv6 address token. ipv6TokenToText :: IPv6AddrToken -> T.Text ipv6TokenToText (SixteenBit s) = s ipv6TokenToText Colon = ":"@@ -138,7 +139,7 @@ where ipv4AddrReplacement ltks' = init ltks' ++ ipv4AddrToIPv6AddrTokens (last ltks') --- | Tokenize a 'Text' into 'Just' a list of 'IPv6AddrToken', or 'Nothing'.+-- | Tokenize a 'T.Text' into 'Just' a list of 'IPv6AddrToken', or 'Nothing'. maybeIPv6AddrTokens :: T.Text -> Maybe [IPv6AddrToken] maybeIPv6AddrTokens s = case readText s of@@ -179,7 +180,7 @@ tokffff = "ffff" tok5efe = "5efe" --- | Rewrites 'Just' an embedded 'IPv4Addr' into the corresponding list of pure 'IPv6Addr' tokens.+-- | Rewrites an embedded 'IPv4Addr' into the corresponding list of pure 'IPv6Addr' tokens. -- -- > ipv4AddrToIPv6AddrTokens (IPv4Addr "127.0.0.1") == [SixteenBits "7f0",Colon,SixteenBits "1"] --@@ -188,13 +189,13 @@ case t of IPv4Addr a -> do let m = toHex a- [ SixteenBit ((!!) m 0 `T.append` addZero ((!!) m 1))+ [ SixteenBit ((!!) m 0 <> addZero ((!!) m 1)) , Colon- , SixteenBit ((!!) m 2 `T.append` addZero ((!!) m 3)) ]+ , SixteenBit ((!!) m 2 <> addZero ((!!) m 3)) ] _ -> [t] where toHex a = map (\x -> T.pack $ showHex (read (T.unpack x)::Int) "") $ T.split (=='.') a- addZero d = if T.length d == 1 then tok0 `T.append` d else d+ addZero d = if T.length d == 1 then tok0 <> d else d expandTokens :: [IPv6AddrToken] -> [IPv6AddrToken] expandTokens = map expandToken