BloombergLP::bdlde::CharConvertUcs2::ucs2ToUtf8

Load into result the UTF-8 conversion of the null-terminated UCS-2 srcString.

Synopsis

Declared in <bdlde_charconvertucs2.h>

static
int
ucs2ToUtf8(
    bsl::string* result,
    unsigned short const* srcString,
    std::size_t* numCharsWritten = 0);

Description

Load, into the specified result, the conversion of the specified null-terminated UCS-2 srcString to its UTF-8 equivalent. Optionally specify numCharsWritten which (if not 0) indicates the modifiable integer into which the number of characters written (including the null terminator) is to be loaded. Return 0 on success and CharConvertStatus::k_INVALID_INPUT_BIT otherwise, meaning that at least one sequence of characters was encountered that could not be translated to UTF-8. The behavior is undefined unless srcString is null-terminated. Note that the null-terminating character is not counted in result->length(). Also note that this function does not currently implement failure modes; however, this could change if UTF-8 input validation is added.

Return Value

0 on success and CharConvertStatus::k_INVALID_INPUT_BIT otherwise

Parameters

NameDescription
resultoutput string for the UTF-8 conversion
srcStringnull-terminated UCS-2 input
numCharsWrittenif non-null, receives character count written