-- 3. Generate a regex matching every value between those min and
-- max values.
-- 4. Join the regexes from step 3 with regexes matching periods.
--- 5. Stick an address boundary on either side of the result.
+-- 5. Stick an address boundary on either side of the result if
+-- use_barriers is True.
--
cidr_to_regex :: Bool -> Cidr.Cidr -> String
cidr_to_regex use_barriers cidr =
-- | Take two Ints as parameters, and return a regex matching any
-- integer between them (inclusive).
+--
+-- IMPORTANT: we match from max to min so that if e.g. the last
+-- octet is '255', we want '255' to match before '2' in the regex
+-- (255|254|...|3|2|1) which does not happen if we use
+-- (1|2|3|...|254|255).
+--
numeric_range :: Int -> Int -> String
numeric_range x y =
- alternate (map show [lower..upper])
+ alternate (map show $ reverse [lower..upper])
where
lower = minimum [x,y]
upper = maximum [x,y]