charenc.H

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
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 // ARCHON_UTILITIES_CHARENC_H

Generated on Sun Jul 30 22:55:44 2006 for Archon by  doxygen 1.4.4