Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Network.IRC.CTCP
Description
Functions for encoding and decoding CTCPs.
Synopsis
- data CTCPByteString
- getUnderlyingByteString :: CTCPByteString -> ByteString
- toCTCP :: Text -> [Text] -> CTCPByteString
- fromCTCP :: CTCPByteString -> (Text, [Text])
- encodeCTCP :: ByteString -> CTCPByteString
- decodeCTCP :: CTCPByteString -> ByteString
- isCTCP :: ByteString -> Bool
- asCTCP :: ByteString -> Maybe CTCPByteString
- orCTCP :: (ByteString -> a) -> (CTCPByteString -> a) -> ByteString -> a
Types
data CTCPByteString Source #
Type representing a CTCP-encoded bytestring.
Instances
Eq CTCPByteString Source # | |
Defined in Network.IRC.CTCP Methods (==) :: CTCPByteString -> CTCPByteString -> Bool # (/=) :: CTCPByteString -> CTCPByteString -> Bool # | |
Show CTCPByteString Source # | |
Defined in Network.IRC.CTCP Methods showsPrec :: Int -> CTCPByteString -> ShowS # show :: CTCPByteString -> String # showList :: [CTCPByteString] -> ShowS # |
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.