00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
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 
00074 
00075 bool has_skip_whitespace(xistream& xis)
00076 {
00077     return xis.flags() & std::ios_base::skipws ;
00078 };
00079 
00080 
00081 
00082 
00083 xistream& skip_whitespace(xistream& xis)
00084 {
00085     std::skipws(xis);
00086     return xis;
00087 };
00088 
00089 
00090 
00091 
00092 xistream& no_skip_whitespace(xistream& xis)
00093 {
00094     std::noskipws(xis);
00095     return xis;
00096 };
00097 
00098 
00099 
00100 
00101 xistream& drop_space(xistream& xis)
00102 {
00103     XIMOL_PARSER_USING_NAMESPACE;
00104     return read_optionnal_space(xis);
00105 };
00106 
00107 
00108 
00109 
00110 xistream& drop_content(xistream& xis)
00111 {
00112     XIMOL_XML_NAMESPACE_PATH::char_data_content(xis);
00113     return xis; 
00114 };
00115 
00116 
00117 
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 
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 
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 
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