import Data.Char (digitToInt, intToDigit)
-import qualified Data.List as DL
+import Data.List (concatMap, intercalate, intersperse, splitAt)
import qualified Numeric as N
import System.Exit (exitFailure)
import Text.Regex.Posix
-- characters, and concatenated together.
octets_base_two :: [Int] -> String
octets_base_two octet_list =
- DL.concatMap ((pad_left_to 8 '0') .base_two) octet_list
+ concatMap ((pad_left_to 8 '0') .base_two) octet_list
-- Returns the minimum address (as a base-two string) satisfying the
[octet1, octet2, octet3, octet4]
where
addr = min_base_two_address cidr
- octet1 = fst (DL.splitAt 8 addr)
- octet2 = fst (DL.splitAt 8 (snd (DL.splitAt 8 addr)))
- octet3 = fst (DL.splitAt 8 (snd (DL.splitAt 16 addr)))
- octet4 = snd (DL.splitAt 24 addr)
+ octet1 = fst (splitAt 8 addr)
+ octet2 = fst (splitAt 8 (snd (splitAt 8 addr)))
+ octet3 = fst (splitAt 8 (snd (splitAt 16 addr)))
+ octet4 = snd (splitAt 24 addr)
-- The octet components of max_base_two_address, as a base-two String.
[octet1, octet2, octet3, octet4]
where
addr = max_base_two_address cidr
- octet1 = fst (DL.splitAt 8 addr)
- octet2 = fst (DL.splitAt 8 (snd (DL.splitAt 8 addr)))
- octet3 = fst (DL.splitAt 8 (snd (DL.splitAt 16 addr)))
- octet4 = snd (DL.splitAt 24 addr)
+ octet1 = fst (splitAt 8 addr)
+ octet2 = fst (splitAt 8 (snd (splitAt 8 addr)))
+ octet3 = fst (splitAt 8 (snd (splitAt 16 addr)))
+ octet4 = snd (splitAt 24 addr)
-- The octet components of min_base_two_address, as Ints.
-- 5. Stick an address boundary on either side of the result.
cidr_to_regex :: String -> String
cidr_to_regex cidr =
- addr_barrier (DL.intercalate "\\." [range1, range2, range3, range4])
+ addr_barrier (intercalate "\\." [range1, range2, range3, range4])
where
range1 = numeric_range min1 max1
range2 = numeric_range min2 max2
-- Take a list of Strings, and return a regular expression matching
-- any of them.
alternate :: [String] -> String
-alternate terms = "(" ++ (concat (DL.intersperse "|" terms)) ++ ")"
+alternate terms = "(" ++ (concat (intersperse "|" terms)) ++ ")"
-- Take two Ints as parameters, and return a regex matching any