X-Git-Url: https://gitweb.michael.orlitzky.com/?p=hath.git;a=blobdiff_plain;f=src%2FMain.hs;h=deb902297c45d3fac0990854f7a471c80f09a9b2;hp=45705be673f087d76d8e64ea61f16c086ac98632;hb=9b637112e7112180e3ddb6129a62b5e21953b469;hpb=8ee63239cbfeed3c96879d7dabe3b9dacb706f2f diff --git a/src/Main.hs b/src/Main.hs index 45705be..deb9022 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -49,7 +49,8 @@ add_barriers x = non_addr_char ++ x ++ non_addr_char -- 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 = @@ -79,9 +80,15 @@ alternate terms = "(" ++ (intercalate "|" terms) ++ ")" -- | 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]