packages feed

IPv6Addr 1.1.2 → 1.1.3

raw patch · 2 files changed

+42/−42 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

IPv6Addr.cabal view
@@ -1,5 +1,5 @@ name:                IPv6Addr-version:             1.1.2+version:             1.1.3 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@@ -7,11 +7,13 @@ license-file:        LICENSE author:              Michel Boucey maintainer:          michel.boucey@gmail.com-copyright:           (c) 2011-2019 - Michel Boucey+copyright:           (c) 2011-2020 - Michel Boucey category:            Network build-type:          Simple extra-source-files:  README.md cabal-version:       >=1.10++Tested-With: GHC ==8.4.3 || ==8.6.5 || ==8.8.1  Source-Repository head   Type: git
Text/IPv6Addr.hs view
@@ -36,7 +36,7 @@ import           Data.IP              (IPv6) import           Data.List            (elemIndex, elemIndices, group,                                        intersperse, isSuffixOf)-import           Data.Maybe           (fromJust, isJust, isNothing)+import           Data.Maybe           (fromJust, isJust) import           Data.Monoid          ((<>)) import qualified Data.Text            as T import qualified Data.Text.Read       as R (decimal)@@ -161,45 +161,43 @@ -- > randIPv6AddrWithPrefix (Just "4321:0:1:2:3:4") -- randIPv6AddrWithPrefix :: Maybe T.Text -> IO (Maybe IPv6Addr)-randIPv6AddrWithPrefix p =-  if isNothing p-    then do-      r   <- randomRIO (1,8)-      tks <--        case r of+randIPv6AddrWithPrefix Nothing = do+  r   <- randomRIO (1,8)+  tks <-+    case r of+      8 -> randPartialIPv6Addr 8+      _ -> do+        r' <- randomRIO (1,8-r)+        case r + r' of+          7 -> concat <$>+            sequence [ randPartialIPv6Addr r+                     , pure [Colon,AllZeros,Colon]+                     , randPartialIPv6Addr r'+                     ]           8 -> randPartialIPv6Addr 8-          _ -> do-            r' <- randomRIO (1,8-r)-            case r + r' of-              7 -> concat <$>-                sequence [ randPartialIPv6Addr r-                         , pure [Colon,AllZeros,Colon]-                         , randPartialIPv6Addr r'-                         ]-              8 -> randPartialIPv6Addr 8-              _ -> concat <$>-                sequence [ randPartialIPv6Addr r-                         , pure [DoubleColon]-                         , randPartialIPv6Addr r'-                         ]-      return (ipv6TokensToIPv6Addr tks)-    else do-      let mtks = maybeIPv6AddrTokens (fromJust p)-      guard (isJust mtks)-      let tks = fromJust mtks-      ntks <- do-        let ctks = countChunks tks-        return $-          case (snd ctks :: Int) of-            0 -> 8 - fst ctks-            1 -> 6 - fst ctks-            _ -> 0-      guard (ntks > 0)-      rtks <- randPartialIPv6Addr ntks-      let tks' = addColon tks ++ rtks-      guard (isIPv6Addr tks')-      return $ ipv6TokensToIPv6Addr $-        (toDoubleColon . fromDoubleColon) tks'+          _ -> concat <$>+            sequence [ randPartialIPv6Addr r+                     , pure [DoubleColon]+                     , randPartialIPv6Addr r'+                     ]+  return (ipv6TokensToIPv6Addr tks)+randIPv6AddrWithPrefix (Just p) = do+  let mtks = maybeIPv6AddrTokens p+  guard (isJust mtks)+  let tks = fromJust mtks+  ntks <- do+    let ctks = countChunks tks+    return $+      case (snd ctks :: Int) of+        0 -> 8 - fst ctks+        1 -> 6 - fst ctks+        _ -> 0+  guard (ntks > 0)+  rtks <- randPartialIPv6Addr ntks+  let tks' = addColon tks ++ rtks+  guard (isIPv6Addr tks')+  return $ ipv6TokensToIPv6Addr $+    (toDoubleColon . fromDoubleColon) tks'   where     countChunks =       foldr go (0,0)@@ -218,7 +216,7 @@   -- ------------------------------------------------------------------------ ----- Maniplations                                                             --+-- Manipulations                                                             -- -- ------------------------------------------------------------------------ --  -- | Returns 'Just' a random 'SixteenBit' token based on a mask \"____\", each