| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hmssql.Tds.Utf16
Description
Encoding Text as UTF-16LE, as every string the client sends is: the
SQL text of a batch or sp_executesql, nvarchar parameters, parameter
names, LOGIN7's strings; and decoding UTF-16LE into Text, as every
string the server sends is.
The encoder is a transcoder straight from the UTF-8 array of a Text.
text's own encodeUtf16LE (text 2.1) goes through
stream fusion into a buffer that doubles as it grows: about 14 ns and
100 bytes of allocation per character. Here ASCII runs take eight bytes
per step, and the output is written once into a buffer of its exact
size. The decoder likewise writes UTF-8 straight into a Text array.
Synopsis
- encodeUtf16LE :: Text -> ByteString
- utf16Length :: Text -> Int
- unsafeWriteUtf16LE :: Text -> Ptr Word8 -> IO Int
- utf16LEBuilder :: Text -> Builder
- decodeUtf16LE :: ByteString -> Text
- decodeUtf16Chunks :: forall (m :: Type -> Type) r. Monad m => Stream (Of ByteString) m r -> Stream (Of Text) m r
Documentation
encodeUtf16LE :: Text -> ByteString Source #
The text in UTF-16LE, without a byte order mark. The same bytes as
encodeUtf16LE.
utf16Length :: Text -> Int Source #
The length of the text in UTF-16 code units: its characters, plus one for each outside the Basic Multilingual Plane. (Every UTF-8 byte that isn't a continuation byte starts a character, and a four-byte sequence is a surrogate pair.)
unsafeWriteUtf16LE :: Text -> Ptr Word8 -> IO Int Source #
Write UTF-16LE into caller-owned memory without checking capacity.
Returns the byte count written: 2 * utf16Length text, with no byte
order mark or terminator.
The pointer must remain valid and writable for at least that many bytes
throughout the call. Twice the text's UTF-8 byte length is a sufficient
upper bound when avoiding a length scan. Size and offset arithmetic must
fit in Int; source and destination must not overlap, and the caller
must respect the lifetime and immutability of any aliases to the buffer.
Use encodeUtf16LE or utf16LEBuilder to let the library provide storage.
utf16LEBuilder :: Text -> Builder Source #
encodeUtf16LE as a Builder, written straight into the builder's
buffer, a piece at a time for text too long for one of 32 KiB.
decodeUtf16LE :: ByteString -> Text Source #
Decode UTF-16LE text from the server, never failing: each ill-formed
code unit (an unpaired surrogate) becomes one U+FFFD, and so does a
trailing odd byte. decodeUtf16LE says why.
decodeUtf16Chunks :: forall (m :: Type -> Type) r. Monad m => Stream (Of ByteString) m r -> Stream (Of Text) m r Source #
decodeUtf16LE for a value that arrives in chunks: the result is the same
however the value is cut. SQL Server ends PLP chunks at packet ends, which
can fall inside a code unit or a surrogate pair. Only the pending character,
at most three bytes, is copied between chunks.