text-0.7.1.0: An efficient packed Unicode text typeSource codeContentsIndex
Data.Text.Foreign
PortabilityGHC
Stabilityexperimental
Maintainerbos@serpentine.com, rtharper@aftereternity.co.uk, duncan@haskell.org
Contents
Interoperability with native code
Safe conversion functions
Unsafe conversion code
Description
Support for using Text data with native code via the Haskell foreign function interface.
Synopsis
fromPtr :: Ptr Word16 -> Int -> IO Text
useAsPtr :: Text -> (Ptr Word16 -> Int -> IO a) -> IO a
lengthWord16 :: Text -> Int
unsafeCopyToPtr :: Text -> Ptr Word16 -> IO ()
Interoperability with native code

The Text type is implemented using arrays that are not guaranteed to have a fixed address in the Haskell heap. All communication with native code must thus occur by copying data back and forth.

The Text type's internal representation is UTF-16, using the platform's native endianness. This makes copied data suitable for use with native libraries that use a similar representation, such as ICU. To interoperate with native libraries that use different internal representations, such as UTF-8 or UTF-32, consider using the functions in the Data.Text.Encoding module.

Safe conversion functions
fromPtrSource
:: Ptr Word16source array
-> Intlength of source array (in Word16 units)
-> IO Text
O(n) Create a new Text from a Ptr Word16 by copying the contents of the array.
useAsPtr :: Text -> (Ptr Word16 -> Int -> IO a) -> IO aSource
O(n) Perform an action on a temporary, mutable copy of a Text. The copy is freed as soon as the action returns.
Unsafe conversion code
lengthWord16 :: Text -> IntSource
O(1) Return the length of a Text in units of Word16. This is useful for sizing a target array appropriately before using unsafeCopyToPtr.
unsafeCopyToPtr :: Text -> Ptr Word16 -> IO ()Source
O(n) Copy a Text to an array. The array is assumed to be big enough to hold the contents of the entire Text.
Produced by Haddock version 2.6.0