00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_UTILITIES_CHARENC_H
00021 #define ARCHON_UTILITIES_CHARENC_H
00022
00023 #include <iconv.h>
00024
00025 namespace Archon
00026 {
00027 namespace Utilities
00028 {
00029 using namespace std;
00030
00037 struct CharEnc
00038 {
00039 static const string US_ASCII;
00040 static const string ISO_8859_1;
00041 static const string ISO_8859_15;
00042 static const string UTF_8;
00043 static const string UTF_16LE;
00044 static const string UTF_16BE;
00045 static const string UTF_32LE;
00046 static const string UTF_32BE;
00047 static const string WINDOWS_1252;
00048
00049 struct TranscodeException: Exception
00050 {
00051 TranscodeException(string l): Exception(l) {}
00052 };
00053
00075 static string encode(wstring s, string encoding = UTF_8,
00076 bool fail = false) throw(TranscodeException);
00077
00100 static wstring decode(string s, string encoding = UTF_8,
00101 bool fail = false) throw(TranscodeException);
00102
00127 static string transcode(string s, string sourceEncoding,
00128 string targetEncoding,
00129 bool fail = false) throw(TranscodeException);
00130
00146 CharEnc(string sourceEncoding, string targetEncoding);
00147
00148 ~CharEnc();
00149
00177 void transcode(const char *&sourceBuffer, size_t &sourceBytesLeft,
00178 char *&targetBuffer, size_t &targetBytesLeft,
00179 bool fail = false) throw(TranscodeException);
00180
00181 private:
00182 iconv_t iconvState;
00183 string targetEncoding;
00184 string replacementCharacter;
00185 bool needReplacementCharacter;
00186 };
00187 }
00188 }
00189
00190 #endif