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