ximol/encoders/encoders.hpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002  *                                                                           *
00003  * library XiMoL                                                             *
00004  * Copyright (C) 2002, 2003, 2004 Florent Tournois                           *
00005  *                                                                           *
00006  * This library is free software; you can redistribute it and/or             *
00007  * modify it under the terms of the GNU Lesser General Public                *
00008  * License as published by the Free Software Foundation; either              *
00009  * version 2.1 of the License, or (at your option) any later version.        *
00010  *                                                                           *
00011  * This library is distributed in the hope that it will be useful,           *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00014  * Lesser General Public License for more details.                           *
00015  *                                                                           *
00016  * You should have received a copy of the GNU Lesser General Public          *
00017  * License along with this library; if not, write to the Free Software       *
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   *
00019  *                                                                           *
00020 \*****************************************************************************/
00021 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00022 /** \file 
00023         \brief Facet access declaration.
00024     All function about facet encoding are in this file. We use the libiconv
00025     librairie for the encoding.
00026 
00027         @ingroup encoders
00028 
00029         \author Tournois Florent
00030         \version 1.0
00031 
00032     $Id: encoders.hpp,v 1.14 2004/02/22 10:27:34 tournois Exp $
00033     $Log: encoders.hpp,v $
00034     Revision 1.14  2004/02/22 10:27:34  tournois
00035     Add some doc.
00036 
00037     Revision 1.13  2004/02/22 09:54:20  tournois
00038     Change years on the copyright.
00039 
00040     Revision 1.12  2004/01/27 21:49:52  tournois
00041     Add docs and tutorial.
00042 
00043     Revision 1.11  2004/01/25 17:32:17  tournois
00044     no message
00045 
00046     Revision 1.10  2003/11/18 18:54:51  tournois
00047     Add str_cast and drop the transformation.hpp file.
00048 
00049     Revision 1.9  2003/11/15 22:52:57  tournois
00050     Add somes function arround attributes and tests for attributes.
00051 
00052     Revision 1.8  2003/11/14 15:44:05  tournois
00053     Add some comments.
00054 
00055     Revision 1.7  2003/11/02 19:23:01  tournois
00056     Go to the boost coding standard.
00057     Change all name to lower case.
00058 
00059     Revision 1.6  2003/10/25 13:53:39  hfp
00060     review and separation
00061 
00062     Revision 1.5  2003/10/13 21:01:20  tournois
00063     no message
00064 
00065     Revision 1.4  2003/10/09 16:59:45  tournois
00066     add the stringstream initialisation.
00067     add some prolog test.
00068     Correct code for VC6.0.
00069 
00070     Revision 1.3  2003/10/03 17:29:41  tournois
00071     no message
00072 
00073     Revision 1.2  2003/09/24 08:28:17  tournois
00074     Create the namespace Encoders, Parser, Xml
00075     Change the library organization.
00076     add VC7.1 project for this organization.
00077 
00078   */
00079 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00080 #ifndef XIMOL_ENCODERS_XIMOL_ENCODERS_HPP_
00081 #define XIMOL_ENCODERS_XIMOL_ENCODERS_HPP_
00082 
00083 #include <ximol/export_defs.hpp>
00084 #include <ximol/typedefs.hpp>
00085 #include <ximol/macros.hpp>
00086 
00087 #include <locale>
00088 
00089 XIMOL_ENCODERS_BEGIN_NAMESPACE 
00090 
00091 //-----------------------------------------------------------------------------
00092 /** Interface for the ximol_encoders.
00093  *  This interface is based on libiconv 1-8.
00094  *      The memory must be freed. If you use the imbue method with the result, 
00095  *      you must not free the memory.
00096  *
00097  *      Here is the list of all supported encoding (from the libiconv manual):
00098  *
00099  *              \li \b European languages 
00100  *                      ASCII, ISO-8859-{1,2,3,4,5,7,9,10,13,14,15,16}, KOI8-R, KOI8-U, KOI8-RU, CP{1250,1251,1252,1253,1254,1257}, CP{850,866}, Mac{Roman,CentralEurope,Iceland,Croatian,Romania}, Mac{Cyrillic,Ukraine,Greek,Turkish}, Macintosh 
00101  *              \li \b Semitic languages 
00102  *                      ISO-8859-{6,8}, CP{1255,1256}, CP862, Mac{Hebrew,Arabic} 
00103  *              \li \b Japanese 
00104  *                      EUC-JP, SHIFT_JIS, CP932, ISO-2022-JP, ISO-2022-JP-2, ISO-2022-JP-1 
00105  *              \li \b Chinese 
00106  *                      EUC-CN, HZ, GBK, GB18030, EUC-TW, BIG5, CP950, BIG5-HKSCS, ISO-2022-CN, ISO-2022-CN-EXT 
00107  *              \li \b Korean 
00108  *                      EUC-KR, CP949, ISO-2022-KR, JOHAB 
00109  *              \li \b Armenian 
00110  *                      ARMSCII-8 
00111  *              \li \b Georgian 
00112  *                      Georgian-Academy, Georgian-PS 
00113  *              \li \b Tajik 
00114  *                      KOI8-T 
00115  *              \li \b Thai 
00116  *                      TIS-620, CP874, MacThai 
00117  *              \li \b Laotian 
00118  *                      MuleLao-1, CP1133 
00119  *              \li \b Vietnamese 
00120  *                      VISCII, TCVN, CP1258 
00121  *              \li \b Platform specifics 
00122  *                      HP-ROMAN8, NEXTSTEP 
00123  *              \li \b Full Unicode 
00124  *                      UTF-8 
00125  *                      UCS-2, UCS-2BE, UCS-2LE 
00126  *                      UCS-4, UCS-4BE, UCS-4LE 
00127  *                      UTF-16, UTF-16BE, UTF-16LE 
00128  *                      UTF-32, UTF-32BE, UTF-32LE 
00129  *                      UTF-7 
00130  *                      C99, JAVA 
00131  *              \li \b European languages 
00132  *                      CP{437,737,775,852,853,855,857,858,860,861,863,865,869,1125}
00133  *              \li \b Semitic languages 
00134  *                      CP864 
00135  *              \li \b Japanese 
00136  *                      EUC-JISX0213, Shift_JISX0213, ISO-2022-JP-3 
00137  *              \li \b Turkmen 
00138  *                      TDS565 
00139  *              \li \b Platform specifics 
00140  *                      RISCOS-LATIN1 
00141  *
00142  *      @param encoding_name : the encoding name from the list above.
00143  *      @return ::std::codecvt<xchar_t, char, mbstate_t>* : NULL or the codecvt facet pointer.
00144  *      @ingroup encoders
00145  */
00146 //-----------------------------------------------------------------------------
00147 XIMOL_EXPORT
00148 ::std::codecvt<xchar_t, char, mbstate_t> *
00149 get_ximol_facet(::std::string const & encoding_name);
00150 
00151 //-----------------------------------------------------------------------------
00152 /** place with new placement operator (difficult to use).
00153  *  @ingroup encoders
00154  *      @warning This function is only here for expert.
00155  */
00156 //-----------------------------------------------------------------------------
00157 XIMOL_EXPORT
00158 void
00159 place_ximol_facet(::std::codecvt<xchar_t, char, mbstate_t>* placement, 
00160                   ::std::string const & encoding_name);
00161 
00162 //-----------------------------------------------------------------------------
00163 /** Change encoding on a unique facet.
00164  *  @ingroup encoders
00165  *      This function change the encoding on the facet.
00166  *  If the facet is not a ximol facet then an exception is raise.
00167  *  If facet is NULL then nothing is done.
00168  *  
00169  *  @exception encoders::error
00170  *  @param facet : the ximol facet
00171  *  @param encoding_name : the standard encoding name
00172  *  @see use_xml, prepare_ios
00173  */
00174 //-----------------------------------------------------------------------------
00175 XIMOL_EXPORT
00176 void
00177 change_ximol_facet_encoding(::std::codecvt<xchar_t, char, mbstate_t> * facet, 
00178                             ::std::string const & encoding_name);
00179 
00180 //-----------------------------------------------------------------------------
00181 /** Change the encoding method for the stream.
00182  *  @ingroup encoders
00183  *  \warning This function work if the ios have already a ximol facet.
00184  *  If you do not know the nature of the facet, you could use the prepare_ios.
00185  *  The facet will be change.
00186  *
00187  *  If there is not any ximol facet then the function raise an exception.
00188  * 
00189  *  @exception encoders::error
00190  *  @param ios : the ios in reference
00191  *  @param encoding_name : the standard encoding name
00192  *  @see use_xml, prepare_ios
00193  */
00194 //-----------------------------------------------------------------------------
00195 XIMOL_EXPORT
00196 void deep_change(::std::basic_ios<xchar_t> & ios, 
00197                                  ::std::string const & encoding_name);
00198 
00199 //-----------------------------------------------------------------------------
00200 /** prepare ios.
00201  *  @ingroup encoders
00202  *  put a ximol facet to the ios. 
00203  *  This is a low-level function, and you should consider to use 
00204  *  the use_xml function. 
00205  * 
00206  *  The default encoding name is "UTF-8". You could change the default encoding
00207  *  name at compile time with the macro XIMOL_DEFAULT_ENCODING.
00208  *  
00209  *  @param ios : the ios in reference
00210  *  @param encoding_name : the standard encoding name
00211  *  @see use_xml, XIMOL_DEFAULT_ENCODING
00212  */
00213 //-----------------------------------------------------------------------------
00214 XIMOL_EXPORT
00215 void prepare_ios(::std::basic_ios<xchar_t> & ios, 
00216                  ::std::string const & encoding_name = XIMOL_DEFAULT_ENCODING);
00217 
00218 //-----------------------------------------------------------------------------
00219 /** test ios.
00220  *  @ingroup encoders
00221  *  Test if the ximol facet is set on the stream. This function is only 
00222  *  interessting for test.
00223  * 
00224  *  In normal condition we have \code test_ios(xstream)==true \endcode
00225  * 
00226  *  @param ios : the ios in reference.
00227  *  @return : true if the ximol facet is set and false otherwise.
00228  */
00229 //-----------------------------------------------------------------------------
00230 XIMOL_EXPORT
00231 bool test_ios(::std::basic_ios<xchar_t> & ios);
00232 
00233 XIMOL_ENCODERS_END_NAMESPACE 
00234 
00235 #endif // #ifndef XIMOL_ENCODERS_XIMOL_ENCODERS_HPP_


Donate to the XiMoL project SourceForge.net Logo If you have any questions about XiMoL, you could write to tournois@users.sourceforge.net.