00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef UNICODEMAP_H
00012 #define UNICODEMAP_H
00013
00014 #include <aconf.h>
00015
00016 #ifdef USE_GCC_PRAGMAS
00017 #pragma interface
00018 #endif
00019
00020 #include "gtypes.h"
00021 #include "CharTypes.h"
00022
00023 #if MULTITHREADED
00024 #include "GMutex.h"
00025 #endif
00026
00027 class GString;
00028
00029
00030
00031 enum UnicodeMapKind {
00032 unicodeMapUser,
00033 unicodeMapResident,
00034 unicodeMapFunc
00035 };
00036
00037 typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
00038
00039 struct UnicodeMapRange {
00040 Unicode start, end;
00041 Guint code, nBytes;
00042 };
00043
00044 struct UnicodeMapExt;
00045
00046
00047
00048 class UnicodeMap {
00049 public:
00050
00051
00052
00053 static UnicodeMap *parse(GString *encodingNameA);
00054
00055
00056 UnicodeMap(char *encodingNameA, GBool unicodeOutA,
00057 UnicodeMapRange *rangesA, int lenA);
00058
00059
00060
00061 UnicodeMap(char *encodingNameA, GBool unicodeOutA,
00062 UnicodeMapFunc funcA);
00063
00064 ~UnicodeMap();
00065
00066 void incRefCnt();
00067 void decRefCnt();
00068
00069 GString *getEncodingName() { return encodingName; }
00070
00071 GBool isUnicode() { return unicodeOut; }
00072
00073
00074
00075 GBool match(GString *encodingNameA);
00076
00077
00078
00079
00080
00081 int mapUnicode(Unicode u, char *buf, int bufSize);
00082
00083 private:
00084
00085 UnicodeMap(GString *encodingNameA);
00086
00087 GString *encodingName;
00088 UnicodeMapKind kind;
00089 GBool unicodeOut;
00090 union {
00091 UnicodeMapRange *ranges;
00092 UnicodeMapFunc func;
00093 };
00094 int len;
00095 UnicodeMapExt *eMaps;
00096 int eMapsLen;
00097 int refCnt;
00098 #ifdef MULTITHREADED
00099 GMutex mutex;
00100 #endif
00101 };
00102
00103
00104
00105 #define unicodeMapCacheSize 4
00106
00107 class UnicodeMapCache {
00108 public:
00109
00110 UnicodeMapCache();
00111 ~UnicodeMapCache();
00112
00113
00114
00115
00116 UnicodeMap *getUnicodeMap(GString *encodingName);
00117
00118 private:
00119
00120 UnicodeMap *cache[unicodeMapCacheSize];
00121 };
00122
00123 #endif