irc-ctcp-0.1.3.0: A CTCP encoding and decoding library for IRC clients.

Safe HaskellSafe
LanguageHaskell2010

Network.IRC.CTCP

Contents

Description

Functions for encoding and decoding CTCPs.

Synopsis

Types

data CTCPByteString #

Type representing a CTCP-encoded bytestring.

getUnderlyingByteString :: CTCPByteString -> ByteString #

Get the underlying (encoded) bytestring from a CTCP bytestring.

Encoding and decoding

toCTCP :: Text -> [Text] -> CTCPByteString #

Turn a command name and arguments into a CTCP-encoded bytestring.

This encodes the text with UTF-8. If another encoding is desired, encodeCTCP should be used directly.

fromCTCP :: CTCPByteString -> (Text, [Text]) #

Decode a CTCP-encoded bytestring and turn it into a command name and arguments.

This decodes the text with UTF-8. If another encoding is desired, decodeCTCP should be used directly.

encodeCTCP :: ByteString -> CTCPByteString #

Encode a bytestring according to the CTCP spec.

decodeCTCP :: CTCPByteString -> ByteString #

Decode a CTCP bytestring. Extraeneous escapes are dropped.

Utilities

isCTCP :: ByteString -> Bool #

Check if a bytestring represents a CTCP.

This is intentionally very lenient, in particular it doesn't check that there are no extra escape characters. This is because the spec states that misplaced escape characters should be discarded by the decoding process.

asCTCP :: ByteString -> Maybe CTCPByteString #

Check if a bytestring looks like a CTCP, and if so, wrap it up in the CTCPByteString type.

This uses isCTCP, and so is lenient with escapes.

orCTCP :: (ByteString -> a) -> (CTCPByteString -> a) -> ByteString -> a #

Apply one of two functions depending on whether the bytestring looks like a CTCP or not.

This uses asCTCP, and so is lenient with escapes.