snap-core-1.0.5.1: Snap: A Haskell Web Framework (core interfaces and types)

Safe Haskell | None
Language | Haskell2010

Snap.Internal.Parsing

Synopsis

- fullyParse :: ByteString -> Parser a -> Either String a
- (<?>) :: Parser a -> String -> Parser a
- fullyParse' :: (Parser a -> ByteString -> Result a) -> (Result a -> ByteString -> Result a) -> ByteString -> Parser a -> Either String a
- parseNum :: Parser Int64
- untilEOL :: Parser ByteString
- crlf :: Parser ByteString
- toTableList :: (Char -> Bool) -> [Char]
- toTable :: (Char -> Bool) -> Char -> Bool
- skipFieldChars :: Parser ()
- isFieldChar :: Char -> Bool
- pHeaders :: Parser [(ByteString, ByteString)]
- pWord :: Parser ByteString
- pWord' :: (Char -> Bool) -> Parser ByteString
- pQuotedString :: Parser ByteString
- pQuotedString' :: (Char -> Bool) -> Parser ByteString
- isRFCText :: Char -> Bool
- matchAll :: [Char -> Bool] -> Char -> Bool
- pAvPairs :: Parser [(ByteString, ByteString)]
- pAvPair :: Parser (ByteString, ByteString)
- pParameter :: Parser (ByteString, ByteString)
- pParameter' :: (Char -> Bool) -> Parser (ByteString, ByteString)
- trim :: ByteString -> ByteString
- pValueWithParameters :: Parser (ByteString, [(CI ByteString, ByteString)])
- pValueWithParameters' :: (Char -> Bool) -> Parser (ByteString, [(CI ByteString, ByteString)])
- pContentTypeWithParameters :: Parser (ByteString, [(CI ByteString, ByteString)])
- pToken :: Parser ByteString
- isToken :: Char -> Bool
- pTokens :: Parser [ByteString]
- parseToCompletion :: Parser a -> ByteString -> Maybe a
- type DList a = [a] -> [a]
- pUrlEscaped :: Parser ByteString
- urlDecode :: ByteString -> Maybe ByteString
- urlEncode :: ByteString -> ByteString
- urlEncodeBuilder :: ByteString -> Builder
- urlEncodeClean :: Char -> Bool
- hexd :: Char -> Builder
- finish :: Result a -> Result a
- parseUrlEncoded :: ByteString -> Map ByteString [ByteString]
- buildUrlEncoded :: Map ByteString [ByteString] -> Builder
- printUrlEncoded :: Map ByteString [ByteString] -> ByteString
- pCookies :: Parser [Cookie]
- parseCookie :: ByteString -> Maybe [Cookie]
- unsafeFromHex :: (Enum a, Num a, Bits a) => ByteString -> a
- unsafeFromNat :: (Enum a, Num a, Bits a) => ByteString -> a

# Documentation

fullyParse :: ByteString -> Parser a -> Either String a Source #

(<?>) :: Parser a -> String -> Parser a infix 0 Source #

fullyParse' :: (Parser a -> ByteString -> Result a) -> (Result a -> ByteString -> Result a) -> ByteString -> Parser a -> Either String a Source #

parseNum :: Parser Int64 Source #

untilEOL :: Parser ByteString Source #

crlf :: Parser ByteString Source #

toTableList :: (Char -> Bool) -> [Char] Source #

toTable :: (Char -> Bool) -> Char -> Bool Source #

skipFieldChars :: Parser () Source #

isFieldChar :: Char -> Bool Source #

pHeaders :: Parser [(ByteString, ByteString)] Source #

Parser for request headers.

pWord :: Parser ByteString Source #

pWord' :: (Char -> Bool) -> Parser ByteString Source #

pQuotedString :: Parser ByteString Source #

pQuotedString' :: (Char -> Bool) -> Parser ByteString Source #

isRFCText :: Char -> Bool Source #

matchAll :: [Char -> Bool] -> Char -> Bool Source #

pAvPairs :: Parser [(ByteString, ByteString)] Source #

pAvPair :: Parser (ByteString, ByteString) Source #

pParameter :: Parser (ByteString, ByteString) Source #

pParameter' :: (Char -> Bool) -> Parser (ByteString, ByteString) Source #

trim :: ByteString -> ByteString Source #

pValueWithParameters :: Parser (ByteString, [(CI ByteString, ByteString)]) Source #

pValueWithParameters' :: (Char -> Bool) -> Parser (ByteString, [(CI ByteString, ByteString)]) Source #

pContentTypeWithParameters :: Parser (ByteString, [(CI ByteString, ByteString)]) Source #

pToken :: Parser ByteString Source #

isToken :: Char -> Bool Source #

pTokens :: Parser [ByteString] Source #

Used for "#field-name", and field-name = token, so "#token": comma-separated tokens/field-names, like a header field list.

parseToCompletion :: Parser a -> ByteString -> Maybe a Source #

type DList a = [a] -> [a] Source #

pUrlEscaped :: Parser ByteString Source #

urlDecode :: ByteString -> Maybe ByteString Source #

Decode an URL-escaped string (see http://tools.ietf.org/html/rfc2396.html#section-2.4)

Example:

    ghci> urlDecode "1+attoparsec+%7e%3d+3+*+10%5e-2+meters"
    Just "1 attoparsec ~= 3 * 10^-2 meters"

urlEncode :: ByteString -> ByteString Source #

URL-escape a string (see http://tools.ietf.org/html/rfc2396.html#section-2.4)

Example:

    ghci> urlEncode "1 attoparsec ~= 3 * 10^-2 meters"
    "1+attoparsec+%7e%3d+3+*+10%5e-2+meters"

urlEncodeBuilder :: ByteString -> Builder Source #

URL-escape a string (see http://tools.ietf.org/html/rfc2396.html#section-2.4) into a `Builder`.

Example:

    ghci> import Data.ByteString.Builder
    ghci> toLazyByteString . urlEncodeBuilder $ "1 attoparsec ~= 3 * 10^-2 meters"
    "1+attoparsec+%7e%3d+3+*+10%5e-2+meters"

urlEncodeClean :: Char -> Bool Source #

hexd :: Char -> Builder Source #

finish :: Result a -> Result a Source #

parseUrlEncoded :: ByteString -> Map ByteString [ByteString] Source #

Parse a string encoded in `application/x-www-form-urlencoded` format.

Example:

    ghci> parseUrlEncoded "Name=John+Doe&Name=Jane+Doe&Age=23&Formula=a+%2B+b+%3D%3D+13%25%21"
    fromList [(Age,["23"]),(Formula,["a + b == 13%!"]),(Name,["John Doe","Jane Doe"])]

buildUrlEncoded :: Map ByteString [ByteString] -> Builder Source #

Like `printUrlEncoded`, but produces a `Builder` instead of a `ByteString`. Useful for constructing a large string efficiently in a single step.

Example:

    ghci> import Data.Map
    ghci> import Data.Monoid
    ghci> import Data.ByteString.Builder
    ghci> let bldr = buildUrlEncoded (fromList [(Name, ["John Doe"]), (Age, ["23"])])
    ghci> toLazyByteString $ byteString "http://example.com/script?" <> bldr
    "http://example.com/script?Age=23&Name=John+Doe"

printUrlEncoded :: Map ByteString [ByteString] -> ByteString Source #

Given a collection of key-value pairs with possibly duplicate keys (represented as a `Map`), construct a string in `application/x-www-form-urlencoded` format.

Example:

    ghci> printUrlEncoded (fromList [(Name, ["John Doe"]), (Age, ["23"])])
    "Age=23&Name=John+Doe"

pCookies :: Parser [Cookie] Source #

parseCookie :: ByteString -> Maybe [Cookie] Source #

unsafeFromHex :: (Enum a, Num a, Bits a) => ByteString -> a Source #

unsafeFromNat :: (Enum a, Num a, Bits a) => ByteString -> a Source #