- mapMaybe readMaybe (take 4 (splitOneOf "./" s))
-
-
--- | Return Nothing if we can't parse both maskbits and octets from
--- the string.
-cidr_from_string :: String -> Maybe Cidr
-cidr_from_string s =
- case (octets_from_cidr_string s) of
- [oct1, oct2, oct3, oct4] ->
- case (maskbits_from_cidr_string s) of
- Just mbits ->
- Just $ Cidr (IPv4Address oct1 oct2 oct3 oct4) mbits
- _ -> Nothing
- _ -> Nothing
+ case parts of
+ (p1:p2:p3:p4:_) -> mapMaybe readMaybe [p1,p2,p3,p4]
+ _ -> []
+ where
+ parts = splitOneOf "./" s