HostAndPort-0.1.0: Parser host and port pairs like localhost:22

Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.HostAndPort

Synopsis

Documentation

isIPv4Address :: String -> Bool Source

This function will validate ipv4 address and return True if string is valie adress

isIPv6Address :: String -> Bool Source

Function validates ipv6 address

hostAndPort :: String -> Either String (String, Maybe String) Source

This function will parse it's argument and return either String (Left) with info about error or (Host, Maybe Port) tuple (Right).

Examples:

>>> hostAndPort "localhost"
Right ("localhost",Nothing)
>>> hostAndPort "[::1]:3030"
Right ("::1",Just "3030")

maybeHostAndPort :: String -> Maybe (String, Maybe String) Source

Function will parse argument and return Maybe (Host, Maybe Port)

Examples:

>>> maybeHostAndPort "192.168.10.12"
Just ("192.168.10.12",Nothing)
>>> maybeHostAndPort "192.168.10.12:7272"
Just ("192.168.10.12",Just "7272")

defaultHostAndPort Source

Arguments

:: String

default Port number

-> String

connection string

-> Maybe (String, String)

Maybe (Host, Port)

Function will take default port and connection string and returns Just (Host, Port) for valid input and Nothing for invalid.

Examples:

>>> defaultHostAndPort "22" "my.server.com"
Just ("my.server.com","22")
>>> defaultHostAndPort "22" "my.otherserver.com:54022"
Just ("my.otherserver.com","54022")
>>> defaultHostAndPort "22" "porttobig.com:500022"
Nothing