Documentation

matlab::cpplib::convertUTF16StringToUTF8String

Convert UTF-16 string to UTF-8 string

Description

std::string & str convertUTF16StringToUTF8String(const std::u16string & ustr)

Convert a UTF-16 string to a UTF-8 string. Since ASCII is a subset of UTF-8 encoding, the output is ASCII content as long as no non-ASCII characters are present in the input.

Parameters

const std::u16string & ustr

A UTF-16 string.

Return Value

std::string

A UTF-8 string.

Exceptions

std::range_error

Input is not valid UTF-16 string.

Examples

Convert a UTF-16 String to UTF-8 String

auto app = initMATLABApplication(MATLABApplicationMode::OUT_OF_PROCESS);
auto mylib = initMATLABLibrary(app, convertUTF8StringToUTF16String("mylib"));
std::u16string ustr = mylib->feval<std::u16string>("get_const_str");
std::string str = convertUTF16StringToUTF8String(ustr);

Introduced in R2017b