ximol/control_flow.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 control flow (Implementation).
00024 
00025     \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: control_flow.cpp,v 1.9 2004/03/03 22:05:30 tournois Exp $
00029     $Log: control_flow.cpp,v $
00030     Revision 1.9  2004/03/03 22:05:30  tournois
00031     Add a short roadmap.
00032     Add BOOST_NO_STD_WSTRING for gcc.
00033 
00034     Revision 1.8  2004/02/25 18:58:39  tournois
00035     imporve the gcc compatibility.
00036 
00037     Revision 1.7  2004/02/22 10:27:32  tournois
00038     Add some doc.
00039 
00040     Revision 1.6  2004/02/22 09:54:19  tournois
00041     Change years on the copyright.
00042 
00043     Revision 1.5  2004/02/09 12:41:25  tournois
00044     Fix bug about error message.
00045     Add a read_optionnal_space before the stag read.
00046 
00047     Revision 1.4  2004/01/29 20:52:35  tournois
00048     doc and tutorial.
00049 
00050     Revision 1.3  2004/01/22 22:06:45  tournois
00051     no message
00052 
00053     Revision 1.2  2004/01/21 21:06:41  tournois
00054     no message
00055 
00056     Revision 1.1  2004/01/19 20:40:55  tournois
00057     Add min, max and digits facet.
00058     Create the control flow file.
00059 
00060 
00061   */
00062 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00063 #include <ximol/control_flow.hpp>
00064 #include <ximol/parser/def_signs.hpp>
00065 #include <ximol/parser/utils.hpp>
00066 #include <ximol/xml/content.hpp>
00067 #include <ximol/translation.hpp>
00068 #include <ximol/error.hpp>
00069 
00070 XIMOL_BEGIN_NAMESPACE
00071 
00072 //-----------------------------------------------------------------------------
00073 // Test the flag to eat all white space.
00074 //-----------------------------------------------------------------------------
00075 bool has_skip_whitespace(xistream& xis)
00076 {
00077     return xis.flags() & std::ios_base::skipws ;
00078 };
00079 
00080 //-----------------------------------------------------------------------------
00081 // Turn on the flag to eat all white space.
00082 //-----------------------------------------------------------------------------
00083 xistream& skip_whitespace(xistream& xis)
00084 {
00085     std::skipws(xis);
00086     return xis;
00087 };
00088 
00089 //-----------------------------------------------------------------------------
00090 // Turn off the flag to eat all white space.
00091 //-----------------------------------------------------------------------------
00092 xistream& no_skip_whitespace(xistream& xis)
00093 {
00094     std::noskipws(xis);
00095     return xis;
00096 };
00097 
00098 //-----------------------------------------------------------------------------
00099 // Eat all white space.
00100 //-----------------------------------------------------------------------------
00101 xistream& drop_space(xistream& xis)
00102 {
00103     XIMOL_PARSER_USING_NAMESPACE;
00104     return read_optionnal_space(xis);
00105 };
00106 
00107 //-----------------------------------------------------------------------------
00108 // Eat the content.
00109 //-----------------------------------------------------------------------------
00110 xistream& drop_content(xistream& xis)
00111 {
00112     XIMOL_XML_NAMESPACE_PATH::char_data_content(xis);
00113     return xis; 
00114 };
00115 
00116 //-----------------------------------------------------------------------------
00117 // Test next element.
00118 //-----------------------------------------------------------------------------
00119 bool is_stag(xistream& xis)
00120 {
00121     XIMOL_PARSER_USING_NAMESPACE;
00122         if (!xis.good()) return false;
00123         if (xis.context.is_open_etag()) return false;
00124         if (xis.context.is_open_stag()) return true;
00125 
00126     if (has_skip_whitespace(xis)) 
00127         read_optionnal_space(xis);
00128 
00129         xchar_t xc1,xc2;
00130         xis.get(xc1);
00131         xis.get(xc2);
00132         xis.putback(xc2);
00133         xis.putback(xc1);
00134     return ((xc1==XCHAR_LESS_THAN_SIGN) && (is_letter(xc2))); 
00135 };
00136 
00137 //-----------------------------------------------------------------------------
00138 // Test next element.
00139 //-----------------------------------------------------------------------------
00140 bool is_etag(xistream& xis)
00141 {
00142     XIMOL_PARSER_USING_NAMESPACE;
00143         if (!xis.good()) return false;
00144         if (xis.context.is_open_etag()) return false;
00145         if (xis.context.is_open_stag()) return true;
00146 
00147     if (has_skip_whitespace(xis)) 
00148         read_optionnal_space(xis);
00149 
00150         xchar_t xc1,xc2;
00151         xis.get(xc1);
00152         xis.get(xc2);
00153         xis.putback(xc2);
00154         xis.putback(xc1);
00155     return ((xc1==XCHAR_LESS_THAN_SIGN) && (xc2==XCHAR_SOLIDUS)); 
00156 };
00157 
00158 //-----------------------------------------------------------------------------
00159 // Drop next element
00160 //-----------------------------------------------------------------------------
00161 xistream& drop_next_element(xistream& xis)
00162 {
00163         XIMOL_PARSER_USING_NAMESPACE;
00164 
00165         if (!is_stag(xis)) return xis;
00166 
00167         xstring name1, name2, uri1, uri2;
00168         read_stag(xis, name1, uri1);
00169         drop_element_until_etag(xis);
00170         read_etag(xis, name2, uri2);
00171 
00172         if (name1 != name2)
00173                 XIMOL_THROW << _(L"Waiting for an end tag with name='%o' and there is '%o'",str< ::std::string>::cast(name2),str< ::std::string>::cast(name1))
00174                                         << XIMOL_AS_ERROR;
00175         return xis;
00176 }
00177 
00178 //-----------------------------------------------------------------------------
00179 // Drop next element
00180 //-----------------------------------------------------------------------------
00181 xistream& drop_element_until_etag(xistream& xis)
00182 {
00183         while (drop_content(xis) && is_stag(xis)) drop_next_element(xis);
00184         return xis;
00185 }
00186 
00187 XIMOL_END_NAMESPACE
00188 
00189 


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