Skip to content

OemToUtf8Buffer

See Also: Utf8ToOemBuffer, Free, String Functions

Purpose

Converts an OEM string to UTF-8.

Return Type

Pointer

Syntax

Use CharTranslate.pkg
(OemToUtf8Buffer({pOemBuf}, {iLen}))

Where:

  • {pOemBuf}: A pointer to the string buffer to be converted.
  • {iLen}: The length, in bytes, of the string pointed to by {pOemBuf}.

What It Does

OemToUtf8Buffer converts a string of OEM characters to UTF-8 and returns a pointer to a newly allocated string buffer containing the converted text.

Examples

// Translate data. pass: Data and translation mode.
// Returns pointer to new translated data; 0 if no translation is needed.
// Passed data is not changed.
// eXlt can be: xtUtf8toOem, xtOemtoUtf8, and xtNoTranslate
Function TranslateData Integer eXlt Pointer aData Integer iDataLen Returns Pointer
    Pointer aDataXlt

    Case Begin
        case (eXlt = xtUtf8toOem)
            Move (Utf8toOemBuffer(aData, iDataLen)) to aDataXlt
        case Break

        case (eXlt = xtOemtoUtf8)
            Move (OemToUtf8Buffer(aData, iDataLen)) to aDataXlt
        case Break

        case else
            Move 0 to aDataXlt
    Case End

    Function_Return aDataXlt
End_Function

Notes

OemToUtf8Buffer will allocate a new block of memory to store the converted string. A pointer to this memory is returned by the function. You must use Free to de-allocate this memory when it is no longer required. Failure to do this will cause a memory leak in your application.