--- |> parseWWWFormURLEncoded "aaa=bbb&ccc=ddd"
--- > ==> [("aaa", "bbb"), ("ccc", "ddd")]
-parseWWWFormURLEncoded :: String -> [(String, String)]
-parseWWWFormURLEncoded src
- | src == "" = []
- | otherwise = do pairStr <- splitBy (\ c -> c == ';' || c == '&') src
- let (key, value) = break (== '=') pairStr
- return ( unEscapeString key
- , unEscapeString $ case value of
- ('=':val) -> val
- val -> val
- )
+-- |Convert a 'CIAscii' to an 'Exp' representing it as a literal.
+liftCIAscii ∷ CIAscii → Q Exp
+liftCIAscii a = [| A.toCIAscii (A.unsafeFromString $(strLit a)) |]
+ where
+ strLit ∷ CIAscii → Q Exp
+ strLit = liftString ∘ A.toString ∘ A.fromCIAscii
+
+-- |Convert a 'Text' to an 'Exp' representing it as a literal.
+liftText ∷ Text → Q Exp
+liftText t = [| T.pack $(strLit t) |]
+ where
+ strLit ∷ Text → Q Exp
+ strLit = liftString ∘ T.unpack
+
+-- |Convert an arbitrary 'Map' to an 'Exp' representing it as a
+-- literal, using a given key lifter and a value lifter.
+liftMap ∷ Eq k ⇒ (k → Q Exp) → (v → Q Exp) → Map k v → Q Exp
+liftMap liftK liftV m = [| M.fromAscList $(liftPairs $ M.toAscList m) |]
+ where
+ liftPairs = listE ∘ map liftPair
+ liftPair (k, v) = tupE [liftK k, liftV v]