From: Michael Orlitzky Date: Sun, 2 May 2010 18:01:12 +0000 (-0400) Subject: Move the is_valid_cidr function in to the Cidr module. X-Git-Tag: 0.0.1~85 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=hath.git;a=commitdiff_plain;h=706e492881f05238ace00fefc6ec9cb0000ea2e9 Move the is_valid_cidr function in to the Cidr module. --- diff --git a/src/Cidr.hs b/src/Cidr.hs index a2aed97..553bd15 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -1,6 +1,7 @@ module Cidr ( Cidr, from_string, + is_valid_cidr, min_first_octet, max_first_octet, min_second_octet, @@ -13,6 +14,8 @@ module Cidr import Data.Char (digitToInt, intToDigit) import Numeric (readInt, showIntAtBase) +import Text.Regex.Posix + import ListUtils type Maskbits = Int @@ -27,6 +30,11 @@ data Cidr = Cidr { octet1 :: Octet, maskbits :: Maskbits } deriving (Show) +-- Will return True if the passed String is in CIDR notation, False +-- otherwise. +is_valid_cidr :: String -> Bool +is_valid_cidr cidr = cidr =~ "([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}" + first :: (a,b,c,d) -> a first (w,_,_,_) = w diff --git a/src/Main.hs b/src/Main.hs index 7686ae3..7b3bd7b 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -2,10 +2,9 @@ import Data.List (intercalate, intersperse) import System.Exit (ExitCode(..), exitWith) import System.IO (stderr, hPutStrLn) -import Text.Regex.Posix - import Cidr (Cidr, from_string, + is_valid_cidr, min_first_octet, min_second_octet, min_third_octet, @@ -70,11 +69,6 @@ cidr_to_regex cidr = max4 = max_fourth_octet cidr --- Will return True if the passed String is in CIDR notation, False --- otherwise. -is_valid_cidr :: String -> Bool -is_valid_cidr cidr = cidr =~ "([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}" - -- Take a list of Strings, and return a regular expression matching -- any of them. @@ -95,7 +89,7 @@ numeric_range x y = -- Take a CIDR String, and exit with a failure if it's invalid. validate_or_die :: String -> IO () validate_or_die cidr = do - if (is_valid_cidr cidr) + if (Cidr.is_valid_cidr cidr) then do return () else do