Parse an IP Address: Difference between revisions

Content added Content deleted
m (Haskell - added extra check)
Line 549: Line 549:
<lang Haskell>import Data.List (isInfixOf)
<lang Haskell>import Data.List (isInfixOf)
import Numeric (showHex)
import Numeric (showHex)
import Data.Char (isDigit)


data IPChunk = IPv6Chunk String | IPv4Chunk (String, String) |
data IPChunk = IPv6Chunk String | IPv4Chunk (String, String) |
Line 633: Line 634:
zeroChunk = IPv6Chunk "0000"
zeroChunk = IPv6Chunk "0000"


portIsValid a = between 0 65535 (read a)
portIsValid a = all isDigit a && between 0 65535 (read a)


complete xs = case break isIPZeroSection xs of
complete xs = case break isIPZeroSection xs of