Add textUtf8 for copying text to builder with text-2.0 and newer
This commit is contained in:
parent
95845870ae
commit
0405c0eb88
2 changed files with 18 additions and 0 deletions
|
@ -59,6 +59,7 @@ library
|
|||
, primitive-unlifted >=0.1.2 && <0.2
|
||||
, run-st >=0.1 && <0.2
|
||||
, template-haskell >=2.16
|
||||
, text >=1.2 && <2.2
|
||||
, text-short >=0.1.3 && <0.2
|
||||
, wide-word >=0.1.0.9 && <0.2
|
||||
, zigzag
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{-# language CPP #-}
|
||||
{-# language BangPatterns #-}
|
||||
{-# language DataKinds #-}
|
||||
{-# language DuplicateRecordFields #-}
|
||||
|
@ -27,6 +28,9 @@ module Data.Bytes.Builder
|
|||
, insert
|
||||
, byteArray
|
||||
, shortByteString
|
||||
#if MIN_VERSION_text(2,0,0)
|
||||
, textUtf8
|
||||
#endif
|
||||
, shortTextUtf8
|
||||
, shortTextJsonString
|
||||
, cstring
|
||||
|
@ -184,6 +188,12 @@ import qualified Data.Text.Short as TS
|
|||
import qualified GHC.Exts as Exts
|
||||
import qualified Op as Op
|
||||
|
||||
#if MIN_VERSION_text(2,0,0)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.Internal as I
|
||||
import qualified Data.Text.Array as A
|
||||
#endif
|
||||
|
||||
-- | Run a builder.
|
||||
run ::
|
||||
Int -- ^ Size of initial chunk (use 4080 if uncertain)
|
||||
|
@ -794,6 +804,13 @@ shortTextUtf8 a =
|
|||
let ba = shortTextToByteArray a
|
||||
in bytes (Bytes ba 0 (PM.sizeofByteArray ba))
|
||||
|
||||
#if MIN_VERSION_text(2,0,0)
|
||||
-- | Create a builder from text. The text will be UTF-8 encoded.
|
||||
textUtf8 :: Text -> Builder
|
||||
textUtf8 (I.Text (A.ByteArray b) off len) =
|
||||
bytes (Bytes (ByteArray b) off len)
|
||||
#endif
|
||||
|
||||
-- | Create a builder from text. The text will be UTF-8 encoded,
|
||||
-- and JSON special characters will be escaped. Additionally, the
|
||||
-- result is surrounded by double quotes. For example:
|
||||
|
|
Loading…
Reference in a new issue