|
nux-1.14.0
|
Public Member Functions | |
| ANSICHAR * | Convert (const UNICHAR *Source) |
Definition at line 183 of file NUnicode.h.
| ANSICHAR * nux::UnicharToAnsicharConvertion::Convert | ( | const UNICHAR * | Source | ) |
Convert from UNICHAR to ANSICHAR
| Source | String to convert. Null terminated. |
Definition at line 30 of file NUnicode.cpp.
Referenced by nux::TCharToAnsiConvertion::Convert().
{
std::wstring utf16string (Source);
size_t utf16size = utf16string.length();
size_t utf8size = 6 * utf16size;
ANSICHAR *utf8string = new ANSICHAR[utf8size+1];
const t_UTF16 *source_start = utf16string.c_str();
const t_UTF16 *source_end = source_start + utf16size;
t_UTF8 *target_start = reinterpret_cast<t_UTF8 *> (utf8string);
t_UTF8 *target_end = target_start + utf8size;
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
delete [] utf8string;
utf8string = 0;
}
// mark end of string
*target_start = 0;
return utf8string;
}