00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _PDK__SUPPORT_TEXTCODER__H_
00014 #define _PDK__SUPPORT_TEXTCODER__H_
00015
00022 #include <support/SupportDefs.h>
00023 #include <support/String.h>
00024
00025 #include <LocaleMgr.h>
00026
00027 #if _SUPPORTS_NAMESPACE
00028 namespace palmos {
00029 namespace support {
00030 #endif
00031
00036 class STextCoderUtils {
00037 private:
00038 static CharEncodingType gDeviceEncoding;
00039 static CharEncodingType DeviceEncoding();
00040
00041 friend class STextDecoder;
00042 friend class STextEncoder;
00043 };
00044
00045 class STextDecoder {
00046 public:
00047 STextDecoder();
00048 ~STextDecoder();
00049
00050 status_t DeviceToUTF8(
00051 char const *text, size_t srcLen,
00052 char const * substitutionStr = "",
00053 size_t substitutionLen = 0);
00054 status_t DeviceToUTF8(
00055 wchar32_t srcChar,
00056 char const * substitutionStr = "",
00057 size_t substitutionLen = 0);
00058 status_t EncodingToUTF8(
00059 char const *text,
00060 size_t srcLen,
00061 CharEncodingType fromEncoding,
00062 char const * substitutionStr = "",
00063 size_t substitutionLen = 0);
00064 status_t EncodingToUTF8(const SValue & text,
00065 char const * substitutionStr = "",
00066 size_t substitutionLen = 0);
00067
00068 SString AsString() const;
00069 char const * Buffer() const;
00070 inline size_t Size() const
00071 { return m_length; }
00072 inline size_t ConsumedBytes() const
00073 { return m_consumed; }
00074 private:
00075 STextDecoder(const STextDecoder&);
00076
00077 static size_t const kInternalBufferSize = 60;
00078
00079 SString m_text;
00080 size_t m_consumed;
00081 size_t m_length;
00082
00083 bool m_useInternalBuffer;
00084 char m_buffer[kInternalBufferSize];
00085 };
00086
00087 class STextEncoder {
00088 public:
00089 STextEncoder();
00090 ~STextEncoder();
00091
00092
00093
00094
00095
00096
00097 status_t UTF8ToDevice(
00098 const SString & text,
00099 char const * substitutionStr = "",
00100 size_t substitutionLen = 0);
00101 status_t UTF8ToEncoding(
00102 const SString & text,
00103 CharEncodingType toEncoding,
00104 char const * substitutionStr = "",
00105 size_t substitutionLen = 0);
00106
00107 SValue AsValue() const;
00108 char const * Buffer() const;
00109 CharEncodingType Encoding() const;
00110 inline size_t Size() const
00111 { return m_length; }
00112 inline size_t ConsumedBytes() const
00113 { return m_consumed; }
00114 private:
00115 STextEncoder(const STextEncoder&);
00116
00117 struct encoding_info_block {
00118 CharEncodingType encoding;
00119 uint16_t _unused;
00120 };
00121 friend class STextDecoder;
00122
00123
00124 static size_t const kInternalBufferSize = 60;
00125
00126 SSharedBuffer * m_sharedBuffer;
00127 size_t m_consumed;
00128 size_t m_length;
00129 CharEncodingType m_encoding;
00130
00131 char m_buffer[kInternalBufferSize];
00132 };
00133
00136 #if _SUPPORTS_NAMESPACE
00137 } }
00138 #endif
00139
00140 #endif //_PDK__SUPPORT_TEXTCODER__H_