00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TEXTENCODER_H
00016 #define TEXTENCODER_H
00017
00018 #include "dtoolbase.h"
00019 #include "unicodeLatinMap.h"
00020
00021 class StringDecoder;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class EXPCL_DTOOL TextEncoder {
00036 PUBLISHED:
00037 enum Encoding {
00038 E_iso8859,
00039 E_utf8,
00040 E_unicode
00041 };
00042
00043 INLINE TextEncoder();
00044 INLINE TextEncoder(const TextEncoder ©);
00045
00046 INLINE void set_encoding(Encoding encoding);
00047 INLINE Encoding get_encoding() const;
00048
00049 INLINE static void set_default_encoding(Encoding encoding);
00050 INLINE static Encoding get_default_encoding();
00051
00052 INLINE void set_text(const string &text);
00053 INLINE void set_text(const string &text, Encoding encoding);
00054 INLINE void clear_text();
00055 INLINE bool has_text() const;
00056
00057 void make_upper();
00058 void make_lower();
00059
00060 INLINE string get_text() const;
00061 INLINE string get_text(Encoding encoding) const;
00062 INLINE void append_text(const string &text);
00063 INLINE void append_unicode_char(int character);
00064 INLINE int get_num_chars() const;
00065 INLINE int get_unicode_char(int index) const;
00066 INLINE void set_unicode_char(int index, int character);
00067 INLINE string get_encoded_char(int index) const;
00068 INLINE string get_encoded_char(int index, Encoding encoding) const;
00069 INLINE string get_text_as_ascii() const;
00070
00071 INLINE static string reencode_text(const string &text, Encoding from, Encoding to);
00072
00073 INLINE static bool unicode_isalpha(int character);
00074 INLINE static bool unicode_isdigit(int character);
00075 INLINE static bool unicode_ispunct(int character);
00076 INLINE static bool unicode_islower(int character);
00077 INLINE static bool unicode_isupper(int character);
00078 INLINE static bool unicode_isspace(int character);
00079 INLINE static int unicode_toupper(int character);
00080 INLINE static int unicode_tolower(int character);
00081
00082 INLINE static string upper(const string &source);
00083 INLINE static string upper(const string &source, Encoding encoding);
00084 INLINE static string lower(const string &source);
00085 INLINE static string lower(const string &source, Encoding encoding);
00086
00087
00088
00089 INLINE void set_wtext(const wstring &wtext);
00090 INLINE const wstring &get_wtext() const;
00091 INLINE void append_wtext(const wstring &text);
00092 wstring get_wtext_as_ascii() const;
00093 bool is_wtext() const;
00094
00095 static string encode_wchar(wchar_t ch, Encoding encoding);
00096 INLINE string encode_wtext(const wstring &wtext) const;
00097 static string encode_wtext(const wstring &wtext, Encoding encoding);
00098 INLINE wstring decode_text(const string &text) const;
00099 static wstring decode_text(const string &text, Encoding encoding);
00100
00101 private:
00102 enum Flags {
00103 F_got_text = 0x0001,
00104 F_got_wtext = 0x0002,
00105 };
00106 static wstring decode_text_impl(StringDecoder &decoder);
00107
00108 int _flags;
00109 Encoding _encoding;
00110 string _text;
00111 wstring _wtext;
00112
00113 static Encoding _default_encoding;
00114 };
00115
00116 EXPCL_DTOOL ostream &
00117 operator << (ostream &out, TextEncoder::Encoding encoding);
00118 EXPCL_DTOOL istream &
00119 operator >> (istream &in, TextEncoder::Encoding &encoding);
00120
00121
00122
00123
00124
00125
00126
00127 INLINE EXPCL_DTOOL ostream &
00128 operator << (ostream &out, const wstring &str);
00129
00130 #include "textEncoder.I"
00131
00132 #endif