nux-1.14.0
nux::UnicharToAnsicharConvertion Class Reference

List of all members.

Public Member Functions

ANSICHAR * Convert (const UNICHAR *Source)

Detailed Description

Definition at line 183 of file NUnicode.h.


Member Function Documentation

ANSICHAR * nux::UnicharToAnsicharConvertion::Convert ( const UNICHAR *  Source)

Convert from UNICHAR to ANSICHAR

Parameters:
SourceString to convert. Null terminated.
Returns:
Return a pointer to the new string. 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;
  }

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends