[#BloombergLP-bdlde-CharConvertUcs2-ucs2ToUtf8-03]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlde.adoc[bdlde]::xref:BloombergLP/bdlde/CharConvertUcs2.adoc[CharConvertUcs2]::ucs2ToUtf8
:relfileprefix: ../../../
:mrdocs:

Load, into the specified `dstBuffer` of the specified `dstCapacity`, the result of converting the specified null&hyphen;terminated UCS&hyphen;2 `srcString` to its UTF&hyphen;8 equivalent&period; Optionally specify `numCharsWritten` which (if not 0) indicates the modifiable integer into which the number of _UTF&hyphen;8 characters_ written (including the null terminator) is to be loaded&period; Optionally specify `numBytesWritten` which (if not 0) indicates the modifiable integer into which the number of _bytes_ written (including the null terminator) is to be loaded&period; Return 0 on success and a bitwise&hyphen;or of the masks specified by `CharConvertStatus&colon;&colon;Enum` otherwise, with `CharConvertStatus&colon;&colon;k&lowbar;INVALID&lowbar;INPUT&lowbar;BIT` set to indicate that at least one invalid input sequence was encountered, and `CharConvertStatus&colon;&colon;k&lowbar;OUT&lowbar;OF&lowbar;SPACE&lowbar;BIT` set to indicate that `dstCapacity` was insufficient to accommodate the output&period; If `dstCapacity` was insufficient, the maximal null&hyphen;terminated prefix of the properly converted result string is loaded into `dstBuffer`&period; The behavior is undefined unless `0 &lt;&equals; dstCapacity`, `dstBuffer` refers to an array of at least `dstCapacity` elements, and `srcString` is null&hyphen;terminated&period; Note that if `dstCapacity` is 0, this function returns exactly 2 and `&ast;numCharsWritten` and `&ast;numBytesWritten` (if not null) are loaded with 0 (since there is insufficient space for the null terminator even for an empty input string)&period; Also note that since UTF&hyphen;8 is a variable&hyphen;length encoding, it is possible for `numBytesWritten` to be greater than `numCharsWritten`, and therefore that an input `srcString` of `dstCapacity &hyphen; 1` _characters_ may not fit into `dstBuffer`&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
ucs2ToUtf8(
    char* dstBuffer,
    std::size&lowbar;t dstCapacity,
    unsigned short const* srcString,
    std::size&lowbar;t* numCharsWritten = 0,
    std::size&lowbar;t* numBytesWritten = 0);
----


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