ximol/translation.cpp

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 translation implementations.
00024         
00025         \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: translation.cpp,v 1.9 2004/02/25 18:58:39 tournois Exp $
00029     $Log: translation.cpp,v $
00030     Revision 1.9  2004/02/25 18:58:39  tournois
00031     imporve the gcc compatibility.
00032 
00033     Revision 1.8  2004/02/25 15:57:06  tournois
00034     no message
00035 
00036     Revision 1.7  2004/02/22 10:27:33  tournois
00037     Add some doc.
00038 
00039     Revision 1.6  2004/02/22 09:54:19  tournois
00040     Change years on the copyright.
00041 
00042     Revision 1.5  2003/11/16 13:25:25  tournois
00043     Change the error to use wide string.
00044     Change the translation to use wide string.
00045 
00046     Revision 1.4  2003/11/02 19:23:01  tournois
00047     Go to the boost coding standard.
00048     Change all name to lower case.
00049 
00050     Revision 1.3  2003/10/25 13:53:39  hfp
00051     review and separation
00052 
00053     Revision 1.2  2003/09/24 08:28:17  tournois
00054     Create the namespace Encoders, Parser, Xml
00055     Change the library organization.
00056     add VC7.1 project for this organization.
00057 
00058   */
00059 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00060 #include <ximol/translation.hpp>
00061 
00062 XIMOL_BEGIN_PRIVATE_NAMESPACE
00063 
00064 //------------------------------------------------------------------------------
00065 // translation initialisation
00066 //------------------------------------------------------------------------------
00067 void start_translation()
00068 {
00069 };
00070 
00071 XIMOL_END_PRIVATE_NAMESPACE
00072 
00073 XIMOL_BEGIN_NAMESPACE
00074 
00075 //------------------------------------------------------------------------------
00076 // Function for the translation
00077 //------------------------------------------------------------------------------
00078 const wchar_t * translate(const wchar_t * x)
00079 {
00080     static bool init=true;
00081     if (init) {
00082         start_translation();
00083         init=false;
00084     }
00085 
00086     // nothing at this moment.
00087     return x;
00088 }
00089 
00090 //------------------------------------------------------------------------------
00091 /// Function for the translation with 0 argument.
00092 //------------------------------------------------------------------------------
00093 std::wstring _(const std::wstring& x)
00094 {
00095     return translate(x.c_str());
00096 };
00097 
00098 //------------------------------------------------------------------------------
00099 // Translate the base string and place arguments.
00100 //------------------------------------------------------------------------------
00101 std::wstring translate(const std::wstring & x, const std::list<std::wstring> & args)
00102 {
00103     std::wstring x_translated(translate(x.c_str()));
00104     std::list<std::wstring>::const_iterator arg(args.begin()), arg_end(args.end());
00105     std::wstring::const_iterator pos(x_translated.begin()), pos_end(x_translated.end());
00106     std::wstring result;
00107 
00108     while (pos!=pos_end) 
00109     {
00110         if (*pos!='%') 
00111         {
00112             result+=*pos;
00113             ++pos;
00114         } else {
00115             ++pos;
00116             if ((pos!=pos_end)&&(*pos=='o'))
00117             {
00118                 if (arg!=arg_end)
00119                 {
00120                     result+=*arg;
00121                     ++arg;
00122                 }
00123             } else {
00124                 if (*pos!='%') --pos;
00125                 result+=*pos;
00126             };
00127         };
00128     };
00129     return result;
00130 }
00131 
00132 XIMOL_END_NAMESPACE


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