Skip to content

Character Encoding

Documentation is still in progress. This class has not yet been added to the class reference.

The cCharTranslate class contains a number of character translation/encoding functions that allow you to convert strings into different formats. It also provides mechanisms for storing this data in memory buffers and variant data types.

Functions

The following functions have been added. Note that any functions that work with memory buffers (those with Address parameters) will probably require that you manage the disposal of these memory allocations yourself using the Free() function.

Function ValidStringBufferLength Address aData Returns Boolean
Function Utf16FromBuffer Address pMultiCharBuffer Integer eCharType Integer ByRef iLen Returns Address
Function Utf16ToBuffer Address pWideBuf Integer eCharType Integer iLen Returns Address
Function Utf16FromStr String sValue Integer eCharType Integer ByRef iLen Returns Address
Function Utf16ToStr Address pWideBuf Integer eCharType Integer iLen Returns String
Function Utf8FromBuffer Address pMultiCharBuffer Integer eCharType Returns Address
Function Utf8FromStr String sValue Integer eCharType Returns Address
Function Utf8ToBuffer Address pMultiCharBuffer Integer eCharType Returns Address
Function Utf8ToStr Address pWideBuf Integer eCharType Returns String
Function VariantStrToBuffer Variant vValue Integer eCharType Returns Address
Function VariantStrToStr Variant vValue Integer eCharType Returns String
Function VariantStrFromBuffer Address aSource Integer eCodeType Returns Variant
Function VariantStrFromStr String sValue Integer eCodeType Returns Variant
Function VariantStrToUTF16 Variant vValue Integer ByRef iLen Returns Address
Function VariantStrFromUTF16 Address aSource Returns Variant
Function VariantStrToBuffer Variant vValue Integer eCharType Returns Address
Function VariantStrToStr Variant vValue Integer eCharType Returns String
Function VariantStrFromBuffer Address aSource Integer eCodeType Returns Variant
Function VariantStrFromStr String sValue Integer eCodeType Returns Variant
Function VariantStrToUTF16 Variant vValue Integer ByRef iLen Returns Address
Function VariantStrFromUTF16 Address aSource Returns Variant
Function Base64EncodeToStr Address aText Integer iLen Returns String
Function Base64DecodeFromStr String sBase64 Integer ByRef iLen Returns Address
Function Base64EncodeToVariantStr Address aChar Integer iCharLen Returns Variant
Function Base64DecodeFromVariantStr Variant vVar Integer ByRef iCharLen Returns Address

Notes

  1. The single character string types can be eCharType, which can be CP_ACP (ANSI), CP_OEMCP (OEM), or CP_UTF8 (UTF-8).

  2. Variant string data types are used here because they have two useful characteristics:

  3. They always store string data as Unicode (UTF16).
  4. There is no string size limitation.

However, if you move a Variant string to a DataFlex String, the string is always converted to OEM and can only be as long as Argument_Size. You can, however, read and write these to an XML document using pvNodeValue, and you can read and write these to sequential files using cSeqFileHelper.

File Handling Functions

Documentation is still in progress. This class has not yet been added to the class reference.

This provides helper functions to make it easier to read and write files in various formats. You can read and write binary files, as well as UTF16, UTF8, OEM, and ANSI files. This adds:

Function ReadBinFileToBuffer String sName Integer ByRef iSize Returns Address
Procedure WriteBinFileFromBuffer String sName Address aData Integer iSize
Function ReadFileToVariantStr String sName Integer eInEncoding Returns Variant
Procedure WriteFileFromVariantStr String sName Integer eInEncoding Variant VDat

This works in conjunction with the cCharTranslate package and the Flexml changes (get/set pvNodeValue), which gives you a lot of flexibility. If you are using variants as your means of storing strings, then you are storing these as UTF16 and can store strings of any size. You can move these in and out of XML documents and files without going through an OEM translation, and you can convert data between OEM, ANSI, UTF8, UTF16, and base64 encoding.

See Also

What's New in DataFlex 2014 - 18.0