CkCharset C++ Class Reference
CkCharset
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.
Properties
void get_AltToCharset(CkString &str); void put_AltToCharset(const char *charsetName);
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 get_ErrorAction(void); void put_ErrorAction(int val);
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 (XXXX), (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 get_FromCharset(CkString &str); void put_FromCharset(const char *charset);
Tells the charset converter the charset of the input data for a conversion. Possible values are:
us-ascii
unicode
unicodefffe
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
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
void LastErrorHtml(CkString &str);
Error information in HTML format for the last method called.
void LastErrorText(CkString &str);
Error information in plain-text format for the last method called.
void LastErrorXml(CkString &str);
Error information in XML format for the last method called.
void get_LastInputAsHex(CkString &str);
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 get_LastInputAsQP(CkString &str);
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 get_LastOutputAsHex(CkString &str);
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 get_LastOutputAsQP(CkString &str);
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 get_SaveLast(void); void put_SaveLast(bool value);
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 get_ToCharset(CkString &str); void put_ToCharset(const char *charset);
Tells the charset converter the target charset for a conversion. Possible values are:
us-ascii
unicode
unicodefffe
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
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
bool get_Utf8(void) const; void put_Utf8(bool b);
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 get_Version(CkString &str);
Returns the version of the component, such as "9.0.0"
Methods
int CharsetToCodePage(const char * charsetName);
Converts a charset name to a code page number. For example, "iso-8859-1" converts to code page 28591.
bool CodePageToCharset(int codePage, CkString & outCharset);
Converts a code page number to a charset name. For example, 65001 converts to "utf-8". Returns true for success, false for failure.
bool ConvertData(const CkByteData & inData, CkByteData & 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 ConvertFile(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 ConvertFileNoPreamble(const char * inFilename, const char * outFilename);
To be documented soon...
bool ConvertFromUnicode(const CkByteData & uniData, CkByteData & outMbData);
Converts Unicode text to the charset specified by the ToCharset property.
bool ConvertHtml(const CkByteData & htmlIn, CkByteData & 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.
bool ConvertHtmlFile(const char * inFilename, const char * outFilename);
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.
bool ConvertToUnicode(const CkByteData & mbData, CkByteData & outUniData);
Converts multibyte character data to a Unicode string. The FromCharset property should be set before calling this method.
void EntityEncodeDec(const char * inStr, CkString & outStr);
Converts non-US-ASCII characters to Unicode decimal entities (&#xxxxx;) Returns true for success, false for failure.
void EntityEncodeHex(const char * inStr, CkString & outStr);
Converts non-US-ASCII characters to Unicode hex entities (&#xXXXX;) Returns true for success, false for failure.
bool GetHtmlCharset(const CkByteData & htmlData, CkString & outCharset);
Examines HTML text and extracts the charset name specified by the META tag, if present. Returns true for success, false for failure.
bool GetHtmlFileCharset(const char * htmlFilename, CkString & outCharset);
Examines an HTML file and extracts the charset name specified by the META tag, if present. Returns true for success, false for failure.
bool HtmlDecodeToStr(const char * str, CkString & outStr);
Converts HTML entities to Unicode characters. Returns true for success, false for failure.
bool HtmlEntityDecode(CkByteData & inData, CkByteData & 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 HtmlEntityDecodeFile(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 IsUnlocked();
Returns true if the component is unlocked.
void LowerCase(const char * inStr, CkString & outStr);
Converts a string to lowercase. Returns true for success, false for failure.
bool ReadFile(const char * filename, CkByteData & outData);
Convenience method for reading the entire contents of a file into a byte array.
bool SaveLastError(const char * filename);
Saves the last error information to an XML formatted file.
void SetErrorBytes(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 SetErrorString(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 UnlockComponent(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 UpperCase(const char * inStr, CkString & outStr);
Converts a string to uppercase. Returns true for success, false for failure.
bool UrlDecodeStr(const char * inStr, CkString & outStr);
URL decodes a string. Returns true for success, false for failure.
bool VerifyData(const char * charset, const CkByteData & charData);
Returns true if the byte data conforms to the charset passed in the first argument.
bool VerifyFile(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 WriteFile(const char * filename, const CkByteData & dataBuf);
Convenience method for saving an entire byte array to a file.
const char * altToCharset();
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. Returns a null on failure
const char * codePageToCharset(int codePage);
Converts a code page number to a charset name. For example, 65001 converts to "utf-8". Returns a null on failure
const char * entityEncodeDec(const char * inStr);
Converts non-US-ASCII characters to Unicode decimal entities (&#xxxxx;) Returns a null on failure
const char * entityEncodeHex(const char * inStr);
Converts non-US-ASCII characters to Unicode hex entities (&#xXXXX;) Returns a null on failure
const char * fromCharset();
Tells the charset converter the charset of the input data for a conversion. Possible values are:
us-ascii
unicode
unicodefffe
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
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
Returns a null on failure
const char * getHtmlCharset(const CkByteData & htmlData);
Examines HTML text and extracts the charset name specified by the META tag, if present. Returns a null on failure
const char * getHtmlFileCharset(const char * htmlFilename);
Examines an HTML file and extracts the charset name specified by the META tag, if present. Returns a null on failure
const char * htmlDecodeToStr(const char * str);
Converts HTML entities to Unicode characters. Returns a null on failure
const char * lastErrorHtml();
Error information in HTML format for the last method called.Returns a null on failure
const char * lastErrorText();
Error information in plain-text format for the last method called.Returns a null on failure
const char * lastErrorXml();
Error information in XML format for the last method called.Returns a null on failure
const char * lastInputAsHex();
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. Returns a null on failure
const char * lastInputAsQP();
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. Returns a null on failure
const char * lastOutputAsHex();
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. Returns a null on failure
const char * lastOutputAsQP();
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. Returns a null on failure
const char * lowerCase(const char * inStr);
Converts a string to lowercase. Returns a null on failure
const char * toCharset();
Tells the charset converter the target charset for a conversion. Possible values are:
us-ascii
unicode
unicodefffe
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
ibm037
ibm437
ibm500
ibm737
ibm775
ibm850
ibm852
ibm855
ibm857
ibm00858
ibm860
ibm861
ibm863
ibm864
ibm865
cp866
ibm869
ibm870
cp875
koi8-r
koi8-u
Returns a null on failure
const char * upperCase(const char * inStr);
Converts a string to uppercase. Returns a null on failure
const char * urlDecodeStr(const char * inStr);
URL decodes a string. Returns a null on failure
const char * version();
Returns the version of the component, such as "9.0.0" Returns a null on failure
|