+-- FIXME: Drop this function as soon as possible, to eliminate the
+-- dependency on blaze-textual.
+
+-- |>>> trim " ab c d "
+-- "ab c d"
+trim ∷ String → String
+trim = reverse ∘ f ∘ reverse ∘ f
+ where
+ f = dropWhile isSpace
+
+-- |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]