@@ -0,0 +1,67 @@
2+-- Module : Streamly.Internal.Unicode.Utf8
3+-- Copyright : (c) 2021 Composewell Technologies
4+-- License : BSD-3-Clause
5+-- Maintainer : streamly@composewell.com
6+-- Stability : experimental
9+module Streamly.Internal.Unicode.Utf8
14+ -- * Creation and elimination
21+--------------------------------------------------------------------------------
23+--------------------------------------------------------------------------------
25+import Control.DeepSeq (NFData)
26+import Data.Word (Word8)
27+import Streamly.Internal.Data.Array.Foreign.Type (Array)
28+import System.IO.Unsafe (unsafePerformIO)
30+import qualified Streamly.Internal.Data.Array.Foreign as Array
31+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
32+import qualified Streamly.Internal.Unicode.Stream as Unicode
34+--------------------------------------------------------------------------------
36+--------------------------------------------------------------------------------
38+-- | A space efficient, packed, unboxed Unicode container.
43+--------------------------------------------------------------------------------
45+--------------------------------------------------------------------------------
47+{-# INLINE toArray #-}
48+toArray :: Utf8 -> Array Word8
49+toArray (Utf8 arr) = arr
52+{-# INLINEABLE pack #-}
53+pack :: String -> Utf8
57+ $ Array.fromStreamN len $ Unicode.encodeUtf8' $ Stream.fromList s
63+{-# INLINEABLE unpack #-}
64+unpack :: Utf8 -> String
67+ $ Stream.toList $ Unicode.decodeUtf8' $ Array.toStream $ toArray u