]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Cidr.hs
Move the is_valid_cidr function in to the Cidr module.
[hath.git] / src / Cidr.hs
index a2aed97d6a9b39a84a2753c5d746a01eee898052..553bd15c06061daf2928fce8ae49dee71f56c1c8 100644 (file)
@@ -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