Character Encoding

cCharTranslate

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

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

The following functions have been added. Note that any of  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

Note 1: Are single character string types and can be eCharType can be CP_ACP (ANSI), CP_OEMCP (OEM) or CP_UTF8 (UTF-8).

Note 2: Variant string data types are used here because they have two useful characteristics. They always store string data as Unicode (UTF16) and 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 the string 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 you cSeqFileHelper.

cSeqFileHelper

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 and you can read and write 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 you means of store strings then you are storing these as UTF16 and you 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 base64encoding.

 

See Also

What's New in DataFlex 2014 - 18.0