HostAndPort-0.2.0: Parser for host and port pairs like localhost:22

Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.HostAndPort

Synopsis

Documentation

data ConnectionDetail a Source

Constructors

IPv4Address a 
IPv6Address a 
HostName a 

Instances

isIPv4Address :: String -> Bool Source

This function will validate ipv4 address and return True if string is valid 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")

detailedHostAndPort :: String -> Either String (RemoteAddr, Maybe String) Source

This function will parse it's argument and return either String (Left) in case of error or (`ConnectionDetail String`, Maybe Port) tuple (Right).

Examples:

>>> detailedHostAndPort "localhost"
Right (HostName "localhost",Nothing)
>>> detailedHostAndPort "[::1]:3030"
Right (IPv6Address "::1",Just "3030")
>>> detailedHostAndPort "127.0.0.1:1080"
Right (IPv4Address "127.0.0.1",Just "1080")

Since 0.2

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