@@ -141,6 +141,7 @@ decodeUtf8' bs = unsafeDupablePerformIO $ do
141141 rnf (Chunk _ ts) = rnf ts
142142{-# INLINE decodeUtf8' #-}
143143
144+-- | Encode text using UTF-8 encoding.
144145encodeUtf8 :: Text -> B.ByteString
145146encodeUtf8 Empty = B.empty
146147encodeUtf8 lt@(Chunk t _) =
@@ -154,10 +155,20 @@ encodeUtf8 lt@(Chunk t _) =
154155 firstChunkSize = min B.smallChunkSize (4 * (T.length t + 1))
155156 strategy = B.safeStrategy firstChunkSize B.defaultChunkSize
156157
158+-- | Encode text to a ByteString 'B.Builder' using UTF-8 encoding.
159+--
160+-- @since 1.1.0.0
157161encodeUtf8Builder :: Text -> B.Builder
158162encodeUtf8Builder =
159163 foldrChunks (\c b -> TE.encodeUtf8Builder c `mappend` b) Data.Monoid.mempty
160164
165+-- | Encode text using UTF-8 encoding and escape the ASCII characters using
166+-- a 'BP.BoundedPrim'.
167+--
168+-- Use this function is to implement efficient encoders for text-based formats
169+-- like JSON or HTML.
170+--
171+-- @since 1.1.0.0
161172{-# INLINE encodeUtf8BuilderEscaped #-}
162173encodeUtf8BuilderEscaped :: BP.BoundedPrim Word8 -> Text -> B.Builder
163174encodeUtf8BuilderEscaped prim =