|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||
#include "ot/cvt/CodeConverter.h"

OpenTop comes supplied with CodeConverters for many common encodings such as UTF-8, UTF-16, Latin1, Windows-125x and many others.
| Constructor/Destructor Summary | |
CodeConverter()Creates a CodeConverter with default values. | |
| Method Summary | |
virtual bool |
alwaysNoConversion() constTests if this CodeConverter is using the same encoding as the native OpenTop encoding. |
virtual String |
decode(const ByteString& from)Decodes a sequence of bytes contained within a ByteString into a Unicode String. |
virtual Result |
decode(const Byte* from, const Byte* from_end, const Byte*& from_next, CharType* to, CharType* to_limit, CharType*& to_next)Decodes an array of bytes into an array of CharType values that represent Unicode characters in the native OpenTop encoding. |
static String |
Decode(const String& encoding, const ByteString& from)Static function to decode a sequence of encoded bytes contained within a ByteString into a Unicode String. |
virtual ByteString |
encode(const String& from)Encodes a sequence of Unicode characters into a sequence of bytes. |
virtual Result |
encode(const CharType* from, const CharType* from_end, const CharType*& from_next, Byte* to, Byte* to_limit, Byte*& to_next)Encodes an array of CharType characters, representing Unicode characters in the native OpenTop encoding into a sequence of bytes. |
static ByteString |
Encode(const String& encoding, const String& from)Static function to encode a string of Unicode characters (represented by a sequence of CharType values representing Unicode characters encoded into to the native OpenTop encoding) into a sequence of bytes using the encoding name provided. |
virtual size_t |
getDecodedLength(const Byte* from, const Byte* from_end) constReturns the number of Unicode characters that would be created by decoding the array of bytes starting at from. |
virtual String |
getEncodingName() constReturns the canonical name for the encoding handled by this CodeConverter. |
CharAction |
getInvalidCharAction() constReturns the policy for dealing with invalid byte sequences or Unicode characters which cannot be mapped into the internal OpenTop character encoding. |
UCS4Char |
getInvalidCharReplacement() constReturns the Unicode character that will be used when this CodeConverter detects an invalid byte sequence. |
virtual size_t |
getMaxEncodedLength() constReturns the maximum number of bytes used to encode a single Unicode character up to U+10FFFF. |
CharAction |
getUnmappableCharAction() constReturns the policy for dealing with Unicode characters that cannot be mapped into the target encoding. |
UCS4Char |
getUnmappableCharReplacement() constReturns the Unicode character that will be used when this CodeConverter detects an unmappable Unicode character. |
protected virtual Result |
handleEncodingToInternalError(UCS4Char ch, CharType* to, const CharType* to_limit, CharType*& to_next)Helper function called by derived classes' decode() method when they encounter a Unicode character which cannot be mapped into the native OpenTop encoding. |
protected void |
handleInvalidByteSequence(const Byte* from, size_t len) constHelper function that simply throws a MalformedInputException. |
protected virtual Result |
handleUnmappableCharacter(UCS4Char ch, Byte* to, Byte* to_limit, Byte*& to_next)Helper function called by derived classes' encode() method when it encounters an unmappable Unicode character. |
protected void |
internalEncodingError(const CharType* from, size_t len) constHelper function called by derived classes when they encounter a badly encoded internal CharType array. |
void |
setInvalidCharAction(CharAction eAction)Sets the policy for dealing with badly encoded byte sequences or encoded sequences which result in a Unicode character which cannot be mapped into the native OpenTop encoding. |
void |
setInvalidCharReplacement(UCS4Char ch)Sets the replacement Unicode character used when the CodeConverter detects an invalid byte sequence. |
void |
setUnmappableCharAction(CharAction eAction)Sets the policy for dealing with Unicode characters that cannot be mapped into the target encoding. |
void |
setUnmappableCharReplacement(UCS4Char ch)Sets the replacement Unicode character used when the CodeConverter detects a Unicode character than cannot be encoded into the target encoding. |
protected void |
throwUnsupported(unsigned long illegalChar) const |
| Methods inherited from class ot::CodeConverterBase |
IsLegalUTF16(const wchar_t*, size_t), IsLegalUTF8(const Byte*, size_t), UTF8Decode(UCS4Char&, const Byte*, const Byte*, const Byte*&), UTF8Encode(UCS4Char, Byte*, const Byte*, Byte*&) |
| Methods inherited from class ot::ManagedObject |
addRef(), getRefCount(), onFinalRelease(), operator=(const ManagedObject&), release() |
| Enumerations |
enum CharAction { |
abort, |
|
|
replace} |
|
| Constructor/Destructor Detail |
CodeConverter()
| Method Detail |
virtual bool alwaysNoConversion() const
virtual String decode(const ByteString& from)
from - MalformedInputException - virtual Result decode(const Byte* from,
const Byte* from_end,
const Byte*& from_next,
CharType* to,
CharType* to_limit,
CharType*& to_next)
from - from_end - from_next - to - to_limit - to_next - MalformedInputException - UnmappableCharacterException - static String Decode(const String& encoding,
const ByteString& from)
This function is provided for convenience, but applications which perform a lot of decoding or which need to configure a CodeConverter to behave in a specific way when errors are encountered should consider using the encode() instance method instead.
from - MalformedInputException - virtual ByteString encode(const String& from)
from - UnmappableCharacterException - virtual Result encode(const CharType* from,
const CharType* from_end,
const CharType*& from_next,
Byte* to,
Byte* to_limit,
Byte*& to_next)
from - from_end - from_next - to - to_limit - to_next - UnmappableCharacterException - static ByteString Encode(const String& encoding,
const String& from)
RefPtr<CodeConverter> rpConv =
CodeConverterFactory::GetInstance().getConverter(encoding);
return rpConv->encode(from);
encoding - from - UnsupportedEncodingException - UnmappableCharacterException - virtual size_t getDecodedLength(const Byte* from,
const Byte* from_end) const
from - from_end - virtual String getEncodingName() const
CharAction getInvalidCharAction() const
UCS4Char getInvalidCharReplacement() const
virtual size_t getMaxEncodedLength() const
CharAction getUnmappableCharAction() const
UCS4Char getUnmappableCharReplacement() const
protected virtual Result handleEncodingToInternalError(UCS4Char ch,
CharType* to,
const CharType* to_limit,
CharType*& to_next)
ch - to - to_limit - to_next - UnmappableCharacterException - protected void handleInvalidByteSequence(const Byte* from,
size_t len) const
MalformedInputException - protected virtual Result handleUnmappableCharacter(UCS4Char ch,
Byte* to,
Byte* to_limit,
Byte*& to_next)
ch - to - to_limit - to_next - protected void internalEncodingError(const CharType* from,
size_t len) const
from - void setInvalidCharAction(CharAction eAction)
When the action is set to CodeConverter::abort, a CharacterCodingException is thrown by decode() when an invalid or unsupported byte sequence is decoded. When the action is set to CodeConverter::replace, the invalid byte sequence is decoded as the replacement character returned from getInvalidCharReplacement().
eAction - void setInvalidCharReplacement(UCS4Char ch)
void setUnmappableCharAction(CharAction eAction)
When the action is set to CodeConverter::abort, an UnmappableCharacterException is thrown by encode() when an unmappable Unicode character is encoded. When the action is set to CodeConverter::replace, the unmappable character is replaced by the character returned from getUnmappableCharReplacement().
eAction - void setUnmappableCharReplacement(UCS4Char ch)
protected void throwUnsupported(unsigned long illegalChar) const
|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||