[#BloombergLP-bdlde-CharConvertUcs2-utf8ToUcs2-0d2]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlde.adoc[bdlde]::xref:BloombergLP/bdlde/CharConvertUcs2.adoc[CharConvertUcs2]::utf8ToUcs2
:relfileprefix: ../../../
:mrdocs:

Convert a null&hyphen;terminated UTF&hyphen;8 string to UCS&hyphen;2 in a fixed buffer&period;

== Synopsis

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

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

== Description

Load, into the specified `dstBuffer` of the specified `dstCapacity`, the result of converting the specified null&hyphen;terminated UTF&hyphen;8 `srcString` to its UCS&hyphen;2 equivalent&period; Optionally specify `numCharsWritten` which (if non&hyphen;zero) indicates the modifiable integer into which the number of characters written (including the null terminator) is to be loaded&period; Optionally specify `errorCharacter` to be substituted for invalid (i&period;e&period;, not convertible to UCS&hyphen;2) input characters&period; If `errorCharacter` is 0, invalid input characters are ignored (i&period;e&period;, produce no corresponding output characters)&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`, and (unless null) `&ast;numCharsWritten` is set to `dstCapacity`&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` (if specified) is loaded with 0 (since there is insufficient space for the null terminator even for an empty input string)&period;

== Return Value

0 on success and a bitwise&hyphen;or of the masks specified by `CharConvertStatus&colon;&colon;Enum` otherwise

== Parameters

[cols="1,4"]
|===
| Name| Description
| *dstBuffer*
| output buffer for the UCS&hyphen;2 conversion
| *dstCapacity*
| capacity of `dstBuffer` in `unsigned short`s
| *srcString*
| null&hyphen;terminated UTF&hyphen;8 input
| *numCharsWritten*
| if non&hyphen;null, receives character count written
| *errorCharacter*
| substitute for invalid input&semi; 0 skips them
|===


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