Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/textEncoder.h

Go to the documentation of this file.
00001 // Filename: textEncoder.h
00002 // Created by:  drose (26Mar03)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
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 //       Class : TextEncoder
00029 // Description : This class can be used to convert text between
00030 //               multiple representations, e.g. utf-8 to Unicode.  You
00031 //               may use it as a static class object, passing the
00032 //               encoding each time, or you may create an instance and
00033 //               use that object, which will record the current
00034 //               encoding and retain the current string.
00035 //
00036 //               This class is also a base class of TextNode, which
00037 //               inherits this functionality.
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   // Direct support for wide-character strings.  Not publishable for
00091   // now (until we add support for wstring to interrogate).
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

Generated on Fri May 2 00:38:40 2003 for Panda by doxygen1.3