Main Content

matlab::cpplib::convertUTF8StringToUTF16String

Convert UTF-8 string to UTF-16 string

Description

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

Convert a UTF-8 string (ASCII or Unicode®) to a UTF-16 string. Use this function to convert ASCII strings into the form required to represent startup options (passed to initMATLABApplication), or function names or matlab::data::array.

Prefixing u to a literal char * string is a more concise alternative that achieves the same effect as convertUTF8StringToUTF16String when a literal string is passed as a parameter. For example, you could write initMATLABLibrary(app, u"mylib"); rather than the lengthier initMATLABLibrary(app, convertUTF8StringToUTF16String("mylib")); and get the same results.

Note

Prefixing u is not supported by Visual C++® 2013.

Parameters

const std::string & str

A UTF-8 (possibly ASCII) string.

Return Value

std::u16string

A UTF-16-encoded string.

Exceptions

std::range_error

Input is not a valid UTF-8 string.

Examples

Convert UTF-8 String to UTF-16 String

auto app = initMATLABApplication(MATLABApplicationMode::IN_PROCESS);
const char * libName = getLibNameFromConfigFile(); // imaginary user-defined function
auto mylib = initMATLABLibrary(app, convertUTF8StringToUTF16String(libName));

Version History

Introduced in R2018a