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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.IRC.CTCP

Contents

Description

Functions for encoding and decoding CTCPs.

Synopsis

Types

data CTCPByteString Source

Type representing a CTCP-encoded bytestring.

getUnderlyingByteString :: CTCPByteString -> ByteString Source

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

Encoding and decoding

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

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]) Source

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 Source

Encode a bytestring according to the CTCP spec.

decodeCTCP :: CTCPByteString -> ByteString Source

Decode a CTCP bytestring. Extraeneous escapes are dropped.

Utilities

isCTCP :: ByteString -> Bool Source

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 Source

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 Source

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.