Add textJsonString

This commit is contained in:
Andrew Martin 2024-01-05 12:26:41 -05:00
parent 19a5c098a7
commit 647ef2d2e9
3 changed files with 9 additions and 1 deletions

View file

@ -9,6 +9,7 @@ to ease the migration process.
* Add `Data.Bytes.Builder.Unsafe.pasteUtf8TextJson#` for users who need * Add `Data.Bytes.Builder.Unsafe.pasteUtf8TextJson#` for users who need
to perform JSON string encoding without using a builder. to perform JSON string encoding without using a builder.
* Add `Data.Bytes.Builder.textJsonString` when building with text 2.0+
## 0.3.14.0 -- 2023-07-20 ## 0.3.14.0 -- 2023-07-20

View file

@ -32,6 +32,7 @@ module Data.Bytes.Builder
, shortByteString , shortByteString
#if MIN_VERSION_text(2,0,0) #if MIN_VERSION_text(2,0,0)
, textUtf8 , textUtf8
, textJsonString
#endif #endif
, shortTextUtf8 , shortTextUtf8
, shortTextJsonString , shortTextJsonString
@ -856,6 +857,12 @@ shortTextJsonString a =
!(I# len) = PM.sizeofByteArray (ByteArray ba) !(I# len) = PM.sizeofByteArray (ByteArray ba)
in slicedUtf8TextJson ba 0# len in slicedUtf8TextJson ba 0# len
#if MIN_VERSION_text(2,0,0)
textJsonString :: Text -> Builder
{-# inline textJsonString #-}
textJsonString (I.Text (A.ByteArray ba) (I# off) (I# len)) = slicedUtf8TextJson ba off len
#endif
-- | Encodes an unsigned 64-bit integer as decimal. -- | Encodes an unsigned 64-bit integer as decimal.
-- This encoding never starts with a zero unless the -- This encoding never starts with a zero unless the
-- argument was zero. -- argument was zero.

View file

@ -321,7 +321,7 @@ commitDistance target !n (Mutable buf len cs) =
-- * Precondition: The slice of the byte argument is UTF-8 encoded text. -- * Precondition: The slice of the byte argument is UTF-8 encoded text.
-- * Precondition: There is enough space in the buffer for the result -- * Precondition: There is enough space in the buffer for the result
-- to be written to. A simple way to ensure enough space is to allocate -- to be written to. A simple way to ensure enough space is to allocate
-- @3N + 2@ bytes, where N is the length of the argument. However, the -- @6N + 2@ bytes, where N is the length of the argument. However, the
-- caller may use clever heuristics to find a lower upper bound. -- caller may use clever heuristics to find a lower upper bound.
-- * Result: The next offset in the destination buffer -- * Result: The next offset in the destination buffer
pasteUtf8TextJson# :: pasteUtf8TextJson# ::