[#BloombergLP-bdlde-CharConvertUtf16-utf16ToUtf8-0fb]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlde.adoc[bdlde]::xref:BloombergLP/bdlde/CharConvertUtf16.adoc[CharConvertUtf16]::utf16ToUtf8
:relfileprefix: ../../../
:mrdocs:

Convert the UTF&hyphen;16 source to UTF&hyphen;8 in the destination&period;

== Synopsis

Declared in `&lt;bdlde&lowbar;charconvertutf16&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
utf16ToUtf8(
    xref:bsl/vector-00d.adoc[bsl::vector&lt;char&gt;]* dstVector,
    unsigned short const* srcString,
    std::size&lowbar;t* numCodePointsWritten = 0,
    char errorByte = &apos;?&apos;,
    xref:BloombergLP/bdlde/ByteOrder/Enum.adoc[ByteOrder::Enum] byteOrder = ByteOrder&colon;&colon;e&lowbar;HOST);
----

== Description

Load into the specified `dstVector` the null&hyphen;terminated result of converting the specified UTF&hyphen;16 `&ast;srcString` to its UTF&hyphen;8 equivalent&period; Optionally specify `srcLengthInWords`, the number of `unsigned short`s of input&period; If `srcLengthInWords` is not specified, the input must be terminated by a null word&period; Optionally specify `numCodePointsWritten`, which (if not 0) indicates the location of the modifiable variable into which the number of Unicode code points written, including the null terminator, is to be loaded, where one code point may occupy multiple bytes&period; Optionally specify an `errorByte` to be substituted (if not 0) for invalid encodings in the input string&period; Invalid encodings are incomplete multi&hyphen;word encodings or parts of a two&hyphen;word encoding out of their proper sequence&period; If `errorByte` is 0, invalid input sequences are ignored (i&period;e&period;, produce no corresponding output)&period; Optionally specify `byteOrder` to indicate the byte order of the UTF&hyphen;16 input&semi; if `byteOrder` is not specified, the input is assumed to be in host byte order&period; Any previous contents of the destination are discarded&period; Return 0 on success and `CharConvertStatus&colon;&colon;k&lowbar;INVALID&lowbar;INPUT&lowbar;BIT` if one or more invalid sequences were encountered in the input&period; The behavior is undefined unless either `srcLengthInWords` is passed or `srcString` is null&hyphen;terminated, and `errorByte` is either 0 or a valid single&hyphen;byte Unicode code point (`0 &lt; errorByte &lt; 0x80`)&period;

== Return Value

0 on success and `CharConvertStatus&colon;&colon;k&lowbar;INVALID&lowbar;INPUT&lowbar;BIT` otherwise

== Parameters

[cols="1,4"]
|===
| Name| Description
| *dstVector*
| destination for the converted output
| *srcString*
| source string to convert
| *numCodePointsWritten*
| if non&hyphen;null, set to the code&hyphen;point count written
| *errorByte*
| replacement for invalid input, or 0 to skip
| *byteOrder*
| UTF&hyphen;16 byte order&semi; host order if unspecified
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
