X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCidr.hs;h=553bd15c06061daf2928fce8ae49dee71f56c1c8;hb=706e492881f05238ace00fefc6ec9cb0000ea2e9;hp=a2aed97d6a9b39a84a2753c5d746a01eee898052;hpb=64dfebebdecd1119ab8345a6de34597f6a878a98;p=hath.git 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