Charset C Reference Documentation

Charset

Current Version: 10.0.0

A component/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 instance = CkCharset_Create();
// ...
CkCharset_Dispose(instance);
HCkCharset CkCharset_Create(void);

Creates an instance of the HCkCharset object and returns a handle ("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. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkCharset_Dispose.

Properties

AltToCharset
void CkCharset_getAltToCharset(HCkCharset cHandle, HCkString retval);
void CkCharset_putAltToCharset(HCkCharset cHandle, const char *newVal);
const char *CkCharset_altToCharset(HCkCharset cHandle);

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.

top
DebugLogFilePath
void CkCharset_getDebugLogFilePath(HCkCharset cHandle, HCkString retval);
void CkCharset_putDebugLogFilePath(HCkCharset cHandle, const char *newVal);
const char *CkCharset_debugLogFilePath(HCkCharset cHandle);

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

More Information and Examples
top
ErrorAction
int CkCharset_getErrorAction(HCkCharset cHandle);
void CkCharset_putErrorAction(HCkCharset cHandle, 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.

top
FromCharset
void CkCharset_getFromCharset(HCkCharset cHandle, HCkString retval);
void CkCharset_putFromCharset(HCkCharset cHandle, const char *newVal);
const char *CkCharset_fromCharset(HCkCharset cHandle);

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

<font size="2" face="MS Sans Serif">
us-ascii
unicode  (also known as UTF16LE or simply UTF16)
unicodefffe  (also known as UTF16BE)
ebcdic
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
ibm01140
ibm01141
ibm01142
ibm01143
ibm01144
ibm01145
ibm01146
ibm01147
ibm01148
ibm01149
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
</font>

top
LastErrorHtml
void CkCharset_getLastErrorHtml(HCkCharset cHandle, HCkString retval);
const char *CkCharset_lastErrorHtml(HCkCharset cHandle);

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorText
void CkCharset_getLastErrorText(HCkCharset cHandle, HCkString retval);
const char *CkCharset_lastErrorText(HCkCharset cHandle);

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastErrorXml
void CkCharset_getLastErrorXml(HCkCharset cHandle, HCkString retval);
const char *CkCharset_lastErrorXml(HCkCharset cHandle);

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastInputAsHex
void CkCharset_getLastInputAsHex(HCkCharset cHandle, HCkString retval);
const char *CkCharset_lastInputAsHex(HCkCharset cHandle);

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.

top
LastInputAsQP
void CkCharset_getLastInputAsQP(HCkCharset cHandle, HCkString retval);
const char *CkCharset_lastInputAsQP(HCkCharset cHandle);

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.

top
LastMethodSuccess
BOOL CkCharset_getLastMethodSuccess(HCkCharset cHandle);
void CkCharset_putLastMethodSuccess(HCkCharset cHandle, BOOL newVal);

Indicate whether the last method call succeeded or failed. A value of TRUE indicates success, a value of FALSE indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = TRUE and failure = FALSE.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to TRUE. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

top
LastOutputAsHex
void CkCharset_getLastOutputAsHex(HCkCharset cHandle, HCkString retval);
const char *CkCharset_lastOutputAsHex(HCkCharset cHandle);

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.

top
LastOutputAsQP
void CkCharset_getLastOutputAsQP(HCkCharset cHandle, HCkString retval);
const char *CkCharset_lastOutputAsQP(HCkCharset cHandle);

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.

top
SaveLast
BOOL CkCharset_getSaveLast(HCkCharset cHandle);
void CkCharset_putSaveLast(HCkCharset cHandle, 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)

top
ToCharset
void CkCharset_getToCharset(HCkCharset cHandle, HCkString retval);
void CkCharset_putToCharset(HCkCharset cHandle, const char *newVal);
const char *CkCharset_toCharset(HCkCharset cHandle);

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

<font size="2" face="MS Sans Serif">
us-ascii
unicode  (also known as UTF16LE or simply UTF16)
unicodefffe  (also known as UTF16BE)
ebcdic
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
ibm01140
ibm01141
ibm01142
ibm01143
ibm01144
ibm01145
ibm01146
ibm01147
ibm01148
ibm01149
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
</font>

top
Utf8
BOOL CkCharset_getUtf8(HCkCharset cHandle);
void CkCharset_putUtf8(HCkCharset cHandle, BOOL newVal);

When set to TRUE, all "const char *" arguments are interpreted as utf-8 strings. If set to FALSE (the default), then "const char *" arguments are interpreted as ANSI strings. Also, when set to TRUE, and Chilkat method returning a "const char *" is returning the utf-8 representation. If set to FALSE, all "const char *" return values are ANSI strings.

top
VerboseLogging
BOOL CkCharset_getVerboseLogging(HCkCharset cHandle);
void CkCharset_putVerboseLogging(HCkCharset cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
void CkCharset_getVersion(HCkCharset cHandle, HCkString retval);
const char *CkCharset_version(HCkCharset cHandle);

Version of the component/library, such as "9.5.0.94"

More Information and Examples
top

Methods

CharsetToCodePage
int CkCharset_CharsetToCodePage(HCkCharset cHandle, const char *charsetName);

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

top
CodePageToCharset
BOOL CkCharset_CodePageToCharset(HCkCharset cHandle, int codePage, HCkString outCharset);
const char *CkCharset_codePageToCharset(HCkCharset cHandle, int codePage);

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

Returns TRUE for success, FALSE for failure.

top
ConvertData
BOOL CkCharset_ConvertData(HCkCharset cHandle, 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".

Returns TRUE for success, FALSE for failure.

top
ConvertFile
BOOL CkCharset_ConvertFile(HCkCharset cHandle, const char *inPath, const char *destPath);

Converts a file from one character encoding to another. The FromCharset and ToCharset properties specify the source and destination character encodings. If the ToCharset is utf-16 or utf-8, then the preamble (also known as BOM) is included in the output. (Call ConvertFileNoPreamble to suppress the output of the BOM.)

Returns TRUE for success, FALSE for failure.

top
ConvertFileNoPreamble
BOOL CkCharset_ConvertFileNoPreamble(HCkCharset cHandle, const char *inPath, const char *destPath);

Converts a file from one character encoding to another. The FromCharset and ToCharset properties specify the source and destination character encodings. No preamble (also known as BOM) is included in the output.

top
ConvertFromUnicode
BOOL CkCharset_ConvertFromUnicode(HCkCharset cHandle, const char *inData, HCkByteData outBytes);

Converts Unicode (utf-16) text to the charset specified by the ToCharset property.

Returns TRUE for success, FALSE for failure.

top
ConvertFromUtf16
BOOL CkCharset_ConvertFromUtf16(HCkCharset cHandle, HCkByteData uniData, HCkByteData outMbData);

Converts utf-16 text to the charset specified by the ToCharset property.

Returns TRUE for success, FALSE for failure.

top
ConvertHtml
BOOL CkCharset_ConvertHtml(HCkCharset cHandle, HCkByteData inData, HCkByteData outHtml);

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.

Returns TRUE for success, FALSE for failure.

top
ConvertHtmlFile
BOOL CkCharset_ConvertHtmlFile(HCkCharset cHandle, const char *inPath, const char *destPath);

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

Returns TRUE for success, FALSE for failure.

top
ConvertToUnicode
BOOL CkCharset_ConvertToUnicode(HCkCharset cHandle, HCkByteData inData, HCkString outStr);
const char *CkCharset_convertToUnicode(HCkCharset cHandle, HCkByteData inData);

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

Returns TRUE for success, FALSE for failure.

top
ConvertToUtf16
BOOL CkCharset_ConvertToUtf16(HCkCharset cHandle, HCkByteData mbData, HCkByteData outUniData);

Converts the mbData to utf-16 bytes.

Returns TRUE for success, FALSE for failure.

top
EntityEncodeDec
BOOL CkCharset_EntityEncodeDec(HCkCharset cHandle, const char *str, HCkString outStr);
const char *CkCharset_entityEncodeDec(HCkCharset cHandle, const char *str);

Converts non-US-ASCII characters to Unicode decimal entities (&#xxxxx;)

Returns TRUE for success, FALSE for failure.

top
EntityEncodeHex
BOOL CkCharset_EntityEncodeHex(HCkCharset cHandle, const char *str, HCkString outStr);
const char *CkCharset_entityEncodeHex(HCkCharset cHandle, const char *str);

Converts non-US-ASCII characters to Unicode hex entities (&#xXXXX;)

Returns TRUE for success, FALSE for failure.

top
GetHtmlCharset
BOOL CkCharset_GetHtmlCharset(HCkCharset cHandle, HCkByteData inData, HCkString outCharset);
const char *CkCharset_getHtmlCharset(HCkCharset cHandle, HCkByteData inData);

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

Returns TRUE for success, FALSE for failure.

top
GetHtmlFileCharset
BOOL CkCharset_GetHtmlFileCharset(HCkCharset cHandle, const char *htmlFilePath, HCkString outCharset);
const char *CkCharset_getHtmlFileCharset(HCkCharset cHandle, const char *htmlFilePath);

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

Returns TRUE for success, FALSE for failure.

top
HtmlDecodeToStr
BOOL CkCharset_HtmlDecodeToStr(HCkCharset cHandle, const char *inStr, HCkString outStr);
const char *CkCharset_htmlDecodeToStr(HCkCharset cHandle, const char *inStr);

Converts HTML entities to Unicode characters.

Returns TRUE for success, FALSE for failure.

top
HtmlEntityDecode
BOOL CkCharset_HtmlEntityDecode(HCkCharset cHandle, HCkByteData inHtml, 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 &lt; , &#229; , &#xE5; , &#x6C34; , &Iacute; , etc.

Returns TRUE for success, FALSE for failure.

top
HtmlEntityDecodeFile
BOOL CkCharset_HtmlEntityDecodeFile(HCkCharset cHandle, const char *inPath, const char *destPath);

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 &lt; , &#229; , &#xE5; , &#x6C34; , &Iacute; , etc.

Returns TRUE for success, FALSE for failure.

top
LowerCase
BOOL CkCharset_LowerCase(HCkCharset cHandle, const char *inStr, HCkString outStr);
const char *CkCharset_lowerCase(HCkCharset cHandle, const char *inStr);

Converts a string to lowercase.

Returns TRUE for success, FALSE for failure.

top
ReadFile
BOOL CkCharset_ReadFile(HCkCharset cHandle, const char *path, HCkByteData outData);

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

Returns TRUE for success, FALSE for failure.

top
ReadFileToString
BOOL CkCharset_ReadFileToString(HCkCharset cHandle, const char *path, const char *charset, HCkString outStr);
const char *CkCharset_readFileToString(HCkCharset cHandle, const char *path, const char *charset);

Reads a text file and returns the text converted to a Unicode string. The filename is specified by the first method argument, and the charset of the text data is specified by the 2nd method argument.

Returns TRUE for success, FALSE for failure.

top
SetErrorBytes
void CkCharset_SetErrorBytes(HCkCharset cHandle, HCkByteData data);

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.

top
SetErrorString
void CkCharset_SetErrorString(HCkCharset cHandle, const char *str, const char *charset);

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.

top
UpperCase
BOOL CkCharset_UpperCase(HCkCharset cHandle, const char *inStr, HCkString outStr);
const char *CkCharset_upperCase(HCkCharset cHandle, const char *inStr);

Converts a string to uppercase.

Returns TRUE for success, FALSE for failure.

top
UrlDecodeStr
BOOL CkCharset_UrlDecodeStr(HCkCharset cHandle, const char *inStr, HCkString outStr);
const char *CkCharset_urlDecodeStr(HCkCharset cHandle, const char *inStr);

URL decodes a string.

This method assumes the ANSI byte representation was used for encoding. For example, the letter É, where the ANSI charset is Latin-1, would appear as "%C9" when URL encoded. (As opposed to the utf-8 encoding where É is represented by 2 bytes 0xC3, 0x89 and would appear as "%C3%89" when URl encoded. This method assumes ANSI encoding.

You can use encoding/decoding methods in Chilkat's StringBuilder class to specify the charset from which to decode or encode.

Returns TRUE for success, FALSE for failure.

top
VerifyData
BOOL CkCharset_VerifyData(HCkCharset cHandle, const char *charset, HCkByteData inData);

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

top
VerifyFile
BOOL CkCharset_VerifyFile(HCkCharset cHandle, const char *charset, const char *path);

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

top
WriteFile
BOOL CkCharset_WriteFile(HCkCharset cHandle, const char *path, HCkByteData byteData);

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

top
WriteStringToFile
BOOL CkCharset_WriteStringToFile(HCkCharset cHandle, const char *textData, const char *path, const char *charset);

Converts a Unicode string to a multibyte charset and writes the multibyte text data to a file. The destination charset is specified in the 2nd method argument.

Returns TRUE for success, FALSE for failure.

top