Charset C Library Reference

Charset

A C library/class for converting character data from one encoding to another. This software is unique in that the data required for converting to/from the supported charsets is entirely embedded witin the Chilkat DLL/library. It does not depend on what code pages may or may not be installed on a particular computer. This allows programs to operate correctly regardless of the locale, OS version, or other factors.

Create/Dispose

HCkCharset CkCharset_Create(void);

Creates an instance of the CkCharset object and returns a handle (i.e. a "void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkCharset_Dispose(HCkCharset handle);

Objects created by calling CkCharset_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

C "Properties"

void CkCharset_getAltToCharset(HCkCharset handle, HCkString retval);
void CkCharset_putAltToCharset(HCkCharset handle, const char *newVal);

If the ErrorAction property is set to 6, then this property controls how errors are handled. It specifies an alternate "To" charset. When a character in the input data cannot be converted to the target charset, an attempt is made to convert it to the AltToCharset. If that fails, the input character is dropped.

int CkCharset_getErrorAction(HCkCharset handle);
void CkCharset_putErrorAction(HCkCharset handle, int newVal);

Controls how errors are handled. When a character in the input data cannot be converted to the target charset, the action taken is controlled by this property. The possible settings are: (0) drop the error characters, (1) substitute the data set by the SetErrorBytes or SetErrorString method, (2) convert to a hex-escaped string (&#xXXXX), (3) RESERVED, (4) RESERVED, (5) RESERVED, (6) convert the error character to the AltToCharset instead, if that fails then drop the character, (7) Pass non-convertible characters to the output unchanged.

void CkCharset_getFromCharset(HCkCharset handle, HCkString retval);
void CkCharset_putFromCharset(HCkCharset handle, const char *newVal);

Tells the charset converter the charset of the input data for a conversion. Possible values are:


us-ascii
unicode
unicodefffe
iso-8859-1
iso-8859-2
iso-8859-3
iso-8859-4
iso-8859-5
iso-8859-6
iso-8859-7
iso-8859-8
iso-8859-9
iso-8859-13
iso-8859-15
windows-874
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
utf-7
utf-8
utf-32
utf-32be
shift_jis
gb2312
ks_c_5601-1987
big5
iso-2022-jp
iso-2022-kr
euc-jp
euc-kr
macintosh
x-mac-japanese
x-mac-chinesetrad
x-mac-korean
x-mac-arabic
x-mac-hebrew
x-mac-greek
x-mac-cyrillic
x-mac-chinesesimp
x-mac-romanian
x-mac-ukrainian
x-mac-thai
x-mac-ce
x-mac-icelandic
x-mac-turkish
x-mac-croatian
asmo-708
dos-720
dos-862
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u

void CkCharset_getLastErrorHtml(HCkCharset handle, HCkString retval);

Error information in HTML format for the last method called.

void CkCharset_getLastErrorText(HCkCharset handle, HCkString retval);

Error information in plain-text format for the last method called.

void CkCharset_getLastErrorXml(HCkCharset handle, HCkString retval);

Error information in XML format for the last method called.

void CkCharset_getLastInputAsHex(HCkCharset handle, HCkString retval);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last input data in a hexidecimalized string.

void CkCharset_getLastInputAsQP(HCkCharset handle, HCkString retval);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last input data in a quoted-printable string.

void CkCharset_getLastOutputAsHex(HCkCharset handle, HCkString retval);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last output data in a hexidecimalized string.

void CkCharset_getLastOutputAsQP(HCkCharset handle, HCkString retval);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last output data in a quoted-printable string.

BOOL CkCharset_getSaveLast(HCkCharset handle);
void CkCharset_putSaveLast(HCkCharset handle, BOOL newVal);

Tells the component to keep the input/output byte data in memory after a conversion is complete so the data can be examined via the LastInputAsHex/QP and LastOutputAsHex/QP properties. (for debugging purposes)

void CkCharset_getToCharset(HCkCharset handle, HCkString retval);
void CkCharset_putToCharset(HCkCharset handle, const char *newVal);

Tells the charset converter the target charset for a conversion. Possible values are:


us-ascii
unicode
unicodefffe
iso-8859-1
iso-8859-2
iso-8859-3
iso-8859-4
iso-8859-5
iso-8859-6
iso-8859-7
iso-8859-8
iso-8859-9
iso-8859-13
iso-8859-15
windows-874
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
utf-7
utf-8
utf-32
utf-32be
shift_jis
gb2312
ks_c_5601-1987
big5
iso-2022-jp
iso-2022-kr
euc-jp
euc-kr
macintosh
x-mac-japanese
x-mac-chinesetrad
x-mac-korean
x-mac-arabic
x-mac-hebrew
x-mac-greek
x-mac-cyrillic
x-mac-chinesesimp
x-mac-romanian
x-mac-ukrainian
x-mac-thai
x-mac-ce
x-mac-icelandic
x-mac-turkish
x-mac-croatian
asmo-708
dos-720
dos-862
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u

BOOL CkCharset_getUtf8(HCkCharset handle);
void CkCharset_putUtf8(HCkCharset handle, BOOL newVal);

When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.

void CkCharset_getVersion(HCkCharset handle, HCkString retval);

Returns the version of the component, such as "9.0.0"

C "Methods"

int CkCharset_CharsetToCodePage(HCkCharset handle, const char *charsetName);

Converts a charset name to a code page number. For example, "iso-8859-1" converts to code page 28591.

BOOL CkCharset_CodePageToCharset(HCkCharset handle, int codePage, HCkString sCharset);

Converts a code page number to a charset name. For example, 65001 converts to "utf-8".

BOOL CkCharset_ConvertData(HCkCharset handle, HCkByteData inData, HCkByteData outData);

Converts character data from one charset to another. Before calling ConvertData, the FromCharset and ToCharset properties must be set to the source and destination charset names, such as "iso-8859-1" or "Shift_JIS".

BOOL CkCharset_ConvertData(HCkCharset handle, const unsigned char *inData, unsigned long inDataLen, HCkByteData outData);

Converts character data from one charset to another. Before calling ConvertData, the FromCharset and ToCharset properties must be set to the source and destination charset names, such as "iso-8859-1" or "Shift_JIS".

BOOL CkCharset_ConvertData(HCkCharset handle, const unsigned char *inData, unsigned long inDataLen, unsigned char *outData, unsigned long *outDataLen);

Converts character data from one charset to another. Before calling ConvertData, the FromCharset and ToCharset properties must be set to the source and destination charset names, such as "iso-8859-1" or "Shift_JIS".

BOOL CkCharset_ConvertFile(HCkCharset handle, const char *inFilename, const char *outFilename);

Converts a file from one character encoding to another. The FromCharset and ToCharset properties must be set to the source and destination character encodings before calling this method.

BOOL CkCharset_ConvertFromUnicode(HCkCharset handle, HCkByteData uniData, HCkByteData mbData);

Converts Unicode text to the charset specified by the ToCharset property.

BOOL CkCharset_ConvertFromUnicode(HCkCharset handle, const unsigned char *data, unsigned long dataLen, HCkByteData mbData);

Converts Unicode text to the charset specified by the ToCharset property.

BOOL CkCharset_ConvertHtml(HCkCharset handle, HCkByteData htmlIn, HCkByteData htmlOut);

Converts HTML text from one character encoding to another. The FromCharset and ToCharset properties must be set prior to calling this method. This method automatically edits the META tag within the HTML that indicates the charset.

BOOL CkCharset_ConvertHtml(HCkCharset handle, const unsigned char *htmlIn, unsigned long htmlInLen, HCkByteData htmlOut);

Converts HTML text from one character encoding to another. The FromCharset and ToCharset properties must be set prior to calling this method. This method automatically edits the META tag within the HTML that indicates the charset.

BOOL CkCharset_ConvertHtmlFile(HCkCharset handle, const char *inFilename, const char *outFilename);

Converts an HTML file from one character encoding to another. The FromCharset and ToCharset properties must be set prior to calling this method. This method automatically edits the META tag within the HTML that indicates the charset.

BOOL CkCharset_ConvertToUnicode(HCkCharset handle, HCkByteData mbData, HCkByteData uniData);

Converts multibyte character data to a Unicode string. The FromCharset property should be set before calling this method.

BOOL CkCharset_ConvertToUnicode(HCkCharset handle, const unsigned char *data, unsigned long dataLen, HCkByteData uniData);

Converts multibyte character data to a Unicode string. The FromCharset property should be set before calling this method.

void CkCharset_EntityEncodeDec(HCkCharset handle, const char *inStr, HCkString outStr);

To be documented soon...

void CkCharset_EntityEncodeHex(HCkCharset handle, const char *inStr, HCkString outStr);

To be documented soon...

BOOL CkCharset_GetHtmlCharset(HCkCharset handle, HCkByteData htmlData, HCkString strCharset);

Examines HTML text and extracts the charset name specified by the META tag, if present.

BOOL CkCharset_GetHtmlCharset(HCkCharset handle, const unsigned char *htmlData, unsigned long htmlDataLen, HCkString strCharset);

Examines HTML text and extracts the charset name specified by the META tag, if present.

BOOL CkCharset_GetHtmlFileCharset(HCkCharset handle, const char *htmlFilename, HCkString strCharset);

Examines an HTML file and extracts the charset name specified by the META tag, if present.

BOOL CkCharset_HtmlDecodeToStr(HCkCharset handle, const char *str, HCkString strOut);

Converts HTML entities to Unicode characters.

BOOL CkCharset_HtmlEntityDecode(HCkCharset handle, HCkByteData inData, HCkByteData outData);

Decodes HTML entities. See http://www.w3.org/TR/REC-html40/sgml/entities.html for information on HTML entities. Examples of HTML entities are < , å , å , 水 , Í , etc.

BOOL CkCharset_HtmlEntityDecodeFile(HCkCharset handle, const char *inFilename, const char *outFilename);

Decodes HTML entities in a file and creates a new HTML file with the entities decoded. See http://www.w3.org/TR/REC-html40/sgml/entities.html for information on HTML entities. Examples of HTML entities are < , å , å , 水 , Í , etc.

Returns TRUE for success, FALSE for failure.

BOOL CkCharset_IsUnlocked(HCkCharset handle);

Returns true if the component is unlocked.

void CkCharset_LowerCase(HCkCharset handle, const char *inStr, HCkString outStr);

To be documented soon...

BOOL CkCharset_ReadFile(HCkCharset handle, const char *filename, HCkByteData dataBuf);

Convenience method for reading the entire contents of a file into a byte array.

BOOL CkCharset_SaveLastError(HCkCharset handle, const char *filename);

Saves the last error information to an XML formatted file.

void CkCharset_SetErrorBytes(HCkCharset handle, const unsigned char *data, unsigned long dataLen);

If the ErrorAction property is set to 1, the bytes passed to this method are used as the result for any characters that cannot be converted during a conversion.

void CkCharset_SetErrorString(HCkCharset handle, const char *str);

If the ErrorAction property is set to 1, the string passed to this method is used as the result for any characters that cannot be converted during a conversion.

BOOL CkCharset_UnlockComponent(HCkCharset handle, const char *unlockCode);

Unlocks the component. This method must be called once at the beginning of the program. Properties can be get/set without unlocking, but methods will not work unless the component has been unlocked.

void CkCharset_UpperCase(HCkCharset handle, const char *inStr, HCkString outStr);

To be documented soon...

BOOL CkCharset_VerifyData(HCkCharset handle, const char *charset, HCkByteData charData);

Returns true if the byte data conforms to the charset passed in the first argument.

BOOL CkCharset_VerifyFile(HCkCharset handle, const char *charset, const char *filename);

Returns true if the file contains character data that conforms to the charset passed in the 1st argument.

BOOL CkCharset_WriteFile(HCkCharset handle, const char *filename, HCkByteData dataBuf);

Convenience method for saving an entire byte array to a file.

BOOL CkCharset_WriteFile(HCkCharset handle, const char *filename, const unsigned char *data, unsigned long dataLen);

Convenience method for saving an entire byte array to a file.

const char *CkCharset_altToCharset(HCkCharset handle);

If the ErrorAction property is set to 6, then this property controls how errors are handled. It specifies an alternate "To" charset. When a character in the input data cannot be converted to the target charset, an attempt is made to convert it to the AltToCharset. If that fails, the input character is dropped.

const char *CkCharset_codePageToCharset(HCkCharset handle, int codePage);

Converts a code page number to a charset name. For example, 65001 converts to "utf-8".

const char *CkCharset_entityEncodeDec(HCkCharset handle, const char *inStr);

To be documented soon...

const char *CkCharset_entityEncodeHex(HCkCharset handle, const char *inStr);

To be documented soon...

const char *CkCharset_fromCharset(HCkCharset handle);

Tells the charset converter the charset of the input data for a conversion. Possible values are:


us-ascii
unicode
unicodefffe
iso-8859-1
iso-8859-2
iso-8859-3
iso-8859-4
iso-8859-5
iso-8859-6
iso-8859-7
iso-8859-8
iso-8859-9
iso-8859-13
iso-8859-15
windows-874
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
utf-7
utf-8
utf-32
utf-32be
shift_jis
gb2312
ks_c_5601-1987
big5
iso-2022-jp
iso-2022-kr
euc-jp
euc-kr
macintosh
x-mac-japanese
x-mac-chinesetrad
x-mac-korean
x-mac-arabic
x-mac-hebrew
x-mac-greek
x-mac-cyrillic
x-mac-chinesesimp
x-mac-romanian
x-mac-ukrainian
x-mac-thai
x-mac-ce
x-mac-icelandic
x-mac-turkish
x-mac-croatian
asmo-708
dos-720
dos-862
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u

const char *CkCharset_getHtmlCharset(HCkCharset handle, HCkByteData htmlData);

Examines HTML text and extracts the charset name specified by the META tag, if present.

const char *CkCharset_getHtmlCharset(HCkCharset handle, const unsigned char *htmlData, unsigned long htmlDataLen);

Examines HTML text and extracts the charset name specified by the META tag, if present.

const char *CkCharset_getHtmlFileCharset(HCkCharset handle, const char *htmlFilename);

Examines an HTML file and extracts the charset name specified by the META tag, if present.

const char *CkCharset_htmlDecodeToStr(HCkCharset handle, const char *str);

Converts HTML entities to Unicode characters.

const char *CkCharset_lastErrorHtml(HCkCharset handle);

Error information in HTML format for the last method called.

const char *CkCharset_lastErrorText(HCkCharset handle);

Error information in plain-text format for the last method called.

const char *CkCharset_lastErrorXml(HCkCharset handle);

Error information in XML format for the last method called.

const char *CkCharset_lastInputAsHex(HCkCharset handle);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last input data in a hexidecimalized string.

const char *CkCharset_lastInputAsQP(HCkCharset handle);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last input data in a quoted-printable string.

const char *CkCharset_lastOutputAsHex(HCkCharset handle);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last output data in a hexidecimalized string.

const char *CkCharset_lastOutputAsQP(HCkCharset handle);

If SaveLast is set to true, then the input and output of a conversion is saved to allow the exact bytes that are sent to the converter to be seen (for debugging purposes). This property shows the last output data in a quoted-printable string.

const char *CkCharset_lowerCase(HCkCharset handle, const char *inStr);

To be documented soon...

const char *CkCharset_toCharset(HCkCharset handle);

Tells the charset converter the target charset for a conversion. Possible values are:


us-ascii
unicode
unicodefffe
iso-8859-1
iso-8859-2
iso-8859-3
iso-8859-4
iso-8859-5
iso-8859-6
iso-8859-7
iso-8859-8
iso-8859-9
iso-8859-13
iso-8859-15
windows-874
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
utf-7
utf-8
utf-32
utf-32be
shift_jis
gb2312
ks_c_5601-1987
big5
iso-2022-jp
iso-2022-kr
euc-jp
euc-kr
macintosh
x-mac-japanese
x-mac-chinesetrad
x-mac-korean
x-mac-arabic
x-mac-hebrew
x-mac-greek
x-mac-cyrillic
x-mac-chinesesimp
x-mac-romanian
x-mac-ukrainian
x-mac-thai
x-mac-ce
x-mac-icelandic
x-mac-turkish
x-mac-croatian
asmo-708
dos-720
dos-862
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u

const char *CkCharset_upperCase(HCkCharset handle, const char *inStr);

To be documented soon...

const char *CkCharset_version(HCkCharset handle);

Returns the version of the component, such as "9.0.0"